Fehler in ASTFactory mit Generischen FEldern beheben

This commit is contained in:
Andreas Stadelmeier 2018-05-07 15:12:07 +02:00
parent c8728bab10
commit 35d5fb2f03
2 changed files with 14 additions and 2 deletions

View File

@ -37,7 +37,7 @@ public class ASTFactory {
methoden.add(createMethod(method, jreClass));
}
List<Field> felder = new ArrayList<>();
for(java.lang.reflect.Field field : jreClass.getFields()){
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
felder.add(createField(field, name));
}
int modifier = jreClass.getModifiers();
@ -89,7 +89,7 @@ public class ASTFactory {
}
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
return new Field(field.getName(), createType(field.getType(), jreClass, null), field.getModifiers(), new NullToken());
return new Field(field.getName(), createType(field.getGenericType(), jreClass, null), field.getModifiers(), new NullToken());
}
//private static RefType createType(Class classType) {

View File

@ -1,6 +1,9 @@
package astfactory;
//import javafx.collections.ObservableList;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import org.junit.Test;
import java.lang.reflect.ParameterizedType;
@ -19,4 +22,13 @@ public class ASTFactoryTest<A> extends HashMap<String, A>{
System.out.println(Arrays.toString(arguments));
System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration());
}
public static class GenericFieldTest<G>{
public G testField;
}
@Test
public void genericFieldTest(){
ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class);
assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType);
}
}