From 23c37a8cc2224060f08ea1214bf216e2de2e28da Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Fri, 19 Apr 2019 20:49:28 +0200 Subject: [PATCH] Richtiges Einsetzen ohne Speichern. --- .../typedeployment/TypeInsertPoint.java | 5 +++++ .../typeinference/result/ResultPairMap.java | 15 ++++++++++----- .../typeinference/result/ResultSet.java | 3 +-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java index 13fdae63..4c495d65 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java @@ -4,6 +4,7 @@ import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import java.time.OffsetDateTime; import java.util.List; import java.util.stream.Collectors; @@ -33,6 +34,10 @@ public class TypeInsertPoint { this.extraOffset += toAdd; } + public int getPositionInCode() { + return point.getStartIndex() + extraOffset; + } + /* PL 2018-06-19 * Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind * eingefuegt damit man TypeReplaceMarker vergleichen kann diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java index 4f2a7ebc..e04c21ad 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairMap.java @@ -5,9 +5,13 @@ import java.util.Map; import org.antlr.v4.runtime.Token; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + public class ResultPairMap { - private Map> indexMap = new HashMap<>(); + private Table> indexMap = HashBasedTable.create(); + private Map> inner = new HashMap<>(); public static final ResultPairMap RESULT_PAIRS = new ResultPairMap(); @@ -15,11 +19,12 @@ public class ResultPairMap { // Nothing to do here. } - public void put(Token tkn, ResultPair resultPair) { - indexMap.put(tkn, resultPair); + public void put(Token tkn, String insertString, ResultPair resultPair) { + indexMap.put(tkn, insertString.trim(), resultPair); + inner.put(tkn, resultPair); } - public ResultPair get(Token tkn) { - return indexMap.get(tkn); + public ResultPair get(Token tkn, String insertString) { + return inner.get(tkn); } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java index 7af159d6..9b9aef4e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -65,8 +65,6 @@ class Resolver implements ResultSetVisitor { resolved = null; System.out.println(tph.toString()); for(ResultPair resultPair : result.results) { - RESULT_PAIRS.put(resultPair.getRight().getOffset(), resultPair); - RESULT_PAIRS.put(resultPair.getLeft().getOffset(), resultPair); if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){ return resolve(((PairTPHEqualTPH) resultPair).getRight()); } @@ -95,6 +93,7 @@ class Resolver implements ResultSetVisitor { public void visit(PairTPHequalRefTypeOrWildcardType 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);