From e147a8ce85b2167b5bc0951adf92177ee409ea66 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 23 Mar 2021 12:02:58 +0100 Subject: [PATCH 1/5] toString geaendert, um Tests generieren zu koennen: modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java geaendert, um GenerateGenerics direkt teste zu koennen, sollte ggf. wieder rueckgaenig gemacht werden modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java angepasset Tests: modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java --- .../bytecode/constraint/TPHConstraint.java | 26 +++++++++++ .../GeneratedGenericsFinder.java | 10 +++++ .../insertGenerics/ClassConstraint.java | 9 ++++ .../FamilyOfGeneratedGenerics.java | 19 ++++++++ .../insertGenerics/MethodConstraint.java | 10 +++++ .../de/dhbwstuttgart/core/JavaTXCompiler.java | 7 +++ .../insertGenerics/TestLocalVarLambda.java | 26 +++++++++++ .../insertGenerics/TestTPHsAndGenerics.java | 45 +++++++++++++++++-- src/test/java/insertGenerics/TestTwoArgs.java | 43 ++++++++++++++++++ 9 files changed, 191 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index 0e3c9ed8..ae51c18e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -49,6 +49,23 @@ public class TPHConstraint { return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight()); } + @Override + public int hashCode() { + return (left+right).hashCode(); + } + + @Override + public boolean equals (Object o) { + if (o instanceof TPHConstraint) { + TPHConstraint o_tphcons = (TPHConstraint)o; + return (left+right).equals(o_tphcons.getLeft()+o_tphcons.getRight()); + } + else { + return false; + } + } + + /* @Override public String toString() { if(rel == Relation.EXTENDS) { @@ -57,4 +74,13 @@ public class TPHConstraint { return left + " = " + right; } } + */ + public String toString() { + if(rel == Relation.EXTENDS) { + return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; + } + else { + return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; + } + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 595f874e..e25958d1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -79,6 +79,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { private JavaClassName className; private Resolver resolver; + /** * @param sf * @param listOfResultSets @@ -93,6 +94,14 @@ public class GeneratedGenericsFinder implements ASTVisitor { return generatedGenericsForSF; } + /** + * returns the family of Generated Generics + * insbesondere fuer Testzwecke + */ + public FamilyOfGeneratedGenerics getFogg() { + return fogg; + } + /* * (non-Javadoc) * @@ -140,6 +149,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); + System.out.println(fogg); ///* //Fayez Ansatz Anfang diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java index 3f1d19d2..afbae005 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.bytecode.insertGenerics; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; public class ClassConstraint extends TPHConstraint { //private TPHConstraint constraint; @@ -12,4 +13,12 @@ public class ClassConstraint extends TPHConstraint { /*public ClassConstraint(TPHConstraint constraint) { this.constraint = constraint; }*/ + public String toString() { + if(rel == Relation.EXTENDS) { + return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; + } + else { + return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; + } + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 5aafb37a..a5d01d03 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -760,6 +760,25 @@ public class FamilyOfGeneratedGenerics { return tempMethodConstraintsWithPosition; } + + public String toString() { + String ret = + "List classConstraintsTest = new ArrayList<>();\n"; + for(ClassConstraint cC: classConstraints) { + ret = ret + "classConstraintsTest.add(" + cC.toString() + ");\n"; + } + ret = ret + "HashMap> methodConstraintsWithPositionTest = new HashMap<>();\n"; + ret = ret + "List lmc;\n"; + for (String methName : methodConstraintsWithPosition.keySet()) { + String consSet = ""; + ret = ret + "lmc = new ArrayList<>();\n"; + for (MethodConstraint methConstrs : methodConstraintsWithPosition.get(methName)) { + consSet = consSet + "lmc.add(" + methConstrs + ");\n"; + } + ret = ret + consSet + "methodConstraintsWithPositionTest.put(\""+ methName + "\", lmc);\n"; + } + return ret; + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java index d68f7d3f..c0000f20 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java @@ -1,9 +1,19 @@ package de.dhbwstuttgart.bytecode.insertGenerics; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; public class MethodConstraint extends TPHConstraint { public MethodConstraint(String left, String right, Relation rel) { super(left, right, rel); } + + public String toString() { + if(rel == Relation.EXTENDS) { + return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; + } + else { + return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; + } + } } diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 8425d180..eb220f4f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.BytecodeGen; import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError; import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.environment.DirectoryClassLoader; import de.dhbwstuttgart.exceptions.DebugException; @@ -78,7 +79,12 @@ public class JavaTXCompiler { Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); private final ClassLoader classLoader; + + //nur fuer Testzwecke of Generated Generics + //wieder loeschen PL 2021-03-22 + public FamilyOfGeneratedGenerics fogg; + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile), null); } @@ -872,6 +878,7 @@ public class JavaTXCompiler { SourceFile sf = sourceFiles.get(f); GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult); GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics(); + this.fogg = sResFinder.getFogg(); result.add(simplifyResOfSF); } return result; diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index bc830b49..043a9797 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,24 @@ public class TestLocalVarLambda { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS)); + lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(computedClassCons, expectedClassCons); + + assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + 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/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index e49ed344..6aebd04f 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -1,7 +1,11 @@ package insertGenerics; - import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; - import de.dhbwstuttgart.core.JavaTXCompiler; + import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; +import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; @@ -10,7 +14,9 @@ package insertGenerics; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; - import java.io.File; +import static org.junit.Assert.assertEquals; + +import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URL; @@ -19,7 +25,9 @@ package insertGenerics; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; - import java.util.HashSet; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -46,6 +54,35 @@ public class TestTPHsAndGenerics { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + 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.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(computedClassCons, expectedClassCons); + + assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index 0b2b87e3..d106e5c7 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -1,6 +1,13 @@ package insertGenerics; +import static org.junit.Assert.*; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -19,6 +26,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +54,40 @@ public class TestTwoArgs { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("AP", "Z", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("Z", "P", Relation.EXTENDS)); + 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<>(); + lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); + lmc = new ArrayList<>(); + 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.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS)); + lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(computedClassCons, expectedClassCons); + + assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From 8c6027645f229917559eb385e6ff88579d30f41f Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 24 Mar 2021 10:22:57 +0100 Subject: [PATCH 2/5] modified: src/test/java/insertGenerics/TestLocalVarLambda.java Alternative Typvarnamen eingefuegt. --- .../insertGenerics/TestLocalVarLambda.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index 043a9797..d83e6d21 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -56,14 +56,24 @@ public class TestLocalVarLambda { List classConstraintsTest = new ArrayList<>(); HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); - lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS)); - lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; + + List lmc; + lmc = new ArrayList<>(); + + if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) { + lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS)); + lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS)); + } + else { + lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS)); + lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS)); + } + methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); + Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); From e5816bac22323d59fa7fd534e6c6c8091274aa51 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 24 Mar 2021 11:35:15 +0100 Subject: [PATCH 3/5] modified: src/test/java/insertGenerics/TestAny.java modified: src/test/java/insertGenerics/TestGGFinder.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java modified: src/test/java/insertGenerics/TestTwoArgs2.java Tests fuer GeneratedGenerics eingefuegt --- src/test/java/insertGenerics/TestAny.java | 30 ++++++++++++++ .../java/insertGenerics/TestGGFinder.java | 35 ++++++++++++++++ .../insertGenerics/TestLocalVarLambda.java | 4 +- .../insertGenerics/TestTPHsAndGenerics.java | 4 +- src/test/java/insertGenerics/TestTwoArgs.java | 4 +- .../java/insertGenerics/TestTwoArgs2.java | 41 +++++++++++++++++++ 6 files changed, 112 insertions(+), 6 deletions(-) diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java index 6c6d2a95..e40c205e 100644 --- a/src/test/java/insertGenerics/TestAny.java +++ b/src/test/java/insertGenerics/TestAny.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,12 +14,16 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -40,6 +48,28 @@ public class TestAny { } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "O", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc); + lmc = new ArrayList<>(); + methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); for(File f : compiler.sourceFiles.keySet()){ SourceFile sf = compiler.sourceFiles.get(f); diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index 3b9e378e..55e9a09a 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,33 @@ public class TestGGFinder { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + 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.add(new MethodConstraint("T", "S", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Y", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("voidm(TPH YTPH Z)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + 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/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index d83e6d21..ea8071d7 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -77,9 +77,9 @@ public class TestLocalVarLambda { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); 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 6aebd04f..3c243171 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -79,9 +79,9 @@ public class TestTPHsAndGenerics { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index d106e5c7..e492c49f 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -84,9 +84,9 @@ public class TestTwoArgs { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java index 6522187a..42a5a833 100644 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ b/src/test/java/insertGenerics/TestTwoArgs2.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,39 @@ public class TestTwoArgs2 { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AA", "U", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From bc378f2fe956fda4a3970fafff0812c0667ffd1b Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Mar 2021 00:41:03 +0100 Subject: [PATCH 4/5] modified: src/test/java/insertGenerics/AllTests.java modified: src/test/java/insertGenerics/TestTwoCalls.java modified: src/test/java/insertGenerics/TestVector.java --- src/test/java/insertGenerics/AllTests.java | 44 ++++++++++++++++++- .../java/insertGenerics/TestTwoCalls.java | 29 ++++++++++++ src/test/java/insertGenerics/TestVector.java | 27 ++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/test/java/insertGenerics/AllTests.java b/src/test/java/insertGenerics/AllTests.java index 42fa736f..f4f09992 100644 --- a/src/test/java/insertGenerics/AllTests.java +++ b/src/test/java/insertGenerics/AllTests.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -35,7 +43,41 @@ public class AllTests { @Test public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { className = "TestMutualRecursion"; - execute(new File(rootDirectory+className+".jav")); + JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav")); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + 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.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.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)); + methodConstraintsWithPositionTest.put("TPH ALmain(TPH AGTPH AH)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); } @Test diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index 6d107b16..a6157ecc 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,27 @@ public class TestTwoCalls { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + 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.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)); + methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + 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 a585abe5..a020b279 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,25 @@ public class TestVector { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + 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<>(); + methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From 705d0b6a73a76a6b75ee3ab6ac58f009077ec044 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Mar 2021 18:56:38 +0100 Subject: [PATCH 5/5] renamed: src/test/java/insertGenerics/AllTests.java -> src/test/java/insertGenerics/TestMutualRecursion.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestVector.java Tests angepasst an die GeneratedGenerics --- ...AllTests.java => TestMutualRecursion.java} | 10 +--- .../insertGenerics/TestTPHsAndGenerics.java | 58 +++++++++++++------ src/test/java/insertGenerics/TestVector.java | 1 + 3 files changed, 44 insertions(+), 25 deletions(-) rename src/test/java/insertGenerics/{AllTests.java => TestMutualRecursion.java} (90%) diff --git a/src/test/java/insertGenerics/AllTests.java b/src/test/java/insertGenerics/TestMutualRecursion.java similarity index 90% rename from src/test/java/insertGenerics/AllTests.java rename to src/test/java/insertGenerics/TestMutualRecursion.java index f4f09992..30778032 100644 --- a/src/test/java/insertGenerics/AllTests.java +++ b/src/test/java/insertGenerics/TestMutualRecursion.java @@ -31,7 +31,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class AllTests { +public class TestMutualRecursion { private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; @@ -41,7 +41,7 @@ public class AllTests { private static String className; @Test - public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { className = "TestMutualRecursion"; JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav")); List results = compiler.typeInference(); @@ -98,12 +98,6 @@ public class AllTests { execute(new File(rootDirectory+className+".jav")); } - @Test - public void TestContraVariant() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - className = "TestContraVariant"; - execute(new File(rootDirectory+className+".jav")); - } - private static class TestResultSet{ } diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 3c243171..9254100f 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -56,26 +56,50 @@ public class TestTPHsAndGenerics { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); - lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); - 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.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new ArrayList<>(); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; + + List lmc; + lmc = new ArrayList<>(); + + if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { + classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + 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.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + } + else { + classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + 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.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + } + Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index a020b279..b902e93e 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -63,6 +63,7 @@ public class TestVector { lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg;