diff --git a/src/de/dhbwstuttgart/parser/JavaParser.java b/src/de/dhbwstuttgart/parser/JavaParser.java index c62303e2..a90acd91 100644 --- a/src/de/dhbwstuttgart/parser/JavaParser.java +++ b/src/de/dhbwstuttgart/parser/JavaParser.java @@ -1038,7 +1038,7 @@ case 42: // line 535 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { /*Luar 29.11.06 Offset auf -1, da keine Angabe vorhanden*/ - WildcardType wc = new WildcardType(null,-1); + WildcardType wc = new WildcardType(null,null,-1); yyVal = wc; } break; diff --git a/src/de/dhbwstuttgart/parser/JavaParser.jay b/src/de/dhbwstuttgart/parser/JavaParser.jay index 96b4facf..7d6874b0 100755 --- a/src/de/dhbwstuttgart/parser/JavaParser.jay +++ b/src/de/dhbwstuttgart/parser/JavaParser.jay @@ -534,7 +534,7 @@ paralist : IDENTIFIER wildcardparameter : '?' { //Luar 29.11.06 Offset auf -1, da keine Angabe vorhanden - WildcardType wc = new WildcardType(null,-1); + WildcardType wc = new WildcardType(null,null,-1); $$ = wc; } | '?' EXTENDS referencetype diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java index dc4bedbe..419061f1 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java @@ -62,11 +62,11 @@ public abstract class AddOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Integer",this,-1), this), ass.getTypeFor(new RefType("java.lang.Integer",this,-1),this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Double",this,-1), this), ass.getTypeFor(new RefType("java.lang.Double",this,-1),this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Float",this,-1), this), ass.getTypeFor(new RefType("java.lang.Float",this,-1),this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Long",this,-1), this), ass.getTypeFor(new RefType("java.lang.Long",this,-1),this)); - ret.put(ass.getTypeFor(new RefType("java.lang.String",this,-1),this), ass.getTypeFor(new RefType("java.lang.String",this,-1),this)); + ret.put(new RefType("java.lang.Integer",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Double",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Float",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Long",this,-1).TYPE(ass, this), new RefType("java.lang.Long",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.String",this,-1).TYPE(ass, this), new RefType("java.lang.String",this,-1).TYPE(ass, this)); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java index ce80cd9b..7b2953ab 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java @@ -232,7 +232,7 @@ public abstract class LogOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap<>(); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",this,-1), this), ass.getTypeFor(new RefType("java.lang.Boolean",this,-1), this)); + ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Boolean",this,-1).TYPE(ass, this)); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java index e3b37f08..34ca0f7e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java @@ -43,10 +43,10 @@ public abstract class MulOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap<>(); - ret.put(ass.getTypeFor(new RefType("java.lang.Integer",this,-1), this), ass.getTypeFor(new RefType("java.lang.Integer",this,-1), this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Double",this,-1), this), ass.getTypeFor(new RefType("java.lang.Double",this,-1), this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Float",this,-1), this), ass.getTypeFor(new RefType("java.lang.Float",this,-1), this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Long",this,-1), this), ass.getTypeFor(new RefType("java.lang.Long",this,-1), this)); + ret.put(new RefType("java.lang.Integer",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Double",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Float",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Long",this,-1).TYPE(ass, this), new RefType("java.lang.Long",this,-1).TYPE(ass, this)); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java index c0718774..43fb132d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java @@ -54,10 +54,10 @@ public abstract class RelOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap<>(); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",this,-1), this), ass.getTypeFor(new RefType("java.lang.Integer",this,-1), this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",this,-1), this), ass.getTypeFor(new RefType("java.lang.Double",this,-1), this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",this,-1), this), ass.getTypeFor(new RefType("java.lang.Float",this,-1), this)); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",this,-1), this), ass.getTypeFor(new RefType("java.lang.Long",this,-1), this)); + ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this)); + ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Long",this,-1).TYPE(ass, this)); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index 8b8ae046..4541f13c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -258,7 +258,7 @@ public class IfStmt extends Statement ret.add(this.else_block.TYPEStmt(assumptions)); if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); } - ret.add(new SingleConstraint(expr.getType().TYPE(assumptions, this),assumptions.getTypeFor(new RefType("Boolean",this,0), this))); //(expressionDesIfStmt)<.boolean + ret.add(new SingleConstraint(expr.getType().TYPE(assumptions, this),new RefType("Boolean",this,0).TYPE(assumptions, this))); //(expressionDesIfStmt)<.boolean if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); if(then_block.getType() instanceof Void && (else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this,this.getOffset())); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 055f8041..7976481a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -155,39 +155,33 @@ public class LambdaExpression extends Expr{ ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression //Die Constraints für ParameterTypen und Ret Typ erstellen: - Vector tphParamTypes = new Vector<>(); + Vector modifiedParamTypes = new Vector<>(); for(Type pT : paramTypes){ - TypePlaceholder tph = TypePlaceholder.fresh(this); - tphParamTypes.add(tph); - // PN < TPH PN if(pT instanceof WildcardType){ - ret.add(new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this))); + //Auf Typfehler kontrollieren. Siehe Bug #12 Kommentar 3 + if(pT instanceof ExtendsWildcardType){ + throw new TypeinferenceException("Typfehler von Parametertyp "+pT,this); + }else{ + modifiedParamTypes.add(pT); + } }else{ - OderConstraint orCons = new OderConstraint(); - SuperWildcardType superpT = new SuperWildcardType(pT.getOffset(), (ObjectType) pT); - SingleConstraint cons1 = new SingleConstraint(tph.TYPE(assumptions, this), superpT.TYPE(assumptions, this)); - SingleConstraint cons2 = new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this)); - orCons.addConstraint(cons1); - orCons.addConstraint(cons2); - ret.add(orCons); + modifiedParamTypes.add(new SuperWildcardType((ObjectType) pT)); } } Type retType = method_body.getType(); - Type tphRetType = TypePlaceholder.fresh(this); // PN < TPH PN if(retType instanceof WildcardType){ - ret.add(new SingleConstraint(retType.TYPE(assumptions, this), tphRetType.TYPE(assumptions, this))); - }else{ - OderConstraint orCons = new OderConstraint(); - SuperWildcardType superretType = new SuperWildcardType(retType.getOffset(), (ObjectType) retType); - SingleConstraint cons1 = new SingleConstraint(tphRetType.TYPE(assumptions, this), superretType.TYPE(assumptions, this)); - SingleConstraint cons2 = new SingleConstraint(tphRetType.TYPE(assumptions, this), retType.TYPE(assumptions, this)); - orCons.addConstraint(cons1); - orCons.addConstraint(cons2); - ret.add(orCons); + //Auf Typfehler kontrollieren. Siehe Bug #12 Kommentar 3 + if(retType instanceof SuperWildcardType){ + throw new TypeinferenceException("Typfehler von Parametertyp "+retType,this); + }else{ + //retType bleibt unverändert + } + }else{ + retType = new ExtendsWildcardType((ObjectType) retType); } - ret.add(new SingleConstraint(new FunN(tphRetType, tphParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); + ret.add(new SingleConstraint(new FunN(retType, modifiedParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java index e859441e..d318c9da 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java @@ -145,7 +145,7 @@ public class NotExpr extends UnaryExpr public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); OderConstraint constraint = new OderConstraint(); - constraint.addConstraint(this.getType().TYPE(assumptions, this), assumptions.getTypeFor(new RefType("Boolean",this,-1),this)); + constraint.addConstraint(this.getType().TYPE(assumptions, this), new RefType("Boolean",this,-1).TYPE(assumptions, this)); ret.add(constraint); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index 8d1e0ddc..13a2ace4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -165,7 +165,7 @@ public class WhileStmt extends Statement public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); ret.add(expr.TYPEExpr(assumptions)); - SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType().TYPE(assumptions, this), assumptions.getTypeFor(new RefType("Boolean",this, 0), this)); // while(expr){}; expr <. boolean + SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType().TYPE(assumptions, this), new RefType("Boolean",this, 0).TYPE(assumptions, this)); // while(expr){}; expr <. boolean ret.add(exprMustBeBool); ret.add(this.loop_block.TYPEStmt(assumptions)); this.setType(loop_block.getType()); diff --git a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java index 87f4616c..15bee03a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java @@ -91,7 +91,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar Vector tempBounds = new Vector<>(); if(this.bounds != null){ for(ObjectType ev : this.bounds){ - ConstraintType extendsType = ass.getTypeFor(ev, this); + ConstraintType extendsType = ev.TYPE(ass, this); if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); //TODO: ??? stimmt der Cast??? diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java index 5790a29a..7ab8e5e6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java @@ -20,19 +20,20 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; public class ExtendsWildcardType extends WildcardType implements ITypeContainer, IMatchable{ - private ObjectType extendsType = null; - /** * Author: Arne Lüdtke
* Standard Konstruktor für eine ExtendsWildcard */ public ExtendsWildcardType (int offset, ObjectType extendsType) { - super(extendsType.getParent(), offset); - this.extendsType = extendsType; + super(extendsType, extendsType.getParent(), offset); this.name = new JavaClassName(this.toString()); } + public ExtendsWildcardType(ObjectType extendsType) { + this(extendsType.getOffset(),extendsType); + } + /** * Author: Arne Lüdtke
* Gibt den Typen in der Wildcard zurück. @@ -41,7 +42,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, */ public ObjectType get_ExtendsType() { - return this.extendsType; + return this.innerType; } /** @@ -50,7 +51,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, */ public String toString() { - return "? extends " + extendsType.toString(); + return "? extends " + innerType.toString(); } /** @@ -61,7 +62,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, public ExtendsWildcardType clone() { //Hier ist unklar, ob der Extends Type auch geklont werden muss. - return new ExtendsWildcardType(getOffset(),extendsType.clone()); + return new ExtendsWildcardType(getOffset(),innerType.clone()); } /** @@ -88,7 +89,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, */ public FreshExtendsWildcardType GetFreshWildcardType() { - return new FreshExtendsWildcardType(this.extendsType,this.getParent(),-1); + return new FreshExtendsWildcardType(this.innerType,this.getParent(),-1); } /** @@ -109,7 +110,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, public void SetWildcardType(ObjectType T) { //if(T instanceof RefType) - this.extendsType = (RefType)T; + this.innerType = (RefType)T; } /** @@ -134,26 +135,26 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { - return new JavaCodeResult("? extends "+this.extendsType.printJavaCode(resultSet)); + return new JavaCodeResult("? extends "+this.innerType.printJavaCode(resultSet)); } @Override public Vector getInvolvedTypePlaceholder() { Vector ret = super.getInvolvedTypePlaceholder(); - ret.addAll(this.extendsType.getInvolvedTypePlaceholder()); + ret.addAll(this.innerType.getInvolvedTypePlaceholder()); return ret; } @Override public void parserPostProcessing(SyntaxTreeNode parent) { super.parserPostProcessing(parent); - this.extendsType.parserPostProcessing(this); + this.innerType.parserPostProcessing(this); } @Override public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) { //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(); + this.innerType = (ObjectType) this.innerType.TYPE(ass, parent).getType(); return super.TYPE(ass, parent); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java index 829f0f40..3b3f0fc2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java @@ -147,7 +147,7 @@ public class FreshWildcardType extends Type { */ public WildcardType get_WildcardType() { - return new WildcardType(this.getParent(),this.getOffset()); + return new WildcardType(null, this.getParent(),this.getOffset()); } /** * Author: Arne Lüdtke
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java index 5907388c..424fba25 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java @@ -18,16 +18,17 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; public class SuperWildcardType extends WildcardType implements ITypeContainer, IMatchable{ - private ObjectType superType = null; + public SuperWildcardType(ObjectType innerType){ + this(innerType.getOffset(), innerType); + } /** * Author: Arne Lüdtke
* Standard Konstruktor für eine SuperWildcard */ - public SuperWildcardType(int offset, ObjectType superType) + public SuperWildcardType(int offset, ObjectType innerType) { - super(superType.getParent(),offset); - this.superType = superType; + super(innerType, innerType.getParent(),offset); } /** @@ -38,7 +39,7 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I */ public ObjectType get_SuperType() { - return this.superType; + return this.innerType; } /** @@ -47,7 +48,7 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I */ public String toString() { - return "? super " + superType.toString(); + return "? super " + innerType.toString(); } /** @@ -57,7 +58,7 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I */ public SuperWildcardType clone() { - return new SuperWildcardType(getOffset(), (ObjectType) superType.clone()); + return new SuperWildcardType(getOffset(), (ObjectType) innerType.clone()); } @@ -68,17 +69,17 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I */ public FreshSuperWildcardType GetFreshWildcardType() { - return new FreshSuperWildcardType(this.superType,this.getParent(),-1); + return new FreshSuperWildcardType(this.innerType,this.getParent(),-1); } /** * Author: Arne Lüdtke
- * Das gleiche wie get_SuperType(). + * Das gleiche wie get_innerType(). * Überschreibt die Methode der Superklasse */ public Type GetWildcardType() { - return this.get_SuperType(); + return this.get_innerType(); } /** @@ -89,17 +90,17 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I public void SetWildcardType(ObjectType T) { //if(T instanceof RefType) - this.superType = (RefType)T; + this.innerType = (RefType)T; } /** * Author: Arne Lüdtke
- * Das gleiche wie get_SuperType(). + * Das gleiche wie get_innerType(). * Implementiert ITypeContainer */ public Type getContainedType() { - return this.get_SuperType(); + return this.get_innerType(); } /** @@ -109,12 +110,12 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I */ public Type getMatchType() { - return this.get_SuperType(); + return this.get_innerType(); } @Override public JavaCodeResult printJavaCode(ResultSet result){ - return new JavaCodeResult("? super " + this.superType.printJavaCode(result)); + return new JavaCodeResult("? super " + this.innerType.printJavaCode(result)); } /** @@ -137,19 +138,19 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I @Override public Vector getInvolvedTypePlaceholder() { Vector ret = super.getInvolvedTypePlaceholder(); - ret.addAll(this.superType.getInvolvedTypePlaceholder()); + ret.addAll(this.innerType.getInvolvedTypePlaceholder()); return ret; } @Override public void parserPostProcessing(SyntaxTreeNode parent) { super.parserPostProcessing(parent); - this.superType.parserPostProcessing(this); + this.innerType.parserPostProcessing(this); } @Override public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) { - this.superType = (ObjectType) this.superType.TYPE(ass, parent).getType(); + this.innerType = (ObjectType) this.innerType.TYPE(ass, parent).getType(); return super.TYPE(ass, parent); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 79bdb2e5..7f33ba6a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -6,14 +6,16 @@ package de.dhbwstuttgart.syntaxtree.type; import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import de.dhbwstuttgart.logger.*; +import de.dhbwstuttgart.logger.*; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.typeinference.ConstraintType; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; // ino.class.TypePlaceholder.26780.description type=javadoc @@ -41,7 +43,12 @@ public class TypePlaceholder extends ObjectType private SyntaxTreeNode parent; - // ino.method.TypePlaceholder.26794.defdescription type=javadoc + @Override + public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) { + return new ConstraintType(this); + } + + // ino.method.TypePlaceholder.26794.defdescription type=javadoc /** * Privater Konstruktor - Eine TypePlaceholder-Variable wird �ber die * Factory-Methode fresh() erzeugt. diff --git a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java index aa32de77..ef1ca368 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type; import java.util.Vector; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.typeinference.ConstraintType; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; @@ -17,13 +18,16 @@ import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; public class WildcardType extends Type{ + protected ObjectType innerType = null; + /** * Author: Arne Lüdtke
* Standard Konstruktor für eine Wildcard */ - public WildcardType(SyntaxTreeNode parent, int offset) + public WildcardType(ObjectType innerType, SyntaxTreeNode parent, int offset) { super(parent, offset); + this.innerType = innerType; } /** @@ -41,7 +45,7 @@ public class WildcardType extends Type{ */ public WildcardType clone() { - return new WildcardType(this.getParent(), getOffset()); + return new WildcardType(this.innerType, this.getParent(), getOffset()); } /** @@ -78,6 +82,12 @@ public class WildcardType extends Type{ throw new NotImplementedException(); } + @Override + public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) { + this.innerType = (ObjectType) innerType.TYPE(ass, this).getType(); + return new ConstraintType(this); + } + public boolean equals(Object obj) { if(obj instanceof WildcardType) diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index ecb6c6c5..ddc01bb8 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -285,6 +285,7 @@ public class TypeAssumptions { * @return null, falls der Typ nicht vorhanden ist. */ public ConstraintType getTypeFor(Type t, SyntaxTreeNode inNode){ + /* if(t instanceof WildcardType){ WildcardType wt = (WildcardType)t; Type innerType = wt.GetWildcardType(); @@ -295,7 +296,7 @@ public class TypeAssumptions { if(t instanceof TypePlaceholder) return new ConstraintType((TypePlaceholder)t); //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen. - + */ //Alle bekannten Klassen nach diesem Typ durchsuchen: JavaClassName typName = t.getName(); for(ClassAssumption ass : this.classAssumptions){ diff --git a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java index 440bbd50..0e06e9c4 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java +++ b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java @@ -74,8 +74,8 @@ public class FC_TTO public void generateFullyNamedTypes(TypeAssumptions ass) { for(Pair p : this.FC){ - p.TA1 = ass.getTypeFor(p.TA1, p.TA1.getParent()).getType(); - p.TA2 = ass.getTypeFor(p.TA2, p.TA2.getParent()).getType(); + p.TA1 = p.TA1.TYPE(ass, p.TA1.getParent()).getType();//ass.getTypeFor(p.TA1, p.TA1.getParent()).getType(); + p.TA2 = p.TA2.TYPE(ass, p.TA2.getParent()).getType();//ass.getTypeFor(p.TA2, p.TA2.getParent()).getType(); } } } diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest27.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest27.jav new file mode 100644 index 00000000..cf52b258 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest27.jav @@ -0,0 +1,17 @@ +class Klasse{ +main(String argument){ +var; +var.methode(argument); +return var.methode(argument); +} +} +class Klasse1{ +String methode(String arg){ +return arg; +} +} +class Klasse2{ +Integer methode(Integer arg){ +return arg; +} +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest27.java b/test/plugindevelopment/TypeInsertTests/LambdaTest27.java new file mode 100644 index 00000000..69c2f0bd --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest27.java @@ -0,0 +1,18 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class LambdaTest27 { + + private static final String TEST_FILE = "LambdaTest27.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + //mustContain.add("A a"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +}