forked from JavaTX/JavaCompilerCore
modified: ../../../java/bytecode/InheritTest.java
modified: ../../bytecode/javFiles/Inherit.jav
This commit is contained in:
parent
eb27003515
commit
907ab2fcec
@ -5,6 +5,7 @@ import static org.junit.Assert.*;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -30,14 +31,16 @@ public class InheritTest {
|
|||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Class<?> classToTest1, classToTest2, classToTest3, classToTest4;
|
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||||
|
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static Object instanceOfClass1, instanceOfClass2, instanceOfClass3, instanceOfClass4;
|
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
@ -45,9 +48,10 @@ public class InheritTest {
|
|||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest1 = loader.loadClass("AA");
|
classToTestAA = loader.loadClass("AA");
|
||||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
/*
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
@ -55,8 +59,8 @@ public class InheritTest {
|
|||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest2 = loader.loadClass("BB");
|
classToTestBB = loader.loadClass("BB");
|
||||||
instanceOfClass2 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
@ -65,8 +69,8 @@ public class InheritTest {
|
|||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest3 = loader.loadClass("CC");
|
classToTestCC = loader.loadClass("CC");
|
||||||
instanceOfClass3 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
@ -75,15 +79,18 @@ public class InheritTest {
|
|||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest4 = loader.loadClass("DD");
|
classToTestDD = loader.loadClass("DD");
|
||||||
instanceOfClass4 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||||
|
*/
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
/*
|
||||||
compiler = new JavaTXCompiler(
|
compiler = new JavaTXCompiler(
|
||||||
Lists.newArrayList(fileToTest),
|
Lists.newArrayList(fileToTest),
|
||||||
Lists.newArrayList(new File(pathToClassFile)));
|
Lists.newArrayList(new File(pathToClassFile1)));
|
||||||
//compiler = new JavaTXCompiler(fileToTest);
|
*/
|
||||||
typeinferenceResult = compiler.typeInference();
|
typeinferenceResult = compiler.typeInference();
|
||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
@ -91,6 +98,7 @@ public class InheritTest {
|
|||||||
classToTest = loader.loadClass("Inherit");
|
classToTest = loader.loadClass("Inherit");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
/*
|
||||||
for (Method m: classToTest.getMethods()) {
|
for (Method m: classToTest.getMethods()) {
|
||||||
ArrayList<String> param = Arrays.stream(m.getParameterTypes()).map(x -> x.getName()).collect(Collectors.toCollection(ArrayList::new));
|
ArrayList<String> param = Arrays.stream(m.getParameterTypes()).map(x -> x.getName()).collect(Collectors.toCollection(ArrayList::new));
|
||||||
ArrayList<String> nameParam = new ArrayList<>();
|
ArrayList<String> nameParam = new ArrayList<>();
|
||||||
@ -98,6 +106,7 @@ public class InheritTest {
|
|||||||
nameParam.addAll(param);
|
nameParam.addAll(param);
|
||||||
hm.put(nameParam, m);
|
hm.put(nameParam, m);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -105,33 +114,37 @@ public class InheritTest {
|
|||||||
assertEquals("Inherit", classToTest.getName());
|
assertEquals("Inherit", classToTest.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAAName() {
|
|
||||||
assertEquals("AA", classToTest1.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAAName() {
|
||||||
|
assertEquals("AA", classToTestAA.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void testBBName() {
|
public void testBBName() {
|
||||||
assertEquals("BB", classToTest2.getName());
|
assertEquals("BB", classToTestBB.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCCName() {
|
public void testCCName() {
|
||||||
assertEquals("CC", classToTest3.getName());
|
assertEquals("CC", classToTestCC.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDDName() {
|
public void testDDName() {
|
||||||
assertEquals("DD", classToTest4.getName());
|
assertEquals("DD", classToTestDD.getName());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
|
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException {
|
||||||
String[] x = {"main", "AA", "java.lang.Integer"};
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
ArrayList<String> nameParam = new ArrayList<>(Arrays.asList(x));
|
classToTest = loader.loadClass("Inherit");
|
||||||
Method m = hm.get(nameParam);
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(classToTest1.getConstructor().newInstance(), 5), "AA");
|
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Vector<Integer> v_invoke = new Vector<>();
|
Vector<Integer> v_invoke = new Vector<>();
|
||||||
|
@ -6,6 +6,8 @@ import java.lang.String;
|
|||||||
|
|
||||||
public class Inherit {
|
public class Inherit {
|
||||||
|
|
||||||
|
//m(Integer i) { return "AA"; }
|
||||||
|
|
||||||
main(d, i) {
|
main(d, i) {
|
||||||
return d.m(i);
|
return d.m(i);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user