From f27ad61a8be1bcdc7bbe474cca15645c6b37e3a6 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Mon, 18 Mar 2019 09:34:16 +0100 Subject: [PATCH] Logger comes from plugin now. --- .../src/typinferenzplugin/Typinferenz.java | 4 +- .../typinferenzplugin/editor/JavEditor.java | 56 ++++++++++++------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java index 345bf7a..62e65e8 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -16,6 +17,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.apache.commons.io.output.NullOutputStream; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.Status; @@ -62,7 +64,7 @@ public class Typinferenz { compiler = new JavaTXCompiler(editor.getFilePath().toFile(), false); this.parsedSource = compiler.sourceFiles.get(editor.getFilePath().toFile()); - return compiler.typeInferenceAsync(resultListener); + return compiler.typeInferenceAsync(resultListener, new OutputStreamWriter(new NullOutputStream())); } catch (ClassNotFoundException e) { LOG.log(new Status(ERROR, PLUGIN_ID, e.getMessage(), e)); } catch (IOException e) { diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java index 49ca003..8d0f378 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java @@ -79,12 +79,12 @@ 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; /** - * Die TypeReplaceMarker f�r das aktuell geöffnete Dokument + * Die TypeReplaceMarker für das aktuell geöffnete Dokument */ private Vector errorMarkers = new Vector(); @@ -104,6 +104,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener { @Override protected void doSetInput(IEditorInput input) throws CoreException { super.doSetInput(input); + this.removeMarkers(); this.typeReconstruction(); // Marker generieren } @@ -157,7 +158,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener { return ((IFileEditorInput) input).getFile(); } - private void placeMarkers(IResource inDocument, Vector markers) { + private void placeMarkers(IResource inDocument, Collection markers) { // Marker Tut: // http://wiki.eclipse.org/FAQ_How_do_I_create_my_own_tasks,_problems,_bookmarks,_and_so_on%3F // ResourceMarkerAnnotationModel model = new @@ -241,11 +242,26 @@ public class JavEditor extends TextEditor implements UnifyResultListener { public void runReplaceMarker(TypeReplaceMarker typeReplaceMarker) { IDocument document = this.getDocumentProvider().getDocument(this.getEditorInput()); document.set(typeReplaceMarker.insertType(document.get())); - // this.removeMarkers(); - this.typeReconstruction(); + + typeReplaceMarkers.remove(typeReplaceMarker); + + removeVisualMarkers(); + updateGuiWithNewMarkers(typeReplaceMarkers); + /* + this.removeMarkers(); + this.typeReconstruction(); + */ } private void removeMarkers() { + removeVisualMarkers(); + + this.errorMarkers.removeAllElements(); + this.typeReplaceMarkers.removeAllElements(); + this.updateOutlinePage(); + } + + private void removeVisualMarkers() { IResource document = this.extractResource(); try { document.deleteMarkers(Activator.TYPINFERENZMARKER_NAME, true, IProject.DEPTH_INFINITE); @@ -256,12 +272,8 @@ public class JavEditor extends TextEditor implements UnifyResultListener { this.deleteAnnotation(jm); for (JavMarker jm : typeReplaceMarkers) this.deleteAnnotation(jm); - this.errorMarkers.removeAllElements(); - this.typeReplaceMarkers.removeAllElements(); - this.updateOutlinePage(); - // this.outlinePage.update(sourceFile, markers); } - + /** * Aktualisiert die OutlinePage, falls vorhanden. Muss nach �nderungen an * markers aufgerufen werden. @@ -325,21 +337,23 @@ public class JavEditor extends TextEditor implements UnifyResultListener { // Anschließend die TypeReplaceMarker im Quellcode anzeigen: // https://stackoverflow.com/questions/8945371/how-to-implement-quick-fix-quick-assist-for-custom-eclipse-editor //LOG.log(new Status(INFO, PLUGIN_ID, "Typinferez durchgeführt. Berechnete Marker:\n" + markers)); - Display.getDefault().asyncExec(() -> { - // do something in the user interface - IResource activeDocument = extractResource(); - if (activeDocument == null) { - LOG.log(new Status(ERROR, PLUGIN_ID, "Kann das aktive Dokument nicht ermitteln")); - } else { - this.placeMarkers(activeDocument, new Vector(markers)); - } - this.sourceFile = typeinference.getSourceFile(); + updateGuiWithNewMarkers(markers); this.errorMarkers.addAll(markers); - this.updateOutlinePage(); - // this.outlinePage.update(this.sourceFile,this.markers); }); } + private void updateGuiWithNewMarkers(Collection markers) { + IResource activeDocument = extractResource(); + if (activeDocument == null) { + LOG.log(new Status(ERROR, PLUGIN_ID, "Kann das aktive Dokument nicht ermitteln")); + } else { + this.placeMarkers(activeDocument, markers); + } + this.sourceFile = typeinference.getSourceFile(); + + this.updateOutlinePage(); + } + }