From 35d5fb2f03e2a7a4316bfce6e68123c45f87c71b Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Mon, 7 May 2018 15:12:07 +0200 Subject: [PATCH 1/2] Fehler in ASTFactory mit Generischen FEldern beheben --- .../dhbwstuttgart/syntaxtree/factory/ASTFactory.java | 4 ++-- test/astfactory/ASTFactoryTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 52921c5d..efd20831 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -37,7 +37,7 @@ public class ASTFactory { methoden.add(createMethod(method, jreClass)); } List 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) { diff --git a/test/astfactory/ASTFactoryTest.java b/test/astfactory/ASTFactoryTest.java index c3b62b0b..6285cf0a 100644 --- a/test/astfactory/ASTFactoryTest.java +++ b/test/astfactory/ASTFactoryTest.java @@ -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 extends HashMap{ System.out.println(Arrays.toString(arguments)); System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration()); } + + public static class GenericFieldTest{ + public G testField; + } + @Test + public void genericFieldTest(){ + ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class); + assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType); + } } \ No newline at end of file From 832623a738a191ddcab57fe4a71d2d99715eb264 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Wed, 16 May 2018 15:37:46 +0200 Subject: [PATCH 2/2] ClassOrInterface muss im Modifier INTERFACE haben, wenn isInterface gesetzt ist --- src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 72097fc0..00788b63 100644 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.syntaxtree; +import com.sun.org.apache.xpath.internal.operations.Mod; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.parser.scope.JavaClassName; @@ -12,6 +13,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -33,6 +35,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ public ClassOrInterface(int modifiers, JavaClassName name, List fielddecl, List methods, List constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset){ super(offset); + if(isInterface && !Modifier.isInterface(modifiers))modifiers += Modifier.INTERFACE; this.modifiers = modifiers; this.name = name; this.fields = fielddecl;