forked from JavaTX/JavaCompilerCore
- UnitTest für MultiExtends Problem
- Verhindern von doppelten Methoden von Class -> ClassGen
This commit is contained in:
parent
c80dc162d9
commit
b4d7ab02eb
@ -1,8 +1,12 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.commons.bcel6.classfile.BootstrapMethod;
|
||||
import org.apache.commons.bcel6.classfile.BootstrapMethods;
|
||||
@ -10,6 +14,7 @@ import org.apache.commons.bcel6.classfile.ConstantPool;
|
||||
import org.apache.commons.bcel6.classfile.InnerClass;
|
||||
import org.apache.commons.bcel6.classfile.InnerClasses;
|
||||
import org.apache.commons.bcel6.classfile.JavaClass;
|
||||
import org.apache.commons.bcel6.classfile.Method;
|
||||
import org.apache.commons.bcel6.classfile.Signature;
|
||||
import org.apache.commons.bcel6.generic.ClassGen;
|
||||
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
||||
@ -34,6 +39,7 @@ public class ClassGenerator extends ClassGen{
|
||||
private Menge<TypePlaceholder> usedTPHs = new Menge<>();
|
||||
|
||||
private Map<String, ClassGenerator> extraClasses = new HashMap<>();
|
||||
private List<String> methodsNamesAndTypes = new LinkedList<>();
|
||||
|
||||
public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResults typeinferenceResults) {
|
||||
super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen());
|
||||
@ -162,6 +168,20 @@ public class ClassGenerator extends ClassGen{
|
||||
public TypeinferenceResults getTypeinferenceResults() {
|
||||
return tiResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMethod(Method m) {
|
||||
String methodNameAndTypes = m.getName()+Arrays.toString(m.getArgumentTypes());
|
||||
|
||||
if(methodsNamesAndTypes.contains(methodNameAndTypes)){
|
||||
return;
|
||||
}
|
||||
|
||||
methodsNamesAndTypes.add(methodNameAndTypes);
|
||||
super.addMethod(m);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -74,7 +74,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
protected UsedId pkgName;
|
||||
protected Modifiers modifiers;
|
||||
protected String name;
|
||||
private List<String> methodSignaturesAndNames = new LinkedList<>();
|
||||
|
||||
/**
|
||||
*
|
||||
@ -1042,14 +1041,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
public boolean isInterface(){
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean methodExists(String nameAndSignature) {
|
||||
return methodSignaturesAndNames.contains(nameAndSignature);
|
||||
}
|
||||
|
||||
protected void addMethod(String nameAndSignature) {
|
||||
methodSignaturesAndNames.add(nameAndSignature);
|
||||
}
|
||||
|
||||
/*
|
||||
private Collection<? extends ByteCodeResult> getGenericClasses() {
|
||||
|
@ -634,10 +634,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
|
||||
Logger.getLogger("nameAndSignature").error(nameAndSignature, Section.CODEGEN);
|
||||
|
||||
if(classObj.methodExists(nameAndSignature)){
|
||||
Logger.getLogger("methodExists").debug(this.toString(), Section.CODEGEN);
|
||||
continue;
|
||||
}
|
||||
|
||||
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
|
||||
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
|
||||
@ -649,7 +645,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
|
||||
//Methode generieren und anfügen:
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
|
||||
classObj.addMethod(nameAndSignature);
|
||||
|
||||
Logger.getLogger("createMethod").debug(this.toString(), Section.CODEGEN);
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ public class AutoOverloadingMultiResultsTest extends SourceFileBytecodeTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testConstruct() throws Exception{
|
||||
ClassLoader classLoader = getClassLoader();
|
||||
|
||||
|
11
test/bytecode/types/MultiExtends.jav
Normal file
11
test/bytecode/types/MultiExtends.jav
Normal file
@ -0,0 +1,11 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class MultiExtends{
|
||||
Integer method(Vector<Integer> a){
|
||||
return method2(a);
|
||||
}
|
||||
|
||||
Integer method2(Vector<Number> b){
|
||||
return 1;
|
||||
}
|
||||
}
|
35
test/bytecode/types/MultiExtendsTest.java
Normal file
35
test/bytecode/types/MultiExtendsTest.java
Normal file
@ -0,0 +1,35 @@
|
||||
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 org.junit.Ignore;
|
||||
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
|
||||
public class MultiExtendsTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "MultiExtends";
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user