diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 61be1e8c..4fa1b0a2 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -39,55 +39,17 @@ public class ASTToTargetAST { Sigma(ResultSet constraints) { ASTToTargetAST.this.sigma = this; - Set> equalitySet = new HashSet<>(); - Map> unified = new HashMap<>(); - - for (var constraint : constraints.results) { - if (constraint instanceof PairTPHEqualTPH p) { - if (unified.containsKey(p.getLeft())) { - var equals = unified.get(p.getLeft()); - equals.add(p.getRight()); - unified.put(p.getLeft(), equals); - } else if (unified.containsKey(p.getRight())) { - var equals = unified.get(p.getRight()); - equals.add(p.getLeft()); - unified.put(p.getRight(), equals); - } else { - List equals = new ArrayList<>(); - equals.add(p.getLeft()); - equals.add(p.getRight()); - unified.put(p.getLeft(), equals); - unified.put(p.getRight(), equals); - equalitySet.add(equals); - } - } - } - for (var constraint : constraints.results) { if (constraint instanceof PairTPHsmallerTPH p) { - var left = p.left; - var right = p.right; - if (unified.containsKey(left)) - left = unified.get(left).get(0); - if (unified.containsKey(right)) - right = unified.get(right).get(0); - - simplifiedConstraints.add(new PairTPHsmallerTPH(left, right)); - } - } - System.out.println("Simplified constraints: " + simplifiedConstraints); - - for (var equality : equalitySet) { - var first = equality.get(0); - for (var i = 1; i < equality.size(); i++) - this.equality.put(equality.get(i), first); - } - - for (var constraint : constraints.results) { - if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) { + simplifiedConstraints.add(p); + } else if (constraint instanceof PairTPHEqualTPH p) { + equality.put(p.getLeft(), p.getRight()); + } else if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) { concreteTypes.put(this.equality.getOrDefault(p.left, p.left), p.right); } } + + System.out.println("Simplified constraints: " + simplifiedConstraints); } void findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type, Set typeVariables) { diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index cf8cdac8..83ea8ec4 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -231,7 +231,6 @@ public class TestComplete { assertEquals(result, instanceOfClass_m3); } - @Ignore("Thread blocking for some reason") @Test public void matrixTest() throws Exception { var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader()); diff --git a/src/test/java/targetast/TphTest.java b/src/test/java/targetast/TphTest.java index c3f29c7f..837bdaeb 100644 --- a/src/test/java/targetast/TphTest.java +++ b/src/test/java/targetast/TphTest.java @@ -24,67 +24,10 @@ public class TphTest { @Test public void test1() throws Exception { - var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader()); - var classToTest = classFiles.get("Tph7"); - var instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - - //public DZU m(DZL, DZM); Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class); + Object result = m.invoke(instanceOfClass, 1,2); - //System.out.println(m.toString()); - - //Argumenttypes of the method m - var paraTypes = m.getGenericParameterTypes(); - - //Typeparameters of the method m - var typeParaTypes = m.getTypeParameters(); - - //Typeparameters are extracted from the argumenttypes - //Conditions for the extracted typeparameters are set - - //paraTypes[0] = DLZ - var boundFstArg = Arrays.stream(typeParaTypes) - .filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds(); - - //Bound of DLZ has to be Object - assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get()); - - //paraTypes[0] = DZM - var boundSndArg = Arrays.stream(typeParaTypes) - .filter(x -> x.equals(paraTypes[1])).findFirst().get().getBounds(); - - //Bound of DZM has to be the return type of m - assertEquals(Arrays.stream(boundSndArg).findFirst().get(), m.getGenericReturnType()); - - //Bound of the bound of DZM - var boundBoundSndArg = Arrays.stream(typeParaTypes).filter(x -> x.equals(Arrays.stream(boundSndArg) - .findFirst().get())).findFirst().get().getBounds(); - - //boundBoundSndArg have to be a type variable (type of the local variable c) - assertEquals(true, Arrays.stream(boundBoundSndArg).findFirst().get() instanceof TypeVariable); - m.getGenericParameterTypes(); - - //public DZU m2(DZU); - Method m2 = classToTest.getDeclaredMethod("m2", Object.class); - - //Argumenttypes of the method m2 - var paraTypesm2 = m2.getGenericParameterTypes(); - - //Typeparameters of the method m2 - var typeParaTypesm2 = m2.getTypeParameters(); - - //Typeparameters are extracted from the argumenttypes - //Conditions for the extracted typeparameters are set - - //paraTypes[0] = DZU - var fstArgm2 = Arrays.stream(typeParaTypesm2) - .filter(x -> x.equals(paraTypesm2[0])).findFirst().get(); - - //Bound of DZU has to be Object - assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get()); - - //DZU has to be the return type of m - assertEquals(fstArgm2, m2.getGenericReturnType()); + assertEquals(1,result); } @Test