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:
pl@gohorb.ba-horb.de 2020-01-21 12:27:41 +01:00
parent a6287b1551
commit d55e6b3b75
5 changed files with 75 additions and 21 deletions

View File

@ -772,7 +772,7 @@ public class BytecodeGenMethod implements StatementVisitor {
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
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) {
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) {
for(java.lang.reflect.Method m : methods) {
//Fehler
if(name.equals(m.getName()) && i == m.getParameterCount()) {
return m;
}

View File

@ -12,6 +12,8 @@ import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.common.collect.Lists;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.typeinference.result.ResultSet;
@ -23,34 +25,51 @@ public class OLTest {
private static ClassLoader loader;
private static Class<?> classToTest;
private static Class<?> classToTest1;
private static Class<?> classToTest2;
private static String pathToClassFile;
private static Object instanceOfClass;
private static Object instanceOfClass1;
private static Object instanceOfClass2;
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest";
@BeforeClass
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);
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("OL");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile), new URL("file://"+ rootDirectory + "/de/test/output/")});
classToTest1 = loader.loadClass("OLextends");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OLMain.jav";
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest1 = loader.loadClass("OLMain");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile), new URL("file://"+ rootDirectory + "/de/test/output/")});
classToTest2 = loader.loadClass("OLMain");
instanceOfClass2 = classToTest2.getDeclaredConstructor().newInstance();
}
@Test
public void testOLClassName() {
assertEquals("OL", classToTest.getName());
assertEquals("de.test.OL", classToTest.getName());
}
@Test
@ -75,28 +94,54 @@ public class OLTest {
}
@Test
public void testOLMainClassName() {
assertEquals("OLMain", classToTest1.getName());
public void testOLextendsClassName() {
assertEquals("OLextends", classToTest1.getName());
}
@Test
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
public void testextendsInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getMethod("m", Integer.class);
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
assertEquals(new Integer(10), result);
}
@Test
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", Double.class);
public void testextendsDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getMethod("m", Double.class);
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
assertEquals(new Double(10.0), result);
}
@Test
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", String.class);
public void testextendsString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getMethod("m", String.class);
String result = (String) main.invoke(instanceOfClass1, "xxx");
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);
}
}

View File

@ -6,7 +6,7 @@ public class OLMain {
main(x) {
var ol;
ol = new OL();
ol = new OLextends();
return ol.m(x);
}
}

View File

@ -0,0 +1,7 @@
import de.test.OL;
public class OLextends extends OL {
}

View File

@ -1,3 +1,4 @@
package de.test;
import java.lang.String;
import java.lang.Integer;
import java.lang.Double;
@ -7,6 +8,6 @@ import java.lang.Boolean;
public class OL {
m(x) { return x + x; }
public m(x) { return x + x; }
}