Richtiges Einsetzen ohne Speichern.
This commit is contained in:
parent
1a948e56f8
commit
0252781d13
@ -1,54 +1,61 @@
|
||||
package typinferenzplugin;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
|
||||
import typinferenzplugin.editor.JavEditor;
|
||||
|
||||
public class ErrorMarker extends JavMarker{
|
||||
|
||||
private String message;
|
||||
private CodePoint point;
|
||||
|
||||
public ErrorMarker(String message ,CodePoint p){
|
||||
this.message = message;
|
||||
this.point = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage(){
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String ret = "";
|
||||
ret+="ErrorMarker: "+this.getMessage();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodePoint getPoint() {
|
||||
return this.point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object eq){
|
||||
if(! (eq instanceof ErrorMarker))return false;
|
||||
ErrorMarker equals = (ErrorMarker) eq;
|
||||
if(!(equals.point.equals(this.point)))return false;
|
||||
if(!(equals.getMessage().equals(this.getMessage())))return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnnotation(Annotation addAnnotation) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package typinferenzplugin;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
|
||||
import typinferenzplugin.editor.JavEditor;
|
||||
|
||||
public class ErrorMarker extends JavMarker{
|
||||
|
||||
private String message;
|
||||
private CodePoint point;
|
||||
|
||||
public ErrorMarker(String message ,CodePoint p){
|
||||
this.message = message;
|
||||
this.point = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage(){
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String ret = "";
|
||||
ret+="ErrorMarker: "+this.getMessage();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodePoint getPoint() {
|
||||
return this.point;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getPositionInCode() {
|
||||
return point.getPositionInCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object eq){
|
||||
if(! (eq instanceof ErrorMarker))return false;
|
||||
ErrorMarker equals = (ErrorMarker) eq;
|
||||
if(!(equals.point.equals(this.point)))return false;
|
||||
if(!(equals.getMessage().equals(this.getMessage())))return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnnotation(Annotation addAnnotation) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,36 +1,34 @@
|
||||
package typinferenzplugin;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
|
||||
public abstract class JavMarker {
|
||||
|
||||
private Annotation annotation;
|
||||
|
||||
public abstract CodePoint getPoint();
|
||||
public abstract String getMessage();
|
||||
|
||||
public void setAnnotation(Annotation addAnnotation) {
|
||||
this.annotation = addAnnotation;
|
||||
}
|
||||
|
||||
public Annotation getAnnotation() {
|
||||
return annotation;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (! (o instanceof JavMarker)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JavMarker other = (JavMarker)o;
|
||||
return getMessage().equals(other.getMessage()) && getPoint().getPositionInCode() == other.getPoint().getPositionInCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getPoint().getPositionInCode();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package typinferenzplugin;
|
||||
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
|
||||
public abstract class JavMarker {
|
||||
|
||||
private Annotation annotation;
|
||||
|
||||
public abstract CodePoint getPoint();
|
||||
public abstract String getMessage();
|
||||
public abstract int getPositionInCode();
|
||||
|
||||
public void setAnnotation(Annotation addAnnotation) {
|
||||
this.annotation = addAnnotation;
|
||||
}
|
||||
|
||||
public Annotation getAnnotation() {
|
||||
return annotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (! (o instanceof JavMarker)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JavMarker other = (JavMarker)o;
|
||||
return getMessage().equals(other.getMessage()) && getPoint().getPositionInCode() == other.getPoint().getPositionInCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getPoint().getPositionInCode();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package typinferenzplugin;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPairMap;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import typinferenzplugin.editor.JavEditor;
|
||||
|
||||
public class TypeReplaceMarker extends JavMarker {
|
||||
@ -11,13 +10,22 @@ public class TypeReplaceMarker extends JavMarker {
|
||||
private JavEditor editor;
|
||||
private CodePoint point;
|
||||
private TypeInsert tip;
|
||||
private ResultPair<?, ?> resultPair;
|
||||
private ResultSet resultSet;
|
||||
|
||||
public TypeReplaceMarker(JavEditor editor, TypeInsert point){
|
||||
public TypeReplaceMarker(JavEditor editor, ResultSet resultSet, TypeInsert point){
|
||||
this.editor = editor;
|
||||
this.point = new CodePoint(point.point.point);
|
||||
this.tip = point;
|
||||
this.resultPair = resultPair;
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPositionInCode() {
|
||||
return tip.point.getPositionInCode();
|
||||
}
|
||||
|
||||
public boolean isConsistent(TypeReplaceMarker other) {
|
||||
return this.resultSet.contains(ResultPairMap.RESULT_PAIRS.get(other.point.offset, other.tip.getInsertString()));
|
||||
}
|
||||
|
||||
public void run(){
|
||||
@ -76,5 +84,4 @@ public class TypeReplaceMarker extends JavMarker {
|
||||
return ((TypeReplaceMarker)obj).tip.equals(this.tip);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,14 +97,13 @@ public class Typinferenz {
|
||||
return this.tiResults;
|
||||
}
|
||||
|
||||
public Vector<JavMarker> updateWithResult(Vector<JavMarker> ret, List<ResultSet> tiResults) {
|
||||
public Vector<TypeReplaceMarker> updateWithResult(Vector<TypeReplaceMarker> ret, List<ResultSet> tiResults) {
|
||||
this.tiResults.addAll(tiResults);
|
||||
Set<TypeInsert> tips = new HashSet<>();
|
||||
for (ResultSet tiResult : tiResults) {
|
||||
tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult));
|
||||
int numberOfSolutions = 0; // Zählt mit, wie viele verschiedene Lösungen angeboten werden
|
||||
for (TypeInsert p : tips) {
|
||||
TypeReplaceMarker toAdd = new TypeReplaceMarker(editor, p);
|
||||
TypeReplaceMarker toAdd = new TypeReplaceMarker(editor, tiResult, p);
|
||||
if (!ret.contains(toAdd)) {
|
||||
ret.add(toAdd);
|
||||
} else {
|
||||
@ -116,10 +115,8 @@ public class Typinferenz {
|
||||
String outputDirectory = editor.getFilePath().toString();
|
||||
outputDirectory = outputDirectory.substring(0,
|
||||
outputDirectory.length() - editor.getFilePath().lastSegment().length());// ".jav" hat Länge 4
|
||||
// if(tips.size() == 0 && tiResults.size()>0) {
|
||||
if (tiResults.size() > 0) {
|
||||
for (SourceFile sf : compiler.sourceFiles.values()) {
|
||||
// HashMap<String,byte[]> bytecode = getBytecode(sf, tiResults.get(0));
|
||||
HashMap<String, byte[]> bytecode = getBytecode(sf, tiResults, outputDirectory);
|
||||
this.writeClassFile(outputDirectory, bytecode);
|
||||
}
|
||||
|
@ -168,12 +168,12 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
|
||||
CodePoint point = rm.getPoint();
|
||||
try {
|
||||
IMarker m = inDocument.createMarker(Activator.TYPINFERENZMARKER_NAME);
|
||||
m.setAttribute(IMarker.CHAR_START, point.getPositionInCode());
|
||||
m.setAttribute(IMarker.CHAR_END, point.getPositionInCode() + 1);
|
||||
m.setAttribute(IMarker.CHAR_START, rm.getPositionInCode());
|
||||
m.setAttribute(IMarker.CHAR_END, rm.getPositionInCode() + 1);
|
||||
String message = rm.getMessage();
|
||||
m.setAttribute(IMarker.MESSAGE, message);
|
||||
m.setAttribute(IMarker.SEVERITY, 1);
|
||||
rm.setAnnotation(this.addAnnotation(m, point.getPositionInCode()));
|
||||
rm.setAnnotation(this.addAnnotation(m, rm.getPositionInCode()));
|
||||
} catch (CoreException e) {
|
||||
new ErrorOutput("Fehler beim Generieren eines Markers");
|
||||
e.printStackTrace();
|
||||
@ -237,7 +237,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
|
||||
|
||||
/**
|
||||
* Diese Funktion führt einen ReplaceMarker aus.
|
||||
*
|
||||
* Minli
|
||||
* @param typeReplaceMarker
|
||||
*/
|
||||
public void runReplaceMarker(TypeReplaceMarker typeReplaceMarker) {
|
||||
@ -250,17 +250,18 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
|
||||
this.typeReconstruction();
|
||||
*/
|
||||
|
||||
typeReplaceMarkers.remove(typeReplaceMarker);
|
||||
typeReplaceMarkers.removeIf(trm -> trm.getPoint().getPositionInCode() == typeReplaceMarker.getPoint().getPositionInCode());
|
||||
typeReplaceMarkers.removeIf(trm -> !trm.isConsistent(typeReplaceMarker));
|
||||
|
||||
int lengthOfInsert = typeReplaceMarker.getInsertPoint().getInsertString().length();
|
||||
for (int i = 0; i < typeReplaceMarkers.size(); i++) {
|
||||
TypeReplaceMarker toCheck = typeReplaceMarkers.get(i);
|
||||
|
||||
for (TypeReplaceMarker toCheck : typeReplaceMarkers) {
|
||||
if (toCheck.getPoint().getPositionInCode() > typeReplaceMarker.getPoint().getPositionInCode()) {
|
||||
toCheck.getInsertPoint().point.addExtraOffset(lengthOfInsert);;
|
||||
toCheck.getInsertPoint().point.addExtraOffset(lengthOfInsert);
|
||||
}
|
||||
}
|
||||
|
||||
updateGuiWithNewMarkers(typeReplaceMarkers);
|
||||
|
||||
/*
|
||||
ResultPair<?, ?> resultPairOfCurrentTrm = RESULT_PAIRS.get(typeReplaceMarker.getPoint().offset);
|
||||
|
||||
@ -391,7 +392,7 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void onNewTypeResultFound(UnifyResultEvent evt) {
|
||||
Set<JavMarker> markers = updateMarkers(evt);
|
||||
Vector<TypeReplaceMarker> 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
|
||||
@ -404,11 +405,13 @@ public class JavEditor extends TextEditor implements UnifyResultListener {
|
||||
|
||||
}
|
||||
|
||||
private Set<JavMarker> updateMarkers(UnifyResultEvent evt) {
|
||||
private Vector<TypeReplaceMarker> updateMarkers(UnifyResultEvent evt) {
|
||||
typeinference.updateresultSets(new Vector(evt.getNewTypeResult()));
|
||||
|
||||
Set<JavMarker> markers = new HashSet<JavMarker>();
|
||||
typeReplaceMarkers.addAll(typeinference.updateWithResult(new Vector(markers), evt.getNewTypeResult()));
|
||||
Vector<TypeReplaceMarker> markers = new Vector<TypeReplaceMarker>();
|
||||
Vector<TypeReplaceMarker> newMarkers = typeinference.updateWithResult(markers, evt.getNewTypeResult());
|
||||
typeReplaceMarkers.removeAll(newMarkers);
|
||||
typeReplaceMarkers.addAll(newMarkers);
|
||||
|
||||
for (TypeReplaceMarker m : this.getTypeReplaceMarkers()) {
|
||||
markers.add(m);
|
||||
|
Loading…
Reference in New Issue
Block a user