From 400069573670d9caf9e91c4d39ea224ce1c52f3a Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 18 Jun 2014 13:37:17 +0200 Subject: [PATCH] BoundedGenerics werden nun auch mit einbezogen --- src/mycompiler/myclass/Class.java | 10 +++++++--- src/mycompiler/mytype/BaseType.java | 11 +++++++++++ src/mycompiler/mytype/BoundedGenericTypeVar.java | 1 - src/mycompiler/mytype/GenericTypeVar.java | 7 ++++++- .../assumptions/GenericVarAssumption.java | 2 +- .../TypeInsertTests/BoundedGenericTest.jav | 6 ++++++ .../TypeInsertTests/BoundedGenericsTest.java | 16 ++++++++++++++++ .../TypeInsertTests/GenericTypeVarTest.java | 4 ++-- 8 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 test/plugindevelopment/TypeInsertTests/BoundedGenericTest.jav create mode 100644 test/plugindevelopment/TypeInsertTests/BoundedGenericsTest.java diff --git a/src/mycompiler/myclass/Class.java b/src/mycompiler/myclass/Class.java index 3f8efa0b..9c1aed6f 100755 --- a/src/mycompiler/myclass/Class.java +++ b/src/mycompiler/myclass/Class.java @@ -651,9 +651,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit TypeAssumptions assumptions = this.getPrivateFieldAssumptions(); //Globale Assumptions anfügen: assumptions.add(globalAssumptions); - + + ConstraintsSet oderConstraints = new ConstraintsSet(); + for(Type gparam : this.paralist){ - if(gparam instanceof GenericTypeVar)((GenericTypeVar)gparam).TYPE(assumptions); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen + if(gparam instanceof GenericTypeVar)oderConstraints.add(((GenericTypeVar)gparam).TYPE(assumptions)); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen } typinferenzLog.debug("Erstellte Assumptions: "+assumptions); @@ -671,7 +673,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit //ConstraintsSet oderConstraints = this.TYPE(this.getMethodList(), fieldInitializers, assumptions); - ConstraintsSet oderConstraints = new ConstraintsSet(); + for(Field f:this.getFields()){ oderConstraints.add(f.TYPE(assumptions)); } @@ -1259,10 +1261,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit * @return */ public RefType getType() { + /* Vector parameter = new Vector(); for(Type param : this.get_ParaList()){ parameter.add(((GenericTypeVar)param).getTypePlaceHolder());//(TypePlaceholder.fresh()); //Hier ist kein ReplacementListener notwendig. Der Typ soll nie eingesetzt werden. Der TPH wird nur gebraucht, damit das Unifizieren funktioniert. } + */ return new RefType(this.getName(), this.get_ParaList(), 0); } diff --git a/src/mycompiler/mytype/BaseType.java b/src/mycompiler/mytype/BaseType.java index ad606c5c..21c0c6f9 100755 --- a/src/mycompiler/mytype/BaseType.java +++ b/src/mycompiler/mytype/BaseType.java @@ -1,5 +1,9 @@ // ino.module.BaseType.8667.package package mycompiler.mytype; + +import mycompiler.IItemWithOffset; +import typinferenz.assumptions.TypeAssumptions; + // ino.end // ino.class.BaseType.26435.declaration public abstract class BaseType extends Type @@ -76,5 +80,12 @@ public abstract class BaseType extends Type public void setArray(boolean IsArray) { this.IsArray = IsArray; } + + @Override + public Type checkType(TypeAssumptions ass, IItemWithOffset parent) { + return this; //Die Base-Types müssen nicht nachgeschlagen werden. + } + + } // ino.end diff --git a/src/mycompiler/mytype/BoundedGenericTypeVar.java b/src/mycompiler/mytype/BoundedGenericTypeVar.java index 5bd4f081..a2d8566a 100755 --- a/src/mycompiler/mytype/BoundedGenericTypeVar.java +++ b/src/mycompiler/mytype/BoundedGenericTypeVar.java @@ -50,7 +50,6 @@ public class BoundedGenericTypeVar extends GenericTypeVar // ino.end // ino.method.BoundedGenericTypeVar.29409.body { - //TODO: Dieser Konstruktor muss this.genericConstraint setzen super(s, offset); if(bounds != null)for(Type t : bounds){ if(t!=null)this.extendVars.add(t); diff --git a/src/mycompiler/mytype/GenericTypeVar.java b/src/mycompiler/mytype/GenericTypeVar.java index 30aa00b3..e228ee66 100755 --- a/src/mycompiler/mytype/GenericTypeVar.java +++ b/src/mycompiler/mytype/GenericTypeVar.java @@ -194,8 +194,13 @@ public class GenericTypeVar extends Type public ConstraintsSet TYPE(TypeAssumptions ass){ ConstraintsSet ret = new ConstraintsSet(); - if(this.genericConstraint != null)ret.add(new SingleConstraint(this.genericConstraint.TA1, this.genericConstraint.TA2)); ass.addGenericVarAssumption(this); + //if(this.genericConstraint != null)ret.add(new SingleConstraint(this.genericConstraint.TA1, this.genericConstraint.TA2)); + if(this.extendVars != null){ + for(Type ev : this.extendVars){ + ret.add(new SingleConstraint(ass.getTypeFor(this), ass.getTypeFor(ev))); + } + } return ret; } diff --git a/src/typinferenz/assumptions/GenericVarAssumption.java b/src/typinferenz/assumptions/GenericVarAssumption.java index 3b525e41..2cc2a465 100644 --- a/src/typinferenz/assumptions/GenericVarAssumption.java +++ b/src/typinferenz/assumptions/GenericVarAssumption.java @@ -15,7 +15,7 @@ public class GenericVarAssumption extends Assumption{ } public Type getAssumedType() { - return new RefType(this.getIdentifier(), -1); + return genericVar;//new RefType(this.getIdentifier(), -1); } public String getIdentifier(){ diff --git a/test/plugindevelopment/TypeInsertTests/BoundedGenericTest.jav b/test/plugindevelopment/TypeInsertTests/BoundedGenericTest.jav new file mode 100644 index 00000000..a3991d78 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/BoundedGenericTest.jav @@ -0,0 +1,6 @@ +class BoundedGenericTest{ + var; + B methode(){ + return var; + } +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/BoundedGenericsTest.java b/test/plugindevelopment/TypeInsertTests/BoundedGenericsTest.java new file mode 100644 index 00000000..f0c5094a --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/BoundedGenericsTest.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class BoundedGenericsTest { + private static final String TEST_FILE = "BoundedGenericTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("var"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.java b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.java index 8166cf86..46e1c93d 100644 --- a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.java +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.java @@ -8,14 +8,14 @@ public class GenericTypeVarTest { private static final String TEST_FILE = "GenericTypeVarTest.jav"; private static final String TEST_FILE2 = "GenericTypeVarTest2.jav"; - /* + @Test public void run(){ Vector mustContain = new Vector(); mustContain.add("String methode"); MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); } - */ + @Test public void run2(){ Vector mustContain = new Vector();