diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java new file mode 100644 index 00000000..6d107b16 --- /dev/null +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -0,0 +1,54 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +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 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.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTwoCalls { + + 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 = "TestTwoCalls"; + + @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); + 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(); + } +} diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java new file mode 100644 index 00000000..a585abe5 --- /dev/null +++ b/src/test/java/insertGenerics/TestVector.java @@ -0,0 +1,54 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +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 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.HashSet; +import java.util.List; +import java.util.Set; + +public class TestVector { + + 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 = "TestVector"; + + @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); + 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(); + } +} diff --git a/src/test/resources/insertGenericsJav/TestLocalVarLambda.jav b/src/test/resources/insertGenericsJav/TestLocalVarLambda.jav new file mode 100644 index 00000000..ab4455c7 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestLocalVarLambda.jav @@ -0,0 +1,7 @@ +public class TestLocalVarLambda { + +m(x) { + var id = z -> z; + return id.apply(x); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestMutualRecursion.jav b/src/test/resources/insertGenericsJav/TestMutualRecursion.jav new file mode 100644 index 00000000..60ce72ca --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestMutualRecursion.jav @@ -0,0 +1,17 @@ +public class TestMutualRecursion { + a; + + id(b) { + var c = b; + return main(b,c); + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + return m(id(x),y); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav new file mode 100644 index 00000000..82dc42d2 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav @@ -0,0 +1,22 @@ +public class TestMutualRecursionWithField { + a; + + id(b) { + var c = b; + return main(b,c); + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + return m(id(x),setA(y)); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestThreeArgs.jav b/src/test/resources/insertGenericsJav/TestThreeArgs.jav new file mode 100644 index 00000000..fe22dd3c --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestThreeArgs.jav @@ -0,0 +1,15 @@ +public class TestThreeArgs { + a; + + id(b) { + var a /* = null */; + var c = b; + m(a,a,b); + return c; + } + + m(x,y, z) { + x = id(y); + return x; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestTwoCalls.jav b/src/test/resources/insertGenericsJav/TestTwoCalls.jav new file mode 100644 index 00000000..be3137f0 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTwoCalls.jav @@ -0,0 +1,12 @@ +public class TestTwoCalls { + + id(b) { + var c = b; + return c; + } + + main(x,y) { + id(x); + return id(y); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestVector.jav b/src/test/resources/insertGenericsJav/TestVector.jav new file mode 100644 index 00000000..1519afb7 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestVector.jav @@ -0,0 +1,12 @@ +import java.util.Vector; + +public class TestVector { + + m(v, w) { + w.addElement(id(v.elementAt(0))); + } + + id(x) { + return x; + } +} \ No newline at end of file