diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 102438f8..4bde13d8 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -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; } diff --git a/src/test/java/packages/OLTest.java b/src/test/java/packages/OLTest.java index 39ca56be..c45b387d 100644 --- a/src/test/java/packages/OLTest.java +++ b/src/test/java/packages/OLTest.java @@ -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); + } } diff --git a/src/test/resources/javFiles/packageTest/OLMain.jav b/src/test/resources/javFiles/packageTest/OLMain.jav index 89512771..0cdb0b4f 100644 --- a/src/test/resources/javFiles/packageTest/OLMain.jav +++ b/src/test/resources/javFiles/packageTest/OLMain.jav @@ -6,7 +6,7 @@ public class OLMain { main(x) { var ol; - ol = new OL(); + ol = new OLextends(); return ol.m(x); } } diff --git a/src/test/resources/javFiles/packageTest/OLextends.jav b/src/test/resources/javFiles/packageTest/OLextends.jav new file mode 100644 index 00000000..b3c055df --- /dev/null +++ b/src/test/resources/javFiles/packageTest/OLextends.jav @@ -0,0 +1,7 @@ +import de.test.OL; + + +public class OLextends extends OL { + + +} diff --git a/src/test/resources/javFiles/packageTest/OL.jav b/src/test/resources/javFiles/packageTest/de/test/OL.jav similarity index 75% rename from src/test/resources/javFiles/packageTest/OL.jav rename to src/test/resources/javFiles/packageTest/de/test/OL.jav index 91d0f4ab..7f1ba512 100644 --- a/src/test/resources/javFiles/packageTest/OL.jav +++ b/src/test/resources/javFiles/packageTest/de/test/OL.jav @@ -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; } }