new file: ../../../java/insertGenerics/TestTwoCalls.java

new file:   ../../../java/insertGenerics/TestVector.java
	new file:   ../../insertGenericsJav/TestLocalVarLambda.jav
	new file:   ../../insertGenericsJav/TestMutualRecursion.jav
	new file:   ../../insertGenericsJav/TestMutualRecursionWithField.jav
	new file:   ../../insertGenericsJav/TestThreeArgs.jav
	new file:   ../../insertGenericsJav/TestTwoCalls.jav
	new file:   ../../insertGenericsJav/TestVector.jav
This commit is contained in:
pl@gohorb.ba-horb.de 2021-02-25 15:59:24 +01:00
parent 60f2e3def4
commit ebb0803a38
8 changed files with 193 additions and 0 deletions

View File

@ -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<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> 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();
}
}

View File

@ -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<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> 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();
}
}

View File

@ -0,0 +1,7 @@
public class TestLocalVarLambda {
m(x) {
var id = z -> z;
return id.apply(x);
}
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,12 @@
public class TestTwoCalls {
id(b) {
var c = b;
return c;
}
main(x,y) {
id(x);
return id(y);
}
}

View File

@ -0,0 +1,12 @@
import java.util.Vector;
public class TestVector {
m(v, w) {
w.addElement(id(v.elementAt(0)));
}
id(x) {
return x;
}
}