Code aufgeräumt.

This commit is contained in:
Michael Uhl 2019-05-14 21:54:27 +02:00
parent 1b3ac13591
commit 59ee469172
3 changed files with 43 additions and 53 deletions

View File

@ -1,13 +1,11 @@
package typinferenzplugin; package typinferenzplugin;
import java.security.interfaces.RSAKey;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.apache.bcel.generic.CHECKCAST;
import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultPairMap;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import typinferenzplugin.editor.JavEditor; import typinferenzplugin.editor.JavEditor;
@ -41,8 +39,6 @@ public class TypeReplaceMarker extends JavMarker {
} }
} }
return false; 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(){ public void run(){
@ -117,4 +113,19 @@ public class TypeReplaceMarker extends JavMarker {
return ((TypeReplaceMarker)obj).tip.equals(this.tip); 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;
});
}
} }

View File

@ -1,5 +1,8 @@
package typinferenzplugin; package typinferenzplugin;
import static org.eclipse.core.runtime.IStatus.ERROR;
import static typinferenzplugin.Activator.PLUGIN_ID;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -13,9 +16,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector; 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.apache.commons.io.output.NullOutputStream;
import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.ILog;
@ -28,21 +28,13 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener; import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
import typinferenzplugin.editor.JavEditor; import typinferenzplugin.editor.JavEditor;
import typinferenzplugin.error.ErrorOutput; 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 { public class Typinferenz {
@ -52,7 +44,7 @@ public class Typinferenz {
private SourceFile parsedSource; private SourceFile parsedSource;
private JavaTXCompiler compiler; private JavaTXCompiler compiler;
private List<ResultSet> tiResults; private List<ResultSet> tiResults = new ArrayList<>();
private Set<ResultSet> forByteCode = new HashSet<>(); private Set<ResultSet> forByteCode = new HashSet<>();
public Typinferenz(JavEditor forEditor) { public Typinferenz(JavEditor forEditor) {
@ -60,8 +52,6 @@ public class Typinferenz {
} }
public UnifyResultModel run(UnifyResultListener resultListener) throws TypeinferenceException { public UnifyResultModel run(UnifyResultListener resultListener) throws TypeinferenceException {
Vector<TypeReplaceMarker> ret = new Vector<TypeReplaceMarker>();
try { try {
compiler = new JavaTXCompiler(editor.getFilePath().toFile(), false); compiler = new JavaTXCompiler(editor.getFilePath().toFile(), false);
SourceFile parsedSourceOrNull = compiler.sourceFiles.get(editor.getFilePath().toFile()); SourceFile parsedSourceOrNull = compiler.sourceFiles.get(editor.getFilePath().toFile());
@ -80,23 +70,8 @@ public class Typinferenz {
return null; return null;
} }
public List<ResultSet> 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<ResultSet> getResultSets() { public Collection<ResultSet> getResultSets() {
return this.tiResults; return this.forByteCode;
} }
public Vector<JavMarker> updateWithResult(Vector<JavMarker> ret, List<ResultSet> newResults) { public Vector<JavMarker> updateWithResult(Vector<JavMarker> ret, List<ResultSet> newResults) {
@ -116,9 +91,7 @@ public class Typinferenz {
} }
} }
String outputDirectory = editor.getFilePath().toString(); String outputDirectory = getOutputDirectory();
outputDirectory = outputDirectory.substring(0,
outputDirectory.length() - editor.getFilePath().lastSegment().length());// ".jav" hat Länge 4
if (this.forByteCode.size() > 0) { if (this.forByteCode.size() > 0) {
for (SourceFile sf : compiler.sourceFiles.values()) { for (SourceFile sf : compiler.sourceFiles.values()) {
@ -135,8 +108,15 @@ public class Typinferenz {
return ret; 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<ResultSet> typeInsertResults) { public void updateresultSets(Vector<ResultSet> typeInsertResults) {
this.tiResults = typeInsertResults; //this.tiResults = typeInsertResults;
// for (ResultSet resultSet : typeInsertResults) { // for (ResultSet resultSet : typeInsertResults) {
// for (ResultPair<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric> result : resultSet.results) { // for (ResultPair<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric> result : resultSet.results) {
// LOG.log(new Status(INFO, PLUGIN_ID, "Types: " + result.getRight().getClass().getCanonicalName() + "," + result.getLeft().getClass().getCanonicalName())); // LOG.log(new Status(INFO, PLUGIN_ID, "Types: " + result.getRight().getClass().getCanonicalName() + "," + result.getLeft().getClass().getCanonicalName()));

View File

@ -6,8 +6,10 @@ import static org.eclipse.core.runtime.IStatus.ERROR;
import static typinferenzplugin.Activator.PLUGIN_ID; import static typinferenzplugin.Activator.PLUGIN_ID;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector; import java.util.Vector;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
@ -38,7 +40,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; 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.UnifyResultEvent;
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener; import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
import typinferenzplugin.Activator; import typinferenzplugin.Activator;
@ -101,7 +103,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
*/ */
protected void initializeEditor() { protected void initializeEditor() {
super.initializeEditor(); super.initializeEditor();
ResultPairMap.RESULT_PAIRS.clear();
setSourceViewerConfiguration(new JavViewerConfiguration(this)); setSourceViewerConfiguration(new JavViewerConfiguration(this));
// install the document provider // install the document provider
// setDocumentProvider(new JavFileProvider()); // setDocumentProvider(new JavFileProvider());
@ -113,7 +114,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
// Wird aufgerufen, sobald das Dokument gespeichert wird. // Wird aufgerufen, sobald das Dokument gespeichert wird.
typeinference = new Typinferenz(this); typeinference = new Typinferenz(this);
this.removeMarkers(); this.removeMarkers();
ResultPairMap.RESULT_PAIRS.clear();
this.typeReconstruction(); this.typeReconstruction();
} }
@ -243,7 +243,16 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
toCheck.getInsertPoint().point.addExtraOffset(lengthOfInsert); toCheck.getInsertPoint().point.addExtraOffset(lengthOfInsert);
} }
} }
// Remove resultsets if not consistent.
for (TypeReplaceMarker trm : typeReplaceMarkers) {
trm.adjustResultSet(typeReplaceMarker);
}
updateGuiWithNewMarkers(typeReplaceMarkers); updateGuiWithNewMarkers(typeReplaceMarkers);
Collection<ResultSet> newResultSets = typeReplaceMarkers.stream().map(trm -> trm.getResultSets()).flatMap(rs -> rs.stream()).collect(Collectors.toSet());
HashMap<String, byte[]> bytecode = typeinference.getBytecode(typeinference.getSourceFile(), newResultSets, typeinference.getOutputDirectory());
typeinference.writeClassFile(typeinference.getOutputDirectory(), bytecode);
} }
private void removeMarkers() { private void removeMarkers() {
@ -337,7 +346,6 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
Vector<JavMarker> markers = new Vector<JavMarker>(); Vector<JavMarker> markers = new Vector<JavMarker>();
Vector<JavMarker> newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult()); Vector<JavMarker> newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult());
//typeReplaceMarkers.removeAll(newMarkers);
errorMarkers.removeAll(newMarkers); errorMarkers.removeAll(newMarkers);
for (JavMarker trm : 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( errorMarkers.addAll(
newMarkers newMarkers
.stream() .stream()
@ -371,6 +369,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
for (TypeReplaceMarker m : this.getTypeReplaceMarkers()) { for (TypeReplaceMarker m : this.getTypeReplaceMarkers()) {
markers.add(m); markers.add(m);
} }
return markers; return markers;
} }