AutoOverloadingVector Test hinzugefügt

This commit is contained in:
Enrico Schrödter 2015-12-05 15:15:28 +01:00
parent 3c80cb275b
commit 116232df57
7 changed files with 111 additions and 5 deletions

View File

@ -126,7 +126,7 @@ public class ClassGenerator extends ClassGen{
//Signatur setzen:
String typeParameters = this.generateParameterSignature();
String superClassSignature = this.superClass.getBytecodeSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
String superClassSignature = this.superClass.getBytecodeSignature(this, null);
String classSignature = typeParameters + superClassSignature;
if(classSignature.length()>0){
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));

View File

@ -67,7 +67,7 @@ public class Constructor extends Method {
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
Class parentClass = this.getParentClass();
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, cg.getTypeinferenceResults().getTypeReconstructions().firstElement()), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
//FieldInitializations an Block anfügen
Block block = this.get_Block();
@ -79,7 +79,7 @@ public class Constructor extends Method {
//method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block(), cg.getTypeinferenceResults().getTypeReconstructions().firstElement()));
cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block(), null));
}
/**

View File

@ -38,6 +38,8 @@ public class SingleClassTester {
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(sourceFiles, results);
//System.out.println(bytecode);
ByteCodeResult result = bytecode.firstElement();
JavaClass javaClass = result.getByteCode().getJavaClass();

View File

@ -1,5 +1,3 @@
import java.util.Vector;
class AutoOverloading{
method2(String p){

View File

@ -0,0 +1,18 @@
import java.util.Vector;
class AutoOverloadingVector{
method2(p){
}
method(Vector<String> p){
method2(p.firstElement());
}
method(Vector<Integer> p){
method2(p.firstElement());
}
}

View File

@ -0,0 +1,84 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class AutoOverloadingVectorTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "AutoOverloadingVector";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
@Test
public void testString() {
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};
Class string = classLoader.loadClass("java.lang.String");
Class[] params = new Class[1];
params[0] = string;
Method method = cls.getDeclaredMethod("method2", params);
method.invoke(obj, string.newInstance());
assertTrue(true);
}catch(Exception e){
throw new RuntimeException(e);
}
}
@Test
public void testInteger() {
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};
Integer integer = new Integer(123);
Class[] params = new Class[1];
params[0] = integer.getClass();
Method method = cls.getDeclaredMethod("method2", params);
method.invoke(obj, integer);
assertTrue(true);
}catch(Exception e){
throw new RuntimeException(e);
}
}
}

View File

@ -4,4 +4,8 @@ class MethodWithTypedVector{
public void method(Vector<String> v) {
}
public void method(Vector<Integer> v) {
}
}