forked from JavaTX/JavaCompilerCore
ASTFactory createClass setzt SuperType
GenericClass erhält richtigen SuperType Tests für ? extends und ? super angelegt
This commit is contained in:
parent
64dce5d814
commit
e9607e37b1
@ -240,7 +240,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
* @param modifiers
|
||||
* @param supertypeGenPara - Eine Liste von Namen, welche die Generischen Parameter der Klasse darstellen.
|
||||
*/
|
||||
public Class(String name, RefType superClass, Modifiers modifiers,
|
||||
public Class(String name, Type superClass, Modifiers modifiers,
|
||||
Menge<String> supertypeGenPara) {
|
||||
this(name,superClass,modifiers,0);
|
||||
if(supertypeGenPara == null)return;
|
||||
@ -252,7 +252,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
this.setGenericParameter(new GenericDeclarationList(gtvs,0));
|
||||
}
|
||||
|
||||
public Class(String name, RefType superClass, Modifiers mod, int offset){
|
||||
public Class(String name, Type superClass, Modifiers mod, int offset){
|
||||
this(name,mod,offset);
|
||||
if(superClass == null)this.superClass = new Class("java.lang.Object",-1).getType();
|
||||
else this.superClass = superClass;
|
||||
|
@ -8,8 +8,11 @@ import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
@ -48,15 +51,12 @@ public class ASTFactory {
|
||||
return new Constructor(method, superClass);
|
||||
}
|
||||
|
||||
public static Class createClass(String className, String superClass, SourceFile parent) {
|
||||
public static Class createClass(String className, Type type, Modifiers modifiers, Menge<String> supertypeGenPara, SourceFile parent) {
|
||||
// TODO bytecode createClass
|
||||
Class generatedClass = new Class(className, 0);
|
||||
//String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara
|
||||
Class generatedClass = new Class(className, type, modifiers, supertypeGenPara);
|
||||
generatedClass.addField(ASTFactory.createEmptyConstructor(generatedClass));
|
||||
|
||||
if(superClass != null){
|
||||
generatedClass.superclassid = UsedId.createFromQualifiedName(superClass, 0);
|
||||
}
|
||||
|
||||
generatedClass.parserPostProcessing(parent);
|
||||
|
||||
return generatedClass;
|
||||
|
23
src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java
Normal file
23
src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
public class GenericClassType extends RefType{
|
||||
|
||||
public GenericClassType(String fullyQualifiedName, Menge parameter, SyntaxTreeNode parent, int offset) {
|
||||
super(fullyQualifiedName, parameter, parent, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
return "L"+getTypeName()+";";
|
||||
}
|
||||
}
|
@ -833,27 +833,10 @@ public class RefType extends ObjectType implements IMatchable
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
/*
|
||||
String paramString = "";
|
||||
if(this.parameter != null && this.parameter.size()>0){
|
||||
paramString+="<";
|
||||
Iterator<Type> it = this.parameter.iterator();
|
||||
while(it.hasNext()){
|
||||
Type param = it.next();
|
||||
paramString+=param.getBytecodeSignature(cg);
|
||||
}
|
||||
paramString+=">";
|
||||
}
|
||||
String typeSignature = this.getBytecodeType(cg).getSignature();
|
||||
typeSignature = typeSignature.substring(0, typeSignature.length()-1);
|
||||
return typeSignature+paramString+";";
|
||||
*/
|
||||
|
||||
//TODO: bytecode woher bekommt ich die parent klasse
|
||||
String combinedType = getCombinedType(cg);
|
||||
if(!combinedType.equals(getName().toString())){
|
||||
// TODO bytecode statt getParentClass die eigene Class?!?!
|
||||
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getName().toString(), new SourceFile());
|
||||
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getGenericClassType(), null, null, new SourceFile());
|
||||
|
||||
cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet())).getByteCode());
|
||||
}
|
||||
@ -874,7 +857,7 @@ public class RefType extends ObjectType implements IMatchable
|
||||
}else if(type instanceof TypePlaceholder){
|
||||
sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%"));
|
||||
}else{
|
||||
sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%"));
|
||||
sb.append(type.getBytecodeType(cg).toString().replace(".", "%"));
|
||||
}
|
||||
|
||||
sb.append("%");
|
||||
@ -886,6 +869,10 @@ public class RefType extends ObjectType implements IMatchable
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public GenericClassType getGenericClassType(){
|
||||
return new GenericClassType(getName().toString(), getParaList(), parent, getOffset());
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
13
test/bytecode/types/ExtendsType.jav
Normal file
13
test/bytecode/types/ExtendsType.jav
Normal file
@ -0,0 +1,13 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class SuperType{
|
||||
Vector<Integer> integerVector;
|
||||
|
||||
void method() {
|
||||
method(integerVector);
|
||||
}
|
||||
|
||||
void method(Vector<? extends Number> v) {
|
||||
|
||||
}
|
||||
}
|
31
test/bytecode/types/ExtendsType.java
Normal file
31
test/bytecode/types/ExtendsType.java
Normal file
@ -0,0 +1,31 @@
|
||||
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.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
|
||||
public class ExtendsType extends BytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "SuperType";
|
||||
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);
|
||||
}
|
||||
}
|
13
test/bytecode/types/SuperType.jav
Normal file
13
test/bytecode/types/SuperType.jav
Normal file
@ -0,0 +1,13 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class SuperType{
|
||||
Vector<Number> numberVector;
|
||||
|
||||
void method() {
|
||||
method(numberVector);
|
||||
}
|
||||
|
||||
void method(Vector<? super Integer> v) {
|
||||
|
||||
}
|
||||
}
|
32
test/bytecode/types/SuperType.java
Normal file
32
test/bytecode/types/SuperType.java
Normal file
@ -0,0 +1,32 @@
|
||||
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.BytecodeTest;
|
||||
|
||||
public class SuperType extends BytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "ExtendsType";
|
||||
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