ResultPair durchgeschleift.

This commit is contained in:
Michael Uhl 2019-05-07 10:38:25 +02:00
parent 4b8b0ec362
commit 1f20fecfee
5 changed files with 34 additions and 4 deletions

View File

@ -4,16 +4,20 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.result.ResultPair;
public class TypeInsert { public class TypeInsert {
/** /**
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt. * point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
*/ */
public final TypeInsertPoint point; public final TypeInsertPoint point;
Set<TypeInsertPoint> inserts; Set<TypeInsertPoint> inserts;
ResultPair<?, ?> resultPair;
public TypeInsert(TypeInsertPoint point, Set<TypeInsertPoint> additionalPoints){ public TypeInsert(TypeInsertPoint point, Set<TypeInsertPoint> additionalPoints, ResultPair<?, ?> resultPair){
this.point = point; this.point = point;
inserts = additionalPoints; inserts = additionalPoints;
this.resultPair = resultPair;
} }
public String insert(String intoSource){ public String insert(String intoSource){
@ -31,6 +35,10 @@ public class TypeInsert {
return point.getInsertString(); return point.getInsertString();
} }
public ResultPair<?, ?> getResultPair() {
return this.resultPair;
}
/* PL 2018-06-18 /* PL 2018-06-18
* Zwei TypeInsert's sind gleich, wenn ihre point's und ihre inserts' gleich sind * Zwei TypeInsert's sind gleich, wenn ihre point's und ihre inserts' gleich sind
* eingefuegt damit man TypeReplaceMarker vergleichen kann * eingefuegt damit man TypeReplaceMarker vergleichen kann

View File

@ -32,7 +32,7 @@ public class TypeInsertFactory {
ResolvedType resolvedType = resultSet.resolveType(type); ResolvedType resolvedType = resultSet.resolveType(type);
TypeInsertPoint insertPoint = new TypeInsertPoint(offset, TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
new TypeToInsertString(resolvedType.resolvedType).insert); new TypeToInsertString(resolvedType.resolvedType).insert);
return new TypeInsert(insertPoint, new HashSet<>()); return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
} }
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){ private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){

View File

@ -7,6 +7,8 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import java.util.Set; import java.util.Set;
public class ResolvedType{ public class ResolvedType{
private ResultPair<?, ?> resultPair;
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType; public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
//public final Set<GenericInsertPair> additionalGenerics; //public final Set<GenericInsertPair> additionalGenerics;
@ -14,4 +16,12 @@ public class ResolvedType{
this.resolvedType = resolvedType; this.resolvedType = resolvedType;
//this.additionalGenerics = additionalGenerics; //this.additionalGenerics = additionalGenerics;
} }
public void setResultPair(ResultPair<?, ?> resultPair) {
this.resultPair = resultPair;
}
public ResultPair<?, ?> getResultPair() {
return resultPair;
}
} }

View File

@ -19,6 +19,10 @@ public class ResultPairMap {
// Nothing to do here. // Nothing to do here.
} }
public void put(Token tkn, ResultPair<?, ?> resultPair) {
inner.put(tkn, resultPair);
}
public void put(Token tkn, String insertString, ResultPair<?, ?> resultPair) { public void put(Token tkn, String insertString, ResultPair<?, ?> resultPair) {
indexMap.put(tkn, insertString.trim(), resultPair); indexMap.put(tkn, insertString.trim(), resultPair);
inner.put(tkn, resultPair); inner.put(tkn, resultPair);

View File

@ -73,6 +73,7 @@ class Resolver implements ResultSetVisitor {
private TypePlaceholder toResolve; private TypePlaceholder toResolve;
private RefTypeOrTPHOrWildcardOrGeneric resolved; private RefTypeOrTPHOrWildcardOrGeneric resolved;
private final Set<GenericInsertPair> additionalTPHs = new HashSet<>(); private final Set<GenericInsertPair> additionalTPHs = new HashSet<>();
private ResultPair<?,?> currentPair;
public Resolver(ResultSet resultPairs){ public Resolver(ResultSet resultPairs){
this.result = resultPairs; this.result = resultPairs;
@ -84,21 +85,28 @@ class Resolver implements ResultSetVisitor {
System.out.println(tph.toString()); System.out.println(tph.toString());
for(ResultPair<?,?> resultPair : result.results) { for(ResultPair<?,?> resultPair : result.results) {
if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){ if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
currentPair = resultPair;
return resolve(((PairTPHEqualTPH) resultPair).getRight()); return resolve(((PairTPHEqualTPH) resultPair).getRight());
} }
} }
for(ResultPair<?,?> resultPair : result.results){ for(ResultPair<?,?> resultPair : result.results){
currentPair = resultPair;
RESULT_PAIRS.put(resultPair.getLeft().getOffset(), resultPair);
RESULT_PAIRS.put(resultPair.getRight().getOffset(), resultPair);
resultPair.accept(this); resultPair.accept(this);
} }
if(resolved==null){//TPH kommt nicht im Result vor: if(resolved==null){//TPH kommt nicht im Result vor:
resolved = tph; resolved = tph;
} }
return new ResolvedType(resolved, additionalTPHs);//resolved; ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved;
result.setResultPair(currentPair);
return result;
} }
@Override @Override
public void visit(PairTPHsmallerTPH p) { public void visit(PairTPHsmallerTPH p) {
currentPair = p;
if(p.left.equals(toResolve)){ if(p.left.equals(toResolve)){
additionalTPHs.add(new GenericInsertPair(p.left, p.right)); additionalTPHs.add(new GenericInsertPair(p.left, p.right));
additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs); additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
@ -109,9 +117,9 @@ class Resolver implements ResultSetVisitor {
@Override @Override
public void visit(PairTPHequalRefTypeOrWildcardType p) { public void visit(PairTPHequalRefTypeOrWildcardType p) {
currentPair = p;
if(p.left.equals(toResolve)){ if(p.left.equals(toResolve)){
resolved = p.right; resolved = p.right;
RESULT_PAIRS.put(p.left.getOffset(), p.right.toString(), p);
RelatedTypeWalker related = new RelatedTypeWalker(null, result); RelatedTypeWalker related = new RelatedTypeWalker(null, result);
p.right.accept(related); p.right.accept(related);
additionalTPHs.addAll(related.relatedTPHs); additionalTPHs.addAll(related.relatedTPHs);