diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 1b7ceea4..a258e5fb 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -47,8 +47,9 @@ public class ASTToTargetAST { } @Override - void generics(ClassOrInterface owner, Method method, Set> result, HashSet referenced) { + void generics(ClassOrInterface owner, Method method, Set> result, Set referenced) { eliminateInfima(result, referenced); + eliminateInnerTypeVariables(referenced, result); } @Override @@ -64,18 +65,19 @@ public class ASTToTargetAST { } @Override - void generics(ClassOrInterface owner, Method method, Set> result, HashSet referenced) { + void generics(ClassOrInterface owner, Method method, Set> result, Set referenced) { eliminateCycles(result, referenced); eliminateInfima(result, referenced); equalizeTypeVariables(result, referenced); + eliminateInnerTypeVariables(referenced, result); } @Override void generics(ClassOrInterface classOrInterface, Set> result, Set referenced) { eliminateCycles(result, referenced); eliminateInfima(result, referenced); - eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced); equalizeTypeVariables(result, referenced); + eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced); } } @@ -172,7 +174,7 @@ public class ASTToTargetAST { static Set> transitiveClosure(Set> generics) { Set> all = new HashSet<>(generics); - HashSet> toAdd = new HashSet<>(); + Set> toAdd = new HashSet<>(); int sizeBefore; do { sizeBefore = all.size(); @@ -221,7 +223,7 @@ public class ASTToTargetAST { //Anfang es werden Paare von TPHs gespeichert, die bei den Generated Generics ueber die Methodengrenzen hinweg //betrachtet werden muessen //Definition 7.2 (Family of generated generics). T1 <. R1 <.^∗ R2 <. T2 - Set T1s = + Set T1s = methodCall.getArgumentList() .getArguments() .stream() @@ -230,10 +232,10 @@ public class ASTToTargetAST { .stream().filter(x -> x instanceof TypePlaceholder) .map(tph -> equality.getOrDefault(tph, (TypePlaceholder) tph)) .collect(Collectors.toCollection(HashSet::new)); - RefTypeOrTPHOrWildcardOrGeneric T2 = superType; - if (T2 instanceof TypePlaceholder tph) T2 = equality.getOrDefault(tph, tph); + Set T2s = new HashSet<>(); + findTphs(superType, T2s); - System.out.println("T1s: " + T1s + " T2: " + T2); + System.out.println("T1s: " + T1s + " T2s: " + T2s); //Ende superType = methodCall.receiverType; @@ -264,6 +266,7 @@ public class ASTToTargetAST { // Loop from hell outer: for (var R1 : typeVariables) { + R1 = equality.getOrDefault(R1, R1); if (typeVariablesOfClass.contains(R1)) continue; for (var generic : all) if (generic instanceof PairTPHsmallerTPH ptph) { var l = equality.getOrDefault(ptph.left, ptph.left); @@ -276,13 +279,17 @@ public class ASTToTargetAST { continue; for (var R2 : typeVariables) { + R2 = equality.getOrDefault(R2, R2); for (var pair2 : simplifiedConstraints) { var l3 = equality.getOrDefault(pair2.left, pair2.left); var r3 = equality.getOrDefault(pair2.right, pair2.right); + if (!(r3.equals(R2) && l3.equals(r))) continue; if (R1.equals(R2)) continue; - if (!T1s.contains(R1) || !R2.equals(T2)) continue; + T2s = T2s.stream().map(tph -> equality.getOrDefault(tph, tph)).collect(Collectors.toSet()); + T1s = T1s.stream().map(tph -> equality.getOrDefault(tph, tph)).collect(Collectors.toSet()); + if (!T1s.contains(R1) || !T2s.contains(R2)) continue; var newPair = new PairTPHsmallerTPH(R1, R2); newPairs.add(newPair); @@ -466,7 +473,7 @@ public class ASTToTargetAST { }); } - abstract void generics(ClassOrInterface owner, Method method, Set> result, HashSet javaTypeVariablesOfClass); + abstract void generics(ClassOrInterface owner, Method method, Set> result, Set javaTypeVariablesOfClass); Set> family(ClassOrInterface owner, Method method) { if (familyOfMethods.containsKey(method)) @@ -492,8 +499,8 @@ public class ASTToTargetAST { } Set> generics(ClassOrInterface owner, Method method) { - //if (computedGenericsOfMethods.containsKey(method)) - // return computedGenericsOfMethods.get(method); + if (computedGenericsOfMethods.containsKey(method)) + return computedGenericsOfMethods.get(method); var classGenerics = generics(owner); @@ -520,7 +527,6 @@ public class ASTToTargetAST { generics(owner, method, result, referenced); usedTPHsOfMethods.put(method, usedTphs); - eliminateInnerTypeVariables(referenced, result); addMissingObjectBounds(result, classGenerics, usedTphs); System.out.println(this.getClass().getSimpleName() + " " + method.name + ": " + result);