From 0c80a4c34305e05dcaa05f5c3ec15313e0a4273c Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 16 Oct 2017 19:19:42 +0200 Subject: [PATCH] Fix bei Typeinsetzung --- .../syntaxtree/factory/UnifyTypeFactory.java | 5 ++- .../typedeployment/TypeInsertFactory.java | 1 - .../result/PairTPHequalRefType.java | 4 +- .../typeinference/result/ResultSet.java | 43 ++++--------------- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 06ea16c1..c154e86f 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.factory; import java.util.*; import java.util.stream.Collectors; +import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.scope.JavaClassName; @@ -148,11 +149,11 @@ public class UnifyTypeFactory { if(tl instanceof TypePlaceholder){ if(tr instanceof TypePlaceholder) { if(mp.getPairOp().equals(PairOperator.EQUALSDOT)) - return new PairTPHequalRefType((TypePlaceholder)tl, tr); + throw new DebugException("TPH =. TPH ist ein ungültiges Ergebnis"); else return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr); } - return new PairTPHequalRefType((TypePlaceholder)tl, tr); + return new PairTPHequalRefType((TypePlaceholder)tl, (RefType) tr); }else throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index 737ef669..b9eea3c6 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -29,7 +29,6 @@ public class TypeInsertFactory { public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m, ResultSet resultSet) { - Set ret = new HashSet<>(); ResolvedType resolvedType = resultSet.resolveType(type); TypeInsertPoint insertPoint = new TypeInsertPoint(offset, new TypeToInsertString(resolvedType.resolvedType).insert); diff --git a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java index 418dff9d..bf29ce52 100644 --- a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java +++ b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java @@ -9,9 +9,9 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; */ public class PairTPHequalRefType extends ResultPair{ public final TypePlaceholder left; - public final RefTypeOrTPHOrWildcardOrGeneric right; + public final RefType right; - public PairTPHequalRefType(TypePlaceholder left, RefTypeOrTPHOrWildcardOrGeneric right){ + public PairTPHequalRefType(TypePlaceholder left, RefType right){ super(left, right); this.left = left; this.right = right; diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java index c28570ae..0b2cfbf9 100644 --- a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -72,34 +72,11 @@ class Resolver implements ResultSetVisitor { @Override public void visit(PairTPHequalRefType p) { - RefTypeOrTPHOrWildcardOrGeneric otherSide = null; if(p.left.equals(toResolve)){ resolved = p.right; - otherSide = p.left; - } - if(p.right.equals(toResolve)){ - resolved = p.left; - otherSide = p.right; - } - if(otherSide != null){ - if(resolved instanceof RefType){ - RelatedTypeWalker related = new RelatedTypeWalker(null, result); - otherSide.accept(related); - additionalTPHs.addAll(related.relatedTPHs); - }else if(resolved instanceof TypePlaceholder){ - RelatedTypeWalker related = new RelatedTypeWalker(null, result); - resolved.accept(related); - Set newResultSet = new HashSet<>(result.results); - newResultSet.remove(p); - additionalTPHs.add(new GenericInsertPair((TypePlaceholder)resolved, null)); - ResolvedType resolvedType = new Resolver(new ResultSet(newResultSet)).resolve((TypePlaceholder) resolved); - this.resolved = resolvedType.resolvedType; - this.additionalTPHs.addAll(resolvedType.additionalGenerics); - resolved.accept(related); - this.additionalTPHs.addAll(related.relatedTPHs); - }else { - throw new NotImplementedException(); - } + RelatedTypeWalker related = new RelatedTypeWalker(null, result); + p.right.accept(related); + additionalTPHs.addAll(related.relatedTPHs); } } @@ -160,14 +137,10 @@ class TPHResolver implements ResultSetVisitor { @Override public void visit(PairTPHequalRefType p) { TypePlaceholder otherSide = null; - if(p.left.equals(tph) && p.right instanceof TypePlaceholder){ - otherSide = (TypePlaceholder) p.right; - } if(p.right.equals(tph)){ otherSide = p.left; } if(otherSide != null){ - resolved.add(new GenericInsertPair(p.left, (TypePlaceholder) p.right)); Set newResultSet = new HashSet<>(this.resultSet.results); newResultSet.remove(p); resolved.addAll(new TPHResolver(otherSide, new ResultSet(newResultSet)).resolved); @@ -216,11 +189,11 @@ class RelatedTypeWalker implements ResultSetVisitor { this.resultSet = resultSet; int resolved = 0; do{ - resolved = relatedTPHs.size(); - for(ResultPair p : resultSet.results){ - p.accept(this); - p.accept(this); - } + resolved = relatedTPHs.size(); + for(ResultPair p : resultSet.results){ + p.accept(this); + p.accept(this); + } }while(resolved - relatedTPHs.size() > 0); }