forked from JavaTX/JavaCompilerCore
AutoOverloadingVector Test hinzugefügt
This commit is contained in:
parent
3c80cb275b
commit
116232df57
@ -126,7 +126,7 @@ public class ClassGenerator extends ClassGen{
|
|||||||
|
|
||||||
//Signatur setzen:
|
//Signatur setzen:
|
||||||
String typeParameters = this.generateParameterSignature();
|
String typeParameters = this.generateParameterSignature();
|
||||||
String superClassSignature = this.superClass.getBytecodeSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
|
String superClassSignature = this.superClass.getBytecodeSignature(this, null);
|
||||||
String classSignature = typeParameters + superClassSignature;
|
String classSignature = typeParameters + superClassSignature;
|
||||||
if(classSignature.length()>0){
|
if(classSignature.length()>0){
|
||||||
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));
|
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));
|
||||||
|
@ -67,7 +67,7 @@ public class Constructor extends Method {
|
|||||||
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
|
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
|
||||||
Class parentClass = this.getParentClass();
|
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
|
//FieldInitializations an Block anfügen
|
||||||
Block block = this.get_Block();
|
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)
|
//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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +38,8 @@ public class SingleClassTester {
|
|||||||
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(sourceFiles, results);
|
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(sourceFiles, results);
|
||||||
//System.out.println(bytecode);
|
//System.out.println(bytecode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ByteCodeResult result = bytecode.firstElement();
|
ByteCodeResult result = bytecode.firstElement();
|
||||||
|
|
||||||
JavaClass javaClass = result.getByteCode().getJavaClass();
|
JavaClass javaClass = result.getByteCode().getJavaClass();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
class AutoOverloading{
|
class AutoOverloading{
|
||||||
|
|
||||||
method2(String p){
|
method2(String p){
|
||||||
|
18
test/bytecode/types/AutoOverloadingVector.jav
Normal file
18
test/bytecode/types/AutoOverloadingVector.jav
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
84
test/bytecode/types/AutoOverloadingVectorTest.java
Normal file
84
test/bytecode/types/AutoOverloadingVectorTest.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,4 +4,8 @@ class MethodWithTypedVector{
|
|||||||
public void method(Vector<String> v) {
|
public void method(Vector<String> v) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void method(Vector<Integer> v) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user