Fehler mit Wildcards in ASTFactory beheben

This commit is contained in:
JanUlrich 2018-08-06 14:01:31 +02:00
parent acf8c108e8
commit af894ebfe4
3 changed files with 23 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import org.antlr.v4.runtime.Token;
/**
@ -201,8 +202,19 @@ public class ASTFactory {
//Diese entfernen:
name = name.split("<")[0];
}
RefType ret = new RefType(new JavaClassName(name), params, new NullToken());
return ret;
if(type instanceof java.lang.reflect.WildcardType){
java.lang.reflect.WildcardType wildcardType = (java.lang.reflect.WildcardType) type;
if(wildcardType.getLowerBounds().length > 0){
return new SuperWildcardType(convertType(wildcardType.getLowerBounds()[0]), new NullToken());
}else if(wildcardType.getUpperBounds().length > 0){
return new ExtendsWildcardType(convertType(wildcardType.getUpperBounds()[0]), new NullToken());
}else{//Es handelt sich um den '?'-Typ:
return new ExtendsWildcardType(createObjectType(), new NullToken());
}
}else{
RefType ret = new RefType(new JavaClassName(name), params, new NullToken());
return ret;
}
}
}

View File

@ -34,6 +34,10 @@ public class ExtendsWildcardType extends WildcardType{
return false;
}
@Override
public String toString() {
return "? extends "+innerType.toString();
}
@Override
public void accept(ASTVisitor visitor) {

View File

@ -35,6 +35,11 @@ public class SuperWildcardType extends WildcardType{
return this.innerType;
}
@Override
public String toString() {
return "? super "+innerType.toString();
}
@Override
public boolean isExtends() {
return false;