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; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; 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; import java.net.URL; import java.net.URLClassLoader; 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; public class TestTPHsAndGenerics { 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/"; private static ClassLoader loader; private static Class classToTest; private static Object instanceOfClass; private static String className = "TestTPHsAndGenerics"; @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); } private static class TestResultSet{ } public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { 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)}); classToTest = loader.loadClass(className); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); */ return new TestResultSet(); } }