diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/TypeReplaceMarker.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/TypeReplaceMarker.java index 2c845a0..cb850a6 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/TypeReplaceMarker.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/TypeReplaceMarker.java @@ -1,13 +1,11 @@ package typinferenzplugin; +import java.security.interfaces.RSAKey; import java.util.HashSet; import java.util.Set; -import org.apache.bcel.generic.CHECKCAST; - import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typeinference.result.ResultPair; -import de.dhbwstuttgart.typeinference.result.ResultPairMap; import de.dhbwstuttgart.typeinference.result.ResultSet; import typinferenzplugin.editor.JavEditor; @@ -41,8 +39,6 @@ public class TypeReplaceMarker extends JavMarker { } } return false; - //return this.resultSets.contains(other.getInsertPoint().getResultPair()); - //return this.resultSet.contains(ResultPairMap.RESULT_PAIRS.get(other.point.offset, other.tip.getInsertString())); } public void run(){ @@ -117,4 +113,19 @@ public class TypeReplaceMarker extends JavMarker { return ((TypeReplaceMarker)obj).tip.equals(this.tip); } } + + public void adjustResultSet(TypeReplaceMarker typeReplaceMarker) { + resultSets.removeIf(rs -> { + boolean result = false; + for (ResultPair rp : typeReplaceMarker.resultPairs) { + if (!rs.contains(rp)) { + result = true; + } else { + result = false; + } + } + return result; + }); + + } } diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java index 662610e..4db2143 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java @@ -1,5 +1,8 @@ package typinferenzplugin; +import static org.eclipse.core.runtime.IStatus.ERROR; +import static typinferenzplugin.Activator.PLUGIN_ID; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -13,9 +16,6 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.Vector; -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; @@ -28,21 +28,13 @@ import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.UnifyResultListener; import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import typinferenzplugin.editor.JavEditor; import typinferenzplugin.error.ErrorOutput; -import typinferenzplugin.log.EclipseLogfileWriter; - -import static java.util.concurrent.Executors.newSingleThreadExecutor; -import static org.eclipse.core.runtime.IStatus.ERROR; -import static org.eclipse.core.runtime.IStatus.INFO; -import static typinferenzplugin.Activator.PLUGIN_ID; public class Typinferenz { @@ -52,7 +44,7 @@ public class Typinferenz { private SourceFile parsedSource; private JavaTXCompiler compiler; - private List tiResults; + private List tiResults = new ArrayList<>(); private Set forByteCode = new HashSet<>(); public Typinferenz(JavEditor forEditor) { @@ -60,8 +52,6 @@ public class Typinferenz { } public UnifyResultModel run(UnifyResultListener resultListener) throws TypeinferenceException { - Vector ret = new Vector(); - try { compiler = new JavaTXCompiler(editor.getFilePath().toFile(), false); SourceFile parsedSourceOrNull = compiler.sourceFiles.get(editor.getFilePath().toFile()); @@ -80,23 +70,8 @@ public class Typinferenz { return null; } - public List fakeRun() { - try { - compiler = new JavaTXCompiler(editor.getFilePath().toFile(), false); - SourceFile parsedSourceOrNull = compiler.sourceFiles.get(editor.getFilePath().toFile()); - if (parsedSourceOrNull != null) { - this.parsedSource = parsedSourceOrNull; - } - } catch (ClassNotFoundException | IOException e) { - LOG.log(new Status(ERROR, PLUGIN_ID, e.getMessage(), e)); - e.printStackTrace(); - } - - return this.tiResults; - } - public Collection getResultSets() { - return this.tiResults; + return this.forByteCode; } public Vector updateWithResult(Vector ret, List newResults) { @@ -116,9 +91,7 @@ public class Typinferenz { } } - String outputDirectory = editor.getFilePath().toString(); - outputDirectory = outputDirectory.substring(0, - outputDirectory.length() - editor.getFilePath().lastSegment().length());// ".jav" hat Länge 4 + String outputDirectory = getOutputDirectory(); if (this.forByteCode.size() > 0) { for (SourceFile sf : compiler.sourceFiles.values()) { @@ -134,9 +107,16 @@ public class Typinferenz { return ret; } + + public String getOutputDirectory() { + String outputDirectory = editor.getFilePath().toString(); + outputDirectory = outputDirectory.substring(0, + outputDirectory.length() - editor.getFilePath().lastSegment().length());// ".jav" hat Länge 4 + return outputDirectory; + } public void updateresultSets(Vector typeInsertResults) { - this.tiResults = typeInsertResults; + //this.tiResults = typeInsertResults; // for (ResultSet resultSet : typeInsertResults) { // for (ResultPair result : resultSet.results) { // LOG.log(new Status(INFO, PLUGIN_ID, "Types: " + result.getRight().getClass().getCanonicalName() + "," + result.getLeft().getClass().getCanonicalName())); diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java index ee87224..ba81f28 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JavEditor.java @@ -6,8 +6,10 @@ import static org.eclipse.core.runtime.IStatus.ERROR; import static typinferenzplugin.Activator.PLUGIN_ID; import java.util.Collection; +import java.util.HashMap; import java.util.TreeSet; import java.util.Vector; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -38,7 +40,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; -import de.dhbwstuttgart.typeinference.result.ResultPairMap; +import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.UnifyResultEvent; import de.dhbwstuttgart.typeinference.unify.UnifyResultListener; import typinferenzplugin.Activator; @@ -101,7 +103,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener { */ protected void initializeEditor() { super.initializeEditor(); - ResultPairMap.RESULT_PAIRS.clear(); setSourceViewerConfiguration(new JavViewerConfiguration(this)); // install the document provider // setDocumentProvider(new JavFileProvider()); @@ -113,7 +114,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener { // Wird aufgerufen, sobald das Dokument gespeichert wird. typeinference = new Typinferenz(this); this.removeMarkers(); - ResultPairMap.RESULT_PAIRS.clear(); this.typeReconstruction(); } @@ -243,7 +243,16 @@ public class JavEditor extends TextEditor implements UnifyResultListener { toCheck.getInsertPoint().point.addExtraOffset(lengthOfInsert); } } + + // Remove resultsets if not consistent. + for (TypeReplaceMarker trm : typeReplaceMarkers) { + trm.adjustResultSet(typeReplaceMarker); + } updateGuiWithNewMarkers(typeReplaceMarkers); + + Collection newResultSets = typeReplaceMarkers.stream().map(trm -> trm.getResultSets()).flatMap(rs -> rs.stream()).collect(Collectors.toSet()); + HashMap bytecode = typeinference.getBytecode(typeinference.getSourceFile(), newResultSets, typeinference.getOutputDirectory()); + typeinference.writeClassFile(typeinference.getOutputDirectory(), bytecode); } private void removeMarkers() { @@ -337,7 +346,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener { Vector markers = new Vector(); Vector newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult()); - //typeReplaceMarkers.removeAll(newMarkers); errorMarkers.removeAll(newMarkers); for (JavMarker trm : newMarkers) { @@ -351,16 +359,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener { } } - /* - typeReplaceMarkers.addAll( - newMarkers - .stream() - .filter(m -> m instanceof TypeReplaceMarker) - .map(m -> (TypeReplaceMarker) m) - .collect(toCollection(Vector::new)) - ); - */ - errorMarkers.addAll( newMarkers .stream() @@ -371,6 +369,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener { for (TypeReplaceMarker m : this.getTypeReplaceMarkers()) { markers.add(m); } + return markers; }