From 276ff44756ba565c72729670239df14c43b308c0 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 25 Sep 2017 11:22:53 +0200 Subject: [PATCH] =?UTF-8?q?Ber=C3=BCcksichtige=20TPH=20=3D.=20TPH=20Ergebn?= =?UTF-8?q?isse=20im=20ResultSet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/factory/UnifyTypeFactory.java | 7 ++++- .../typeinference/result/ResultSet.java | 28 ++++++++++++++++--- test/typeinference/JavaTXCompilerTest.java | 5 +++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index a4c40b98..06ea16c1 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -146,7 +146,12 @@ public class UnifyTypeFactory { RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs); RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs); if(tl instanceof TypePlaceholder){ - if(tr instanceof TypePlaceholder) return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr); + if(tr instanceof TypePlaceholder) { + if(mp.getPairOp().equals(PairOperator.EQUALSDOT)) + return new PairTPHequalRefType((TypePlaceholder)tl, tr); + else + return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr); + } return new PairTPHequalRefType((TypePlaceholder)tl, tr); }else throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java index 6a1d67f9..2199622b 100644 --- a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.result; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.AbstractASTWalker; import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.typeinference.constraints.Pair; @@ -24,7 +25,8 @@ public class ResultSet { type.accept(related); return new ResolvedType(type, related.relatedTPHs); }else{ - return new ResolvedType(type,new HashSet<>()); + throw new NotImplementedException(); + //return new ResolvedType(type,new HashSet<>()); } } @@ -68,11 +70,29 @@ class Resolver implements ResultSetVisitor { @Override public void visit(PairTPHequalRefType p) { + RefTypeOrTPHOrWildcardOrGeneric otherSide = null; if(p.left.equals(toResolve)){ resolved = p.right; - RelatedTypeWalker related = new RelatedTypeWalker(null, result); - p.right.accept(related); - additionalTPHs.addAll(related.relatedTPHs); + 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){ + Set newResultSet = new HashSet<>(result.results); + newResultSet.remove(p); + ResolvedType resolvedType = new Resolver(new ResultSet(newResultSet)).resolve((TypePlaceholder) resolved); + this.resolved = resolvedType.resolvedType; + this.additionalTPHs.addAll(resolvedType.additionalGenerics); + }else { + throw new NotImplementedException(); + } } } diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 0fccae5c..7ea13498 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -49,8 +49,11 @@ public class JavaTXCompilerTest { for(File f : compiler.sourceFiles.keySet()){ SourceFile sf = compiler.sourceFiles.get(f); System.out.println(ASTTypePrinter.print(sf)); - for(ResultSet resultSet : compiler.typeInference()){ + List results = compiler.typeInference(); + assert results.size()>0; + for(ResultSet resultSet : results){ Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); + assert result.size()>0; String content = readFile(f.getPath(), StandardCharsets.UTF_8); for(TypeInsert tip : result){ System.out.println(tip.insert(content));