diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 72b9ccd8a..2e1ce08a9 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -147,8 +147,7 @@ public class UnifyTypeFactory { 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 RefType)return new PairTPHequalRefType((TypePlaceholder)tl, (RefType)tr); - throw new NotImplementedException(); + return new PairTPHequalRefType((TypePlaceholder)tl, tr); }else throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index b1aebc8d9..19a5deae1 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -3,9 +3,7 @@ package de.dhbwstuttgart.typedeployment; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.type.*; -import de.dhbwstuttgart.typeinference.result.GenericInsertPair; -import de.dhbwstuttgart.typeinference.result.ResolvedType; -import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.result.*; import org.antlr.v4.runtime.Token; import java.util.*; @@ -35,10 +33,8 @@ public class TypeInsertFactory { Set ret = new HashSet<>(); TypeInsertPoint insertPoint = null; ResolvedType resolvedType = resultSet.resolveType(type); - if(resolvedType.resolvedType instanceof RefType){ insertPoint = new TypeInsertPoint(offset, - createInsertString((RefType) resolvedType.resolvedType)); - } + new TypeToInsertString(resolvedType.resolvedType).insert); return new TypeInsert(insertPoint, new HashSet<>(Arrays.asList(createGenericInsert(resolvedType.additionalGenerics, cl, m)))); /* for (Pair pair : pairs) { @@ -107,29 +103,6 @@ public class TypeInsertFactory { */ } - private static String createInsertString(RefType resolved) { - String insert = resolved.getName().toString(); - if(resolved.getParaList().size() > 0){ - insert += "<"; - Iterator iterator = resolved.getParaList().iterator(); - while(iterator.hasNext()){ - RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next(); - if(typeParam instanceof TypePlaceholder){ - insert += ((TypePlaceholder) typeParam).getName(); - }else if(typeParam instanceof RefType) { - insert += createInsertString((RefType) typeParam); - }else if(typeParam instanceof SuperWildcardType){ - insert += "? super " + createInsertString(((SuperWildcardType) typeParam).getInnerType()); - }else if(typeParam instanceof ExtendsWildcardType){ - insert += "? extends " + createInsertString(((ExtendsWildcardType) typeParam).getInnerType()); - }else throw new NotImplementedException(); - if(iterator.hasNext())insert += ", "; - } - insert += ">"; - } - return insert; - } - private static TypeInsertPoint createGenericInsert(Set toInsert, ClassOrInterface cl, Method m){ //Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt: //Offset zum Einstzen bestimmen: @@ -180,4 +153,57 @@ public class TypeInsertFactory { } return new TypeInsertPoint(offset, insert + end); } +} + +class TypeToInsertString implements ResultSetVisitor{ + String insert = ""; + + TypeToInsertString(RefTypeOrTPHOrWildcardOrGeneric type){ + type.accept(this); + } + + @Override + public void visit(PairTPHsmallerTPH p) { + + } + + @Override + public void visit(PairTPHequalRefType p) { + + } + + @Override + public void visit(RefType resolved) { + insert = resolved.getName().toString(); + if(resolved.getParaList().size() > 0){ + insert += "<"; + Iterator iterator = resolved.getParaList().iterator(); + while(iterator.hasNext()){ + RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next(); + insert += new TypeToInsertString(typeParam).insert; + if(iterator.hasNext())insert += ", "; + } + insert += ">"; + } + } + + @Override + public void visit(GenericRefType genericRefType) { + insert += genericRefType.getName(); + } + + @Override + public void visit(SuperWildcardType superWildcardType) { + insert += "? super " + new TypeToInsertString(superWildcardType.getInnerType()).insert; + } + + @Override + public void visit(TypePlaceholder typePlaceholder) { + insert += typePlaceholder.getName(); + } + + @Override + public void visit(ExtendsWildcardType extendsWildcardType) { + insert += "? extends " + new TypeToInsertString(extendsWildcardType.getInnerType()).insert; + } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index 17ef45851..467172c46 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -3,8 +3,6 @@ package de.dhbwstuttgart.typedeployment; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.constraints.Pair; -import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; import java.util.HashSet; diff --git a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java index 71db19d82..418dff9d7 100644 --- a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java +++ b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.result; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; /** @@ -8,9 +9,9 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; */ public class PairTPHequalRefType extends ResultPair{ public final TypePlaceholder left; - public final RefType right; + public final RefTypeOrTPHOrWildcardOrGeneric right; - public PairTPHequalRefType(TypePlaceholder left, RefType right){ + public PairTPHequalRefType(TypePlaceholder left, RefTypeOrTPHOrWildcardOrGeneric 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 289c53443..4fc99540e 100644 --- a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -36,7 +36,7 @@ public class ResultSet { class Resolver implements ResultSetVisitor { private final ResultSet result; private TypePlaceholder toResolve; - private RefType resolved; + private RefTypeOrTPHOrWildcardOrGeneric resolved; private final Set additionalTPHs = new HashSet<>(); public Resolver(ResultSet resultPairs){ @@ -50,7 +50,6 @@ class Resolver implements ResultSetVisitor { resultPair.accept(this); } if(resolved==null){//TPH kommt nicht im Result vor: - } return new ResolvedType(resolved, additionalTPHs);//resolved; @@ -71,7 +70,7 @@ class Resolver implements ResultSetVisitor { if(p.left.equals(toResolve)){ resolved = p.right; RelatedTypeWalker related = new RelatedTypeWalker(null, result); - related.visit(p.right); + p.right.accept(related); additionalTPHs.addAll(related.relatedTPHs); } } diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 2aac0f6ad..2f9395fdd 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -25,8 +25,8 @@ public class JavaTXCompilerTest extends JavaTXCompiler { @Test public void test() throws IOException, java.lang.ClassNotFoundException { //filesToTest.add(new File(rootDirectory+"Faculty.jav")); - //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); - filesToTest.add(new File(rootDirectory+"test.jav")); + filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + //filesToTest.add(new File(rootDirectory+"test.jav")); //filesToTest.add(new File(rootDirectory+"Lambda.jav")); //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); //filesToTest.add(new File(rootDirectory+"Lambda3.jav"));