diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index b28bfb411..3ebd54300 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -116,6 +116,8 @@ public class ASTToTargetAST { } return false; }); + } else if (input.stream().anyMatch(p -> p.getLeft().equals(pair.getLeft()))) { + return; } input.add(pair); @@ -605,14 +607,14 @@ public class ASTToTargetAST { if (left.equals(tph)) { var pair = new PairTPHsmallerTPH(tph, right); if (!generics.contains(pair)) { - generics.add(pair); + addToPairs(generics, pair); findAllBounds(right, generics, equality); found = true; } } } if (!found) - generics.add(new PairTPHequalRefTypeOrWildcardType(tph, OBJECT)); + addToPairs(generics, new PairTPHequalRefTypeOrWildcardType(tph, OBJECT)); } else if (type instanceof RefType refType) { refType.getParaList().forEach(t -> findAllBounds(t, generics, equality)); } @@ -663,7 +665,6 @@ public class ASTToTargetAST { } } } - System.out.println(input); } void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set tphs, Map equality) { diff --git a/src/test/java/targetast/TestGenerics.java b/src/test/java/targetast/TestGenerics.java index 23c8b1524..f6308861a 100644 --- a/src/test/java/targetast/TestGenerics.java +++ b/src/test/java/targetast/TestGenerics.java @@ -158,33 +158,30 @@ public class TestGenerics { var generics = result.genericsResults.get(0); assertEquals(1, generics.get(result.clazz).size()); - assertEquals(3, generics.get(id).size()); + assertEquals(2, generics.get(id).size()); assertEquals(2, generics.get(m).size()); assertEquals(3, generics.get(main).size()); - var M = generics.getBounds(a.getType(), result.clazz); - assertEquals(M, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT))); + var N = generics.getBounds(a.getType(), result.clazz); + assertEquals(N, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT))); - var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id); - var OChain = new BoundsList(new Bound(true, TypePlaceholder.of("P")), new Bound(true, ASTToTargetAST.OBJECT)); - assertEquals(O, OChain); - var AK = generics.getBounds(id.getReturnType(), result.clazz, id); - var AKChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)); - assertEquals(AK, AKChain); + var P = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id); + var O = generics.getBounds(id.getReturnType(), result.clazz, id); + assertEquals(P, O); + assertEquals(O, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT))); - // TODO Shouldn't AK and AK2 be the same and on the class? - var AK2 = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m); - var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m); - assertEquals(AK2, AKChain); - assertEquals(Y, AKChain); + assertEquals(generics.resolve(m.getParameterList().getParameterAt(0).getType()), generics.resolve(m.getReturnType())); + var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m); + var AA = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m); + assertEquals(Y, AA); + assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT))); - var AF = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main); - var AG= generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main); - var AK3 = generics.getBounds(main.getReturnType(), result.clazz, main); - var AFChain = new BoundsList(new Bound(true, TypePlaceholder.of("AG")), new Bound(true, ASTToTargetAST.OBJECT)); - assertEquals(AF, AFChain); - assertEquals(AG, AKChain); - assertEquals(AK3, AKChain); + var AI = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m); + var AJ = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m); + var AH = generics.getBounds(m.getReturnType(), result.clazz, m); + assertEquals(AI, AJ); + assertEquals(AJ, AH); + assertEquals(AH, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT))); } @Test