diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index 7e857600..6cded807 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -58,7 +58,9 @@ public class TPHConstraint { public boolean equals (Object o) { if (o instanceof TPHConstraint) { TPHConstraint o_tphcons = (TPHConstraint)o; - return (left+right).equals(o_tphcons.getLeft()+o_tphcons.getRight()); + return (this.left.equals(o_tphcons.getLeft()) + && this.right.equals(o_tphcons.getRight()) + && this.rel.equals(o_tphcons.rel)); } else { return false; diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index 55e9a09a..e861e6e4 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -56,16 +56,16 @@ public class TestGGFinder { List classConstraintsTest = new ArrayList<>(); classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); @@ -78,7 +78,10 @@ public class TestGGFinder { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index ea8071d7..530ef318 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -55,12 +55,12 @@ public class TestLocalVarLambda { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); FamilyOfGeneratedGenerics fogg = compiler.fogg; - List lmc; - lmc = new ArrayList<>(); + Set lmc; + lmc = new HashSet<>(); if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) { lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS)); @@ -79,7 +79,10 @@ public class TestLocalVarLambda { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestMutualRecursion.java b/src/test/java/insertGenerics/TestMutualRecursion.java index 30778032..fac445ed 100644 --- a/src/test/java/insertGenerics/TestMutualRecursion.java +++ b/src/test/java/insertGenerics/TestMutualRecursion.java @@ -49,18 +49,19 @@ public class TestMutualRecursion { List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS)); lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); @@ -71,8 +72,11 @@ public class TestMutualRecursion { Set expectedClassCons = new HashSet<>(classConstraintsTest); assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 9254100f..2b475bbf 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -56,12 +56,12 @@ public class TestTPHsAndGenerics { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); FamilyOfGeneratedGenerics fogg = compiler.fogg; - List lmc; - lmc = new ArrayList<>(); + Set lmc; + lmc = new HashSet<>(); if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); @@ -74,10 +74,10 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } @@ -92,10 +92,10 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } @@ -105,7 +105,10 @@ public class TestTPHsAndGenerics { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index e492c49f..8016a039 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -61,20 +61,20 @@ public class TestTwoArgs { classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS)); lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); @@ -84,9 +84,12 @@ public class TestTwoArgs { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(expectedClassCons, computedClassCons); + assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index 518ca0ad..035e9fb2 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -55,13 +55,13 @@ public class TestTwoCalls { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS)); lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); @@ -73,8 +73,12 @@ public class TestTwoCalls { Set expectedClassCons = new HashSet<>(classConstraintsTest); assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index b902e93e..8245ff9d 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -55,14 +55,14 @@ public class TestVector { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); @@ -70,9 +70,12 @@ public class TestVector { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(expectedClassCons, computedClassCons); + assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className);