modified: src/test/java/insertGenerics/AllTests.java
modified: src/test/java/insertGenerics/TestTwoCalls.java modified: src/test/java/insertGenerics/TestVector.java
This commit is contained in:
parent
e5816bac22
commit
bc378f2fe9
@ -1,6 +1,10 @@
|
|||||||
package insertGenerics;
|
package insertGenerics;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
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.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -35,7 +43,41 @@ public class AllTests {
|
|||||||
@Test
|
@Test
|
||||||
public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
className = "TestMutualRecursion";
|
className = "TestMutualRecursion";
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav"));
|
||||||
|
List<ResultSet> results = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
|
|
||||||
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
|
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
|
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
|
Set<ClassConstraint> 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
|
@Test
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package insertGenerics;
|
package insertGenerics;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
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.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -45,6 +53,27 @@ public class TestTwoCalls {
|
|||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||||
List<ResultSet> results = compiler.typeInference();
|
List<ResultSet> results = compiler.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
|
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
|
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
||||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass(className);
|
classToTest = loader.loadClass(className);
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package insertGenerics;
|
package insertGenerics;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
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.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -45,6 +53,25 @@ public class TestVector {
|
|||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||||
List<ResultSet> results = compiler.typeInference();
|
List<ResultSet> results = compiler.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
|
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
|
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
||||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass(className);
|
classToTest = loader.loadClass(className);
|
||||||
|
Loading…
Reference in New Issue
Block a user