From 1f20fecfee4f6656d3475e239943506188ab28d2 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Tue, 7 May 2019 10:38:25 +0200 Subject: [PATCH] ResultPair durchgeschleift. --- .../de/dhbwstuttgart/typedeployment/TypeInsert.java | 10 +++++++++- .../typedeployment/TypeInsertFactory.java | 2 +- .../typeinference/result/ResolvedType.java | 10 ++++++++++ .../typeinference/result/ResultPairMap.java | 4 ++++ .../typeinference/result/ResultSet.java | 12 ++++++++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsert.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsert.java index 04ee340c..d7e53552 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsert.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsert.java @@ -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 inserts; + ResultPair resultPair; - public TypeInsert(TypeInsertPoint point, Set additionalPoints){ + public TypeInsert(TypeInsertPoint point, Set 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 diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index a2abf30b..3fee03f6 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -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 toInsert, ClassOrInterface cl, Method m){ diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResolvedType.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResolvedType.java index eb43a296..8e7e8451 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResolvedType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResolvedType.java @@ -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 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; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java index 1a93d6ad..d032ace2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java @@ -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); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java index 51f3c106..0f60a0a1 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -73,6 +73,7 @@ class Resolver implements ResultSetVisitor { private TypePlaceholder toResolve; private RefTypeOrTPHOrWildcardOrGeneric resolved; private final Set 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);