diff --git a/src/de/dhbwstuttgart/core/ConsoleInterface.java b/src/de/dhbwstuttgart/core/ConsoleInterface.java index 1c99aa30..9c6735a6 100755 --- a/src/de/dhbwstuttgart/core/ConsoleInterface.java +++ b/src/de/dhbwstuttgart/core/ConsoleInterface.java @@ -7,6 +7,7 @@ import java.util.*; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -34,13 +35,13 @@ public class ConsoleInterface { ///////////////////////// // Parsen: ///////////////////////// - compiler.parse(filenames); + Menge sourceFiles = compiler.parse(filenames); ///////////////////////// // Typrekonstruktion: ///////////////////////// try{ - resultSet = compiler.typeReconstruction(); + resultSet = compiler.typeReconstruction(sourceFiles); }catch(TypeinferenceException texc){ texc.printStackTrace(); fail("Fehler bei Typinferenzalgorithmus. Message: "+texc.getMessage()); diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 117c5b9e..62d67ebf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -869,7 +869,14 @@ public class RefType extends ObjectType implements IMatchable sb.append(getName().toString().replace(".", "%")); sb.append("%%"); for(Type type: parameter){ - sb.append(((RefType) type).getCombinedType(cg).replace(".", "%")); + if(type instanceof RefType){ + sb.append(((RefType) type).getCombinedType(cg).replace(".", "%")); + }else if(type instanceof TypePlaceholder){ + sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%")); + }else{ + sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%")); + } + sb.append("%"); } }else{ diff --git a/test/bytecode/BytecodeTest.java b/test/bytecode/BytecodeTest.java index 35b8dc33..92c38e19 100644 --- a/test/bytecode/BytecodeTest.java +++ b/test/bytecode/BytecodeTest.java @@ -39,11 +39,7 @@ public abstract class BytecodeTest extends TestCase{ protected Class getClassToTest(){ Class classToTest = null; try { - File file = new File(rootDirectory); - URL url = file.toURL(); - URL[] urls = new URL[]{url}; - - ClassLoader classLoader = new URLClassLoader(urls); + ClassLoader classLoader = getClassLoader(); classToTest = classLoader.loadClass(testName); @@ -54,4 +50,12 @@ public abstract class BytecodeTest extends TestCase{ return classToTest; } + + protected ClassLoader getClassLoader() throws Exception{ + File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/"); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + return new URLClassLoader(urls); + } } diff --git a/test/bytecode/types/ExtendsObjectTest.java b/test/bytecode/types/ExtendsObjectTest.java index 43648fdf..964d52c9 100644 --- a/test/bytecode/types/ExtendsObjectTest.java +++ b/test/bytecode/types/ExtendsObjectTest.java @@ -34,7 +34,11 @@ public class ExtendsObjectTest extends BytecodeTest{ @Test public void testConstruct(){ try{ - Class cls = getClassToTest(); + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); Constructor method = cls.getConstructor(new Class[]{}); method.newInstance(); diff --git a/test/bytecode/types/ExtendsVectorStringTest.java b/test/bytecode/types/ExtendsVectorStringTest.java index 8511499b..efcbc095 100644 --- a/test/bytecode/types/ExtendsVectorStringTest.java +++ b/test/bytecode/types/ExtendsVectorStringTest.java @@ -33,7 +33,11 @@ public class ExtendsVectorStringTest extends BytecodeTest{ @Test public void testConstruct() throws Exception{ - Class cls = getClassToTest(); + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); Constructor method = cls.getConstructor(new Class[]{}); method.newInstance(); diff --git a/test/bytecode/types/ExtendsVectorTest.java b/test/bytecode/types/ExtendsVectorTest.java index aefe5d4b..5253507e 100644 --- a/test/bytecode/types/ExtendsVectorTest.java +++ b/test/bytecode/types/ExtendsVectorTest.java @@ -34,7 +34,11 @@ public class ExtendsVectorTest extends BytecodeTest{ @Test public void testConstruct(){ try{ - Class cls = getClassToTest(); + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); Constructor method = cls.getConstructor(new Class[]{}); method.newInstance(); diff --git a/test/bytecode/types/OverloadingTest.java b/test/bytecode/types/OverloadingTest.java index 514264a3..15469089 100644 --- a/test/bytecode/types/OverloadingTest.java +++ b/test/bytecode/types/OverloadingTest.java @@ -24,15 +24,16 @@ public class OverloadingTest extends BytecodeTest{ @Test public void testString() { try{ - Class cls = getClassToTest(); + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + Object obj = cls.newInstance(); File file = new File(rootDirectory); URL url = file.toURL(); URL[] urls = new URL[]{url}; - ClassLoader classLoader = new URLClassLoader(urls); - Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%String%"); Class[] params = new Class[1]; @@ -49,14 +50,11 @@ public class OverloadingTest extends BytecodeTest{ @Test public void testInteger() { try{ - Class cls = getClassToTest(); - Object obj = cls.newInstance(); - - File file = new File(rootDirectory); - URL url = file.toURL(); - URL[] urls = new URL[]{url}; + ClassLoader classLoader = getClassLoader(); - ClassLoader classLoader = new URLClassLoader(urls); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); Class integerVector = classLoader.loadClass("java%util%Vector%%java%lang%Integer%"); diff --git a/test/bytecode/types/ReflectionTest.java b/test/bytecode/types/ReflectionTest.java new file mode 100644 index 00000000..db5a25e2 --- /dev/null +++ b/test/bytecode/types/ReflectionTest.java @@ -0,0 +1,120 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Stack; +import java.util.Vector; + +import org.junit.Test; + +import bytecode.BytecodeTest; +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; + +public class ReflectionTest{ + @Test + public void testUntypedVectorDeclaredMethods() { + try{ + File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/"); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + ClassLoader classLoader = new URLClassLoader(urls); + + Class untypedVectorTest = classLoader.loadClass("UntypedVector"); + + for(Method method: untypedVectorTest.getDeclaredMethods()){ + System.out.println(method.toGenericString()); + } + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testUntypedVectorDeclaredMethodsCallMethod() { + try{ + File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/"); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + ClassLoader classLoader = new URLClassLoader(urls); + + Class untypedVectorTest = classLoader.loadClass("UntypedVector"); + + Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%Object%"); + Object stringVectorObj = stringVector.newInstance(); + + for(Method method: untypedVectorTest.getDeclaredMethods()){ + method.invoke(untypedVectorTest.newInstance(), stringVectorObj); + } + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testUntypedVectorMethod() { + try{ + File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/"); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + ClassLoader classLoader = new URLClassLoader(urls); + + Class untypedVectorTest = classLoader.loadClass("UntypedVector"); + + Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%Object%"); + + Class[] params = new Class[1]; + params[0] = stringVector; + + Method method = untypedVectorTest.getDeclaredMethod("method", params); + method.invoke(untypedVectorTest.newInstance(), stringVector.newInstance()); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testStdVectorAdd() { + try{ + Vector vector = new Vector(); + + Class vectorClass = vector.getClass(); + + String helloWorld = new String("Hello World!"); + + Class[] params = new Class[1]; + params[0] = new Object().getClass(); + + Method method = vectorClass.getDeclaredMethod("add", params); + method.invoke(vector, helloWorld); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testStdVectorEnsureCapacity() { + try{ + Vector vector = new Vector(); + + Class vectorClass = vector.getClass(); + + Integer integer = new Integer(1); + + Class[] params = new Class[1]; + params[0] = int.class; + + Method method = vectorClass.getDeclaredMethod("ensureCapacity", params); + method.invoke(vector, integer); + }catch(Exception e){ + throw new RuntimeException(e); + } + } +} diff --git a/test/bytecode/types/TypedVectorTest.java b/test/bytecode/types/TypedVectorTest.java index ef32180b..6a5cb441 100644 --- a/test/bytecode/types/TypedVectorTest.java +++ b/test/bytecode/types/TypedVectorTest.java @@ -2,7 +2,10 @@ package bytecode.types; import static org.junit.Assert.*; +import java.io.File; import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Stack; import java.util.Vector; @@ -22,20 +25,21 @@ public class TypedVectorTest extends BytecodeTest{ @Test public void test() { try{ - Class cls = getClassToTest(); + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + Object obj = cls.newInstance(); - - Vector stringVector = new Vector(); + + Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%String%"); Class[] params = new Class[1]; - params[0] = stringVector.getClass(); + params[0] = stringVector; Method method = cls.getDeclaredMethod("method", params); - method.invoke(obj, stringVector); - assertTrue(true); + method.invoke(obj, stringVector.newInstance()); }catch(Exception e){ - Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN); - fail(); + throw new RuntimeException(e); } } } diff --git a/test/bytecode/types/UntypedVector.jav b/test/bytecode/types/UntypedVector.jav new file mode 100644 index 00000000..05835507 --- /dev/null +++ b/test/bytecode/types/UntypedVector.jav @@ -0,0 +1,7 @@ +import java.util.Vector; + +class UntypedVector{ + public void method(Vector v) { + + } +} \ No newline at end of file diff --git a/test/bytecode/types/UntypedVectorTest.java b/test/bytecode/types/UntypedVectorTest.java new file mode 100644 index 00000000..a2277c0c --- /dev/null +++ b/test/bytecode/types/UntypedVectorTest.java @@ -0,0 +1,68 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Stack; +import java.util.Vector; + +import org.junit.Test; + +import bytecode.BytecodeTest; +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; + +public class UntypedVectorTest extends BytecodeTest{ + @Override + protected void init() { + testName = "UntypedVector"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + @Test + public void testObjectVector() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + Object object = new Object(); + + Class[] params = new Class[1]; + params[0] = object.getClass(); + + Method method = cls.getDeclaredMethod("method", params); + method.invoke(obj, object); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testGenericClass() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class untypedVectorTest = classLoader.loadClass(testName); + + Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%Object%"); + + Class[] params = new Class[1]; + params[0] = stringVector; + + Method method = untypedVectorTest.getDeclaredMethod("method", params); + method.invoke(untypedVectorTest.newInstance(), stringVector.newInstance()); + }catch(Exception e){ + throw new RuntimeException(e); + } + } +}