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

View File

@ -32,7 +32,7 @@ public class TypeInsertFactory {
ResolvedType resolvedType = resultSet.resolveType(type);
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
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){

View File

@ -7,6 +7,8 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import java.util.Set;
public class ResolvedType{
private ResultPair<?, ?> resultPair;
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
//public final Set<GenericInsertPair> additionalGenerics;
@ -14,4 +16,12 @@ public class ResolvedType{
this.resolvedType = resolvedType;
//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.
}
public void put(Token tkn, ResultPair<?, ?> resultPair) {
inner.put(tkn, resultPair);
}
public void put(Token tkn, String insertString, ResultPair<?, ?> resultPair) {
indexMap.put(tkn, insertString.trim(), resultPair);
inner.put(tkn, resultPair);

View File

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