diff --git a/src/de/dhbwstuttgart/parser/BoundedClassIdentifierList.java b/src/de/dhbwstuttgart/parser/BoundedClassIdentifierList.java index 6a41d80d..844f6ee6 100644 --- a/src/de/dhbwstuttgart/parser/BoundedClassIdentifierList.java +++ b/src/de/dhbwstuttgart/parser/BoundedClassIdentifierList.java @@ -2,15 +2,16 @@ package de.dhbwstuttgart.parser; import java.util.Vector; +import de.dhbwstuttgart.syntaxtree.type.ObjectType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; -public class BoundedClassIdentifierList extends Vector{ +public class BoundedClassIdentifierList extends Vector{ private int endOffset; - private Vector list; + private Vector list; - public BoundedClassIdentifierList(Vector list, int endOffset){ + public BoundedClassIdentifierList(Vector list, int endOffset){ this.endOffset = endOffset; this.addAll(list); } diff --git a/src/de/dhbwstuttgart/parser/JavaParser.java b/src/de/dhbwstuttgart/parser/JavaParser.java index 69f95ed5..c62303e2 100644 --- a/src/de/dhbwstuttgart/parser/JavaParser.java +++ b/src/de/dhbwstuttgart/parser/JavaParser.java @@ -1561,7 +1561,7 @@ case 110: case 111: // line 990 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - Vector vec=new Vector(); + Vector vec=new Vector(); vec.addElement(((RefType)yyVals[0+yyTop])); containedTypes.addElement(((RefType)yyVals[0+yyTop])); yyVal=new BoundedClassIdentifierList(vec, ((RefType)yyVals[0+yyTop]).getOffset()+((RefType)yyVals[0+yyTop]).getName().toString().length()); diff --git a/src/de/dhbwstuttgart/parser/JavaParser.jay b/src/de/dhbwstuttgart/parser/JavaParser.jay index fbce3875..96b4facf 100755 --- a/src/de/dhbwstuttgart/parser/JavaParser.jay +++ b/src/de/dhbwstuttgart/parser/JavaParser.jay @@ -988,7 +988,7 @@ boundedMethodParameter : IDENTIFIER // returns Vector boundedclassidentifierlist : referencetype { - Vector vec=new Vector(); + Vector vec=new Vector(); vec.addElement($1); containedTypes.addElement($1); $$=new BoundedClassIdentifierList(vec, $1.getOffset()+$1.getName().toString().length()); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 144d1278..57af4a02 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -152,19 +152,24 @@ public class LambdaExpression extends Expr{ //ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys: ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression + //TODO: OderConstraint erstellen mit normalem Typ und ? extemds/super Type //Die Typen innerhalb von FunN anpassen: Vector superParamTypes = new Vector<>(); for(Type pT : paramTypes){ if(pT instanceof ObjectType){ superParamTypes.add(new SuperWildcardType(pT.getOffset(), (ObjectType) pT)); - }else{ + }else{ //pT ist weder Void noch ein ObjectType (TPH, GTV, RefType) superParamTypes.add(pT); } } Type retType = method_body.getType(); Type extRetType = retType; if(!(retType instanceof de.dhbwstuttgart.syntaxtree.type.Void)){ - extRetType = new ExtendsWildcardType(retType.getOffset(), retType); + if(retType instanceof ObjectType){ + extRetType = new ExtendsWildcardType(retType.getOffset(), (ObjectType) retType); + }else{ //retType ist weder Void noch ein ObjectType (TPH, GTV, RefType) + extRetType = retType; + } } ret.add(new SingleConstraint(new FunN(extRetType, superParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); diff --git a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java index cc284edc..87f4616c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java @@ -94,7 +94,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar ConstraintType extendsType = ass.getTypeFor(ev, this); if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); - ??? stimmt der Cast??? + //TODO: ??? stimmt der Cast??? tempBounds.add((ObjectType)extendsType.getType()); //ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType )); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java index 69cb4e6f..5790a29a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java @@ -152,7 +152,8 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, @Override public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) { - this.extendsType = this.extendsType.TYPE(ass, parent).getType(); + //Folgender TypeCast ist sicher. Wird ein ObjectType in einen ConstraintType umgewandelt und wieder zurück, kann kein Fehler auftreten. + this.extendsType = (ObjectType) this.extendsType.TYPE(ass, parent).getType(); return super.TYPE(ass, parent); } } diff --git a/test/plugindevelopment/TypeInsertTests/GenericParaListInsertTest2.jav b/test/plugindevelopment/TypeInsertTests/GenericParaListInsertTest2.jav new file mode 100644 index 00000000..d42042c9 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/GenericParaListInsertTest2.jav @@ -0,0 +1,3 @@ +class GenericParaListInsertTest{ + A methode(a){return a;} +} diff --git a/test/plugindevelopment/TypeInsertTests/GenericParaListInsertTest2.java b/test/plugindevelopment/TypeInsertTests/GenericParaListInsertTest2.java new file mode 100644 index 00000000..8a706d8e --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/GenericParaListInsertTest2.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class GenericParaListInsertTest2 { + private static final String TEST_FILE = "GenericParaListInsertTest2.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("<"); //Es muss eine Parameterliste generiert werden. + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java new file mode 100644 index 00000000..cbeae139 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java @@ -0,0 +1,17 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class GenericTypeVarTest2 { + + private static final String TEST_FILE2 = "GenericTypeVarTest2.jav"; + + @Test + public void run2(){ + Vector mustContain = new Vector(); + mustContain.add("String var2"); + MultipleTypesInsertTester.test(TEST_FILE2, mustContain); + } +}