|
|
|
@ -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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -50,15 +51,15 @@ public class ASTFactory {
|
|
|
|
|
java.lang.Class superjreClass = jreClass.getSuperclass();
|
|
|
|
|
RefType superClass;
|
|
|
|
|
if(parameterSuperClass != null){
|
|
|
|
|
superClass = (RefType) convertType(parameterSuperClass);
|
|
|
|
|
superClass = (RefType) createType(parameterSuperClass);
|
|
|
|
|
}else if(superjreClass != null){
|
|
|
|
|
superClass = (RefType) convertType(superjreClass);
|
|
|
|
|
superClass = (RefType) createType(superjreClass);
|
|
|
|
|
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
|
|
|
|
|
superClass = (RefType) createType(java.lang.Object.class, name, "");
|
|
|
|
|
superClass = (RefType) createType(java.lang.Object.class);
|
|
|
|
|
}
|
|
|
|
|
List<RefType> implementedInterfaces = new ArrayList<>();
|
|
|
|
|
for(Type jreInterface : jreClass.getGenericInterfaces()){
|
|
|
|
|
implementedInterfaces.add((RefType) createType(jreInterface, name, ""));
|
|
|
|
|
implementedInterfaces.add((RefType) createType(jreInterface));
|
|
|
|
|
}
|
|
|
|
|
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
|
|
|
|
|
|
|
|
|
@ -67,29 +68,8 @@ public class ASTFactory {
|
|
|
|
|
return new ClassOrInterface(modifier, name, felder, methoden, konstruktoren, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static RefTypeOrTPHOrWildcardOrGeneric convertType(Type type){
|
|
|
|
|
if(type instanceof ParameterizedType){
|
|
|
|
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
|
|
|
|
for(Type paramType : ((ParameterizedType)type).getActualTypeArguments()){
|
|
|
|
|
params.add(convertType(paramType));
|
|
|
|
|
}
|
|
|
|
|
JavaClassName name = new JavaClassName(((ParameterizedType) type).getRawType().getTypeName());
|
|
|
|
|
return new RefType(name, params, new NullToken());
|
|
|
|
|
}else if(type instanceof TypeVariable){
|
|
|
|
|
return new GenericRefType(((TypeVariable) type).getName(), new NullToken());
|
|
|
|
|
}else if(type instanceof Class){
|
|
|
|
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
|
|
|
|
Class paramClass = (Class) type;
|
|
|
|
|
for(TypeVariable tv : paramClass.getTypeParameters()){
|
|
|
|
|
params.add(new GenericRefType(tv.getName(), new NullToken()));
|
|
|
|
|
}
|
|
|
|
|
JavaClassName name = new JavaClassName(paramClass.getName());
|
|
|
|
|
return new RefType(name, params, new NullToken());
|
|
|
|
|
}else throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
|
|
|
|
|
return new Field(field.getName(), createType(field.getGenericType(), jreClass, null), field.getModifiers(), new NullToken());
|
|
|
|
|
return new Field(field.getName(), createType(field.getType()), field.getModifiers(), new NullToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//private static RefType createType(Class classType) {
|
|
|
|
@ -98,13 +78,13 @@ public class ASTFactory {
|
|
|
|
|
|
|
|
|
|
private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) {
|
|
|
|
|
String name = constructor.getName();
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass, new JavaClassName(inClass.getName()), name);
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
|
|
|
|
Parameter[] jreParams = constructor.getParameters();
|
|
|
|
|
Type[] jreGenericParams = constructor.getGenericParameterTypes();
|
|
|
|
|
List<FormalParameter> params = new ArrayList<>();
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(Type jreParam : jreGenericParams){
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name);
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam);
|
|
|
|
|
params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken()));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
@ -130,13 +110,13 @@ public class ASTFactory {
|
|
|
|
|
}else{
|
|
|
|
|
jreRetType = jreMethod.getReturnType();
|
|
|
|
|
}
|
|
|
|
|
returnType = createType(jreRetType,new JavaClassName(inClass.getName()), name);
|
|
|
|
|
returnType = createType(jreRetType);
|
|
|
|
|
Parameter[] jreParams = jreMethod.getParameters();
|
|
|
|
|
Type[] jreGenericParams = jreMethod.getGenericParameterTypes();
|
|
|
|
|
List<FormalParameter> params = new ArrayList<>();
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(Type jreParam : jreGenericParams){
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name);
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam);
|
|
|
|
|
params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken()));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
@ -157,18 +137,7 @@ public class ASTFactory {
|
|
|
|
|
return new GenericDeclarationList(gtvs,new NullToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
public RefType createType(java.lang.Class jreClass){
|
|
|
|
|
List<RefTypeOrTPH> params = new ArrayList<>();
|
|
|
|
|
for(TypeVariable jreTV : jreClass.getTypeParameters()){
|
|
|
|
|
RefType gtv = createType(jreTV);
|
|
|
|
|
params.add(gtv);
|
|
|
|
|
}
|
|
|
|
|
return new RefType(names.getName(jreClass.getName()), params, new NullToken());
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){
|
|
|
|
|
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type){
|
|
|
|
|
if(type.getTypeName().equals("void")){
|
|
|
|
|
return new Void(new NullToken());
|
|
|
|
|
}else if(type.getTypeName().equals("int")){
|
|
|
|
@ -193,7 +162,7 @@ public class ASTFactory {
|
|
|
|
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
|
|
|
|
if(type instanceof ParameterizedType){
|
|
|
|
|
for(Type t : ((ParameterizedType)type).getActualTypeArguments()){
|
|
|
|
|
params.add(createType(t, parentClass, parentMethod));
|
|
|
|
|
params.add(createType(t));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String name = type.getTypeName();
|
|
|
|
@ -201,8 +170,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(createType(wildcardType.getLowerBounds()[0]), new NullToken());
|
|
|
|
|
}else if(wildcardType.getUpperBounds().length > 0){
|
|
|
|
|
return new ExtendsWildcardType(createType(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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -212,7 +192,7 @@ public class ASTFactory {
|
|
|
|
|
java.lang.reflect.Type[] bounds = jreTypeVar.getBounds();
|
|
|
|
|
if(bounds.length > 0){
|
|
|
|
|
for(java.lang.reflect.Type bound : bounds){
|
|
|
|
|
genericBounds.add((RefType) createType(bound, parentClass, parentMethod));
|
|
|
|
|
genericBounds.add((RefType) createType(bound));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new de.dhbwstuttgart.syntaxtree.GenericTypeVar(jreTVName, genericBounds, new NullToken(), new NullToken());
|
|
|
|
|