forked from JavaTX/JavaCompilerCore
modified: ../../../../main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java
fehlerhafter Aufruf getMethod korrigiert. modified: ../../../java/packages/OLTest.java modified: OLMain.jav new file: OLextends.jav renamed: OL.jav -> de/test/OL.jav OL-Beispiel mit doppelter Vererbung eingefuegt.
This commit is contained in:
parent
a6287b1551
commit
d55e6b3b75
@ -772,7 +772,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(),methCallType, typesOfParams, methods);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String superClass = "";
|
String superClass = "";
|
||||||
@ -934,6 +934,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
*/
|
*/
|
||||||
private java.lang.reflect.Method getMethod(String name, int i, java.lang.reflect.Method[] methods) {
|
private java.lang.reflect.Method getMethod(String name, int i, java.lang.reflect.Method[] methods) {
|
||||||
for(java.lang.reflect.Method m : methods) {
|
for(java.lang.reflect.Method m : methods) {
|
||||||
|
//Fehler
|
||||||
if(name.equals(m.getName()) && i == m.getParameterCount()) {
|
if(name.equals(m.getName()) && i == m.getParameterCount()) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import java.util.List;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@ -23,34 +25,51 @@ public class OLTest {
|
|||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Class<?> classToTest1;
|
private static Class<?> classToTest1;
|
||||||
|
private static Class<?> classToTest2;
|
||||||
private static String pathToClassFile;
|
private static String pathToClassFile;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static Object instanceOfClass1;
|
private static Object instanceOfClass1;
|
||||||
|
private static Object instanceOfClass2;
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OL.jav";
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/OL.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "/de/test/output/");
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+ rootDirectory + "/de/test/output/")});
|
||||||
|
classToTest = loader.loadClass("de.test.OL");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OLextends.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/OLextends.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
|
||||||
|
//compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
compiler.generateBytecode(pathToClassFile);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile), new URL("file://"+ rootDirectory + "/de/test/output/")});
|
||||||
classToTest = loader.loadClass("OL");
|
classToTest1 = loader.loadClass("OLextends");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OLMain.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OLMain.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/OLMain.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
|
||||||
|
//compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
compiler.generateBytecode(pathToClassFile);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile), new URL("file://"+ rootDirectory + "/de/test/output/")});
|
||||||
classToTest1 = loader.loadClass("OLMain");
|
classToTest2 = loader.loadClass("OLMain");
|
||||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClass2 = classToTest2.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOLClassName() {
|
public void testOLClassName() {
|
||||||
assertEquals("OL", classToTest.getName());
|
assertEquals("de.test.OL", classToTest.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -75,28 +94,54 @@ public class OLTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOLMainClassName() {
|
public void testOLextendsClassName() {
|
||||||
assertEquals("OLMain", classToTest1.getName());
|
assertEquals("OLextends", classToTest1.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testextendsInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
Method main = classToTest1.getMethod("m", Integer.class);
|
||||||
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||||
assertEquals(new Integer(10), result);
|
assertEquals(new Integer(10), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testextendsDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
Method main = classToTest1.getMethod("m", Double.class);
|
||||||
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||||
assertEquals(new Double(10.0), result);
|
assertEquals(new Double(10.0), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testextendsString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method main = classToTest1.getDeclaredMethod("main", String.class);
|
Method main = classToTest1.getMethod("m", String.class);
|
||||||
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
||||||
assertEquals("xxxxxx", result);
|
assertEquals("xxxxxx", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLMainClassName() {
|
||||||
|
assertEquals("OLMain", classToTest2.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", Integer.class);
|
||||||
|
Integer result = (Integer) main.invoke(instanceOfClass2, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", Double.class);
|
||||||
|
Double result = (Double) main.invoke(instanceOfClass2, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", String.class);
|
||||||
|
String result = (String) main.invoke(instanceOfClass2, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ public class OLMain {
|
|||||||
|
|
||||||
main(x) {
|
main(x) {
|
||||||
var ol;
|
var ol;
|
||||||
ol = new OL();
|
ol = new OLextends();
|
||||||
return ol.m(x);
|
return ol.m(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
src/test/resources/javFiles/packageTest/OLextends.jav
Normal file
7
src/test/resources/javFiles/packageTest/OLextends.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import de.test.OL;
|
||||||
|
|
||||||
|
|
||||||
|
public class OLextends extends OL {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
package de.test;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Double;
|
import java.lang.Double;
|
||||||
@ -7,6 +8,6 @@ import java.lang.Boolean;
|
|||||||
|
|
||||||
public class OL {
|
public class OL {
|
||||||
|
|
||||||
m(x) { return x + x; }
|
public m(x) { return x + x; }
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user