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