diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java index 67bd6d8..662610e 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.Status; import de.dhbwstuttgart.bytecode.BytecodeGen; +import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError; import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.exceptions.TypeinferenceException; @@ -98,7 +99,7 @@ public class Typinferenz { return this.tiResults; } - public Vector updateWithResult(Vector ret, List newResults) { + public Vector updateWithResult(Vector ret, List newResults) { this.tiResults.addAll(newResults); this.forByteCode.addAll(newResults); @@ -121,8 +122,13 @@ public class Typinferenz { if (this.forByteCode.size() > 0) { for (SourceFile sf : compiler.sourceFiles.values()) { - HashMap bytecode = getBytecode(sf, this.forByteCode, outputDirectory); - this.writeClassFile(outputDirectory, bytecode); + try { + HashMap 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); + } } } diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java index 884b654..a755bc6 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java @@ -1,13 +1,11 @@ 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 typinferenzplugin.Activator.PLUGIN_ID; -import static java.util.Collections.singletonList; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; import java.util.TreeSet; import java.util.Vector; @@ -70,7 +68,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener { private JavOutline outlinePage; /** - * Der SyntaxBaum f�r das aktuell geöffnete Dokument. + * Der SyntaxBaum für das aktuell geöffnete Dokument. */ private SourceFile sourceFile; @@ -78,7 +76,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener { * Die TypeReplaceMarker für das aktuell geöffnete Dokument */ private Vector errorMarkers = new Vector(); - private Vector typeReplaceMarkers = new Vector(); // Help: @@ -321,7 +318,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener { @Override public void onNewTypeResultFound(UnifyResultEvent evt) { - Vector markers = updateMarkers(evt); + Vector markers = updateMarkers(evt); // Anschließend die TypeReplaceMarker im Quellcode anzeigen: // 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 updateMarkers(UnifyResultEvent evt) { + private Vector updateMarkers(UnifyResultEvent evt) { typeinference.updateresultSets(new Vector<>(evt.getNewTypeResult())); - Vector markers = new Vector(); - Vector newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult()); + Vector markers = new Vector(); + Vector newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult()); + 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()) { markers.add(m);