forked from JavaTX/JavaCompilerCore
ConsoleInterface an neue CompilerApi angepasst
RefType getBytecodeSignature unterscheidet zwischen RefType und TypePlacholder Abstrakte ByteCodeTest Klasse um getClassLoader erweitert Alle BytecodeTypeTests angepasst
This commit is contained in:
parent
12093f2fc7
commit
ce52fd8904
@ -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<SourceFile> 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());
|
||||
|
@ -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{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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%");
|
||||
|
||||
|
120
test/bytecode/types/ReflectionTest.java
Normal file
120
test/bytecode/types/ReflectionTest.java
Normal file
@ -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<String> vector = new Vector<String>();
|
||||
|
||||
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<String> vector = new Vector<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String> stringVector = new Vector<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
test/bytecode/types/UntypedVector.jav
Normal file
7
test/bytecode/types/UntypedVector.jav
Normal file
@ -0,0 +1,7 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class UntypedVector{
|
||||
public void method(Vector v) {
|
||||
|
||||
}
|
||||
}
|
68
test/bytecode/types/UntypedVectorTest.java
Normal file
68
test/bytecode/types/UntypedVectorTest.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user