BytecodeGeneratorError wird jetzt abgefangen.

This commit is contained in:
Michael Uhl 2019-05-06 13:41:04 +02:00
parent d7c9247a27
commit fdedcb8191
2 changed files with 33 additions and 14 deletions

View File

@ -22,6 +22,7 @@ import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import de.dhbwstuttgart.bytecode.BytecodeGen; import de.dhbwstuttgart.bytecode.BytecodeGen;
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor; import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.exceptions.TypeinferenceException;
@ -98,7 +99,7 @@ public class Typinferenz {
return this.tiResults; return this.tiResults;
} }
public Vector<TypeReplaceMarker> updateWithResult(Vector<TypeReplaceMarker> ret, List<ResultSet> newResults) { public Vector<JavMarker> updateWithResult(Vector<JavMarker> ret, List<ResultSet> newResults) {
this.tiResults.addAll(newResults); this.tiResults.addAll(newResults);
this.forByteCode.addAll(newResults); this.forByteCode.addAll(newResults);
@ -121,8 +122,13 @@ public class Typinferenz {
if (this.forByteCode.size() > 0) { if (this.forByteCode.size() > 0) {
for (SourceFile sf : compiler.sourceFiles.values()) { for (SourceFile sf : compiler.sourceFiles.values()) {
HashMap<String, byte[]> bytecode = getBytecode(sf, this.forByteCode, outputDirectory); try {
this.writeClassFile(outputDirectory, bytecode); HashMap<String, byte[]> bytecode = getBytecode(sf, this.forByteCode, outputDirectory);
this.writeClassFile(outputDirectory, bytecode);
} catch (BytecodeGeneratorError ex) {
ErrorMarker toAdd = new ErrorMarker(ex.getMessage(), new CodePoint(sf.getOffset()));
ret.add(toAdd);
}
} }
} }

View File

@ -1,13 +1,11 @@
package typinferenzplugin.editor; package typinferenzplugin.editor;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toCollection;
import static org.eclipse.core.runtime.IStatus.ERROR; import static org.eclipse.core.runtime.IStatus.ERROR;
import static typinferenzplugin.Activator.PLUGIN_ID; import static typinferenzplugin.Activator.PLUGIN_ID;
import static java.util.Collections.singletonList;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector; import java.util.Vector;
@ -70,7 +68,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
private JavOutline outlinePage; private JavOutline outlinePage;
/** /**
* Der SyntaxBaum f<EFBFBD>r das aktuell geöffnete Dokument. * Der SyntaxBaum für das aktuell geöffnete Dokument.
*/ */
private SourceFile sourceFile; private SourceFile sourceFile;
@ -78,7 +76,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
* Die TypeReplaceMarker für das aktuell geöffnete Dokument * Die TypeReplaceMarker für das aktuell geöffnete Dokument
*/ */
private Vector<JavMarker> errorMarkers = new Vector<JavMarker>(); private Vector<JavMarker> errorMarkers = new Vector<JavMarker>();
private Vector<TypeReplaceMarker> typeReplaceMarkers = new Vector<TypeReplaceMarker>(); private Vector<TypeReplaceMarker> typeReplaceMarkers = new Vector<TypeReplaceMarker>();
// Help: // Help:
@ -321,7 +318,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
@Override @Override
public void onNewTypeResultFound(UnifyResultEvent evt) { public void onNewTypeResultFound(UnifyResultEvent evt) {
Vector<TypeReplaceMarker> markers = updateMarkers(evt); Vector<JavMarker> markers = updateMarkers(evt);
// Anschließend die TypeReplaceMarker im Quellcode anzeigen: // Anschließend die TypeReplaceMarker im Quellcode anzeigen:
// https://stackoverflow.com/questions/8945371/how-to-implement-quick-fix-quick-assist-for-custom-eclipse-editor // https://stackoverflow.com/questions/8945371/how-to-implement-quick-fix-quick-assist-for-custom-eclipse-editor
@ -334,13 +331,29 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
} }
private Vector<TypeReplaceMarker> updateMarkers(UnifyResultEvent evt) { private Vector<JavMarker> updateMarkers(UnifyResultEvent evt) {
typeinference.updateresultSets(new Vector<>(evt.getNewTypeResult())); typeinference.updateresultSets(new Vector<>(evt.getNewTypeResult()));
Vector<TypeReplaceMarker> markers = new Vector<TypeReplaceMarker>(); Vector<JavMarker> markers = new Vector<JavMarker>();
Vector<TypeReplaceMarker> newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult()); Vector<JavMarker> newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult());
typeReplaceMarkers.removeAll(newMarkers); typeReplaceMarkers.removeAll(newMarkers);
typeReplaceMarkers.addAll(newMarkers); errorMarkers.removeAll(newMarkers);
typeReplaceMarkers.addAll(
newMarkers
.stream()
.filter(m -> m instanceof TypeReplaceMarker)
.map(m -> (TypeReplaceMarker) m)
.collect(toCollection(Vector::new))
);
errorMarkers.addAll(
newMarkers
.stream()
.filter(m -> m instanceof TypeReplaceMarker)
.collect(toCollection(Vector::new))
);
for (TypeReplaceMarker m : this.getTypeReplaceMarkers()) { for (TypeReplaceMarker m : this.getTypeReplaceMarkers()) {
markers.add(m); markers.add(m);