Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bigRefactoring

This commit is contained in:
JanUlrich 2018-05-28 16:18:49 +02:00
commit c7042d185f
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree; package de.dhbwstuttgart.syntaxtree;
import com.sun.org.apache.xpath.internal.operations.Mod;
import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
@ -12,6 +13,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -33,6 +35,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){ RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
super(offset); super(offset);
if(isInterface && !Modifier.isInterface(modifiers))modifiers += Modifier.INTERFACE;
this.modifiers = modifiers; this.modifiers = modifiers;
this.name = name; this.name = name;
this.fields = fielddecl; this.fields = fielddecl;

View File

@ -37,7 +37,7 @@ public class ASTFactory {
methoden.add(createMethod(method, jreClass)); methoden.add(createMethod(method, jreClass));
} }
List<Field> felder = new ArrayList<>(); 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)); felder.add(createField(field, name));
} }
int modifier = jreClass.getModifiers(); int modifier = jreClass.getModifiers();
@ -89,7 +89,7 @@ public class ASTFactory {
} }
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) { 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) { //private static RefType createType(Class classType) {

View File

@ -1,6 +1,9 @@
package astfactory; package astfactory;
//import javafx.collections.ObservableList; //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 org.junit.Test;
import java.lang.reflect.ParameterizedType; 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(Arrays.toString(arguments));
System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration()); 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);
}
} }