diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index b7f14f19..33ece33e 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -427,6 +427,9 @@ public class SyntaxTreeGenerator{ GenericsRegistry ret = new GenericsRegistry(this.globalGenerics); ret.putAll(generics); if(ctx == null || ctx.typeParameterList() == null)return ret; + for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){ + ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod)); + } for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){ TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret); } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index 20846a1b..371a5d79 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -77,7 +77,6 @@ public class TypeGenerator { List bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics); GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop()); - generics.put(name, new GenericContext(parentClass, parentMethod)); return ret; } @@ -92,7 +91,7 @@ public class TypeGenerator { return ret; } if(typeBoundContext.classOrInterfaceType() != null){ - ret.add(convert(typeBoundContext.classOrInterfaceType())); + ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics)); if(typeBoundContext.additionalBound() != null) for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){ ret.add(convert(addCtx.interfaceType())); @@ -103,8 +102,9 @@ public class TypeGenerator { } } - private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) { - throw new NotImplementedException(); + private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) { + Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType(); + return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),classOrInterfaceTypeContext.getStart(), reg, generics); } private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) { @@ -114,8 +114,7 @@ public class TypeGenerator { public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) { if(referenceTypeContext.classOrInterfaceType() != null){ if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){ - Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType(); - return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics); + return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics); }else{ throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 4168b587..bf9fe263 100644 --- a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -66,10 +66,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(ParameterList formalParameters) { - Iterator genericIterator = formalParameters.getFormalparalist().iterator(); - if(genericIterator.hasNext()){ - while(genericIterator.hasNext()){ - genericIterator.next().accept(this); + Iterator it = formalParameters.getFormalparalist().iterator(); + if(it.hasNext()){ + while(it.hasNext()){ + it.next().accept(this); } } } diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index e0c09e92..d0177ace 100644 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -12,6 +12,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 +34,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; diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 5c2f1ee6..d92d0b9a 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -38,7 +38,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(); diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index ad591ebe..9e5ba545 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -59,13 +59,11 @@ class TypeInsertPlacerClass extends AbstractASTWalker{ } @Override - public void visit(ParameterList params) { - for(FormalParameter param : params){ + public void visit(FormalParameter param) { if(param.getType() instanceof TypePlaceholder) inserts.add(TypeInsertFactory.createInsertPoints( param.getType(), param.getType().getOffset(), cl, method, results)); - } - super.visit(params); + super.visit(param); } @Override 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 diff --git a/test/javFiles/Generics.jav b/test/javFiles/Generics.jav index c76b40aa..dd7b4eba 100644 --- a/test/javFiles/Generics.jav +++ b/test/javFiles/Generics.jav @@ -1,3 +1,4 @@ +import java.lang.String; class Generics { // A mt1(A a, B b){ diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index b218347f..4e7d9868 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -42,7 +42,7 @@ public class GeneralParserTest{ filenames.add("StructuralTypes.jav"); */ // filenames.add("ExtendsTest.jav"); - filenames.add("OpratorTest.jav"); + filenames.add("PackageNameTest.jav"); try{ new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList())); }catch(Exception exc){