From f20b978b14ece5815963b6852fe002aa90127b42 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sun, 4 Jan 2015 19:30:37 +0100 Subject: [PATCH 1/2] Kleine Anpassungen --- bin/.gitignore | 3 -- .../dhbwstuttgart/syntaxtree/SourceFile.java | 2 +- .../statement/LambdaExpression.java | 9 ++++- .../syntaxtree/type/ExtendsWildcardType.java | 2 +- .../syntaxtree/type/SuperWildcardType.java | 33 ++++++++++--------- .../syntaxtree/type/WildcardType.java | 32 ++++++++---------- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index c682e79ea..34ddca33a 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,5 +1,2 @@ /de/ /plugindevelopment/ -======= -/syntaxTree/ -/bytecode/ diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index a6e8a699d..32856c392 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -698,7 +698,7 @@ public class SourceFile retValue = Unify.unify(pairs, finiteClosure); return retValue;}; oderConstraints.filterWrongConstraints(unifier); - //oderConstraints.unifyUndConstraints(unifier); + oderConstraints.unifyUndConstraints(unifier); typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n", Section.TYPEINFERENCE); //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 20ffdba6a..eec84a109 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.DoubleType; import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.ConstraintsSet; @@ -150,9 +151,15 @@ 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 + //Die Typen innerhalb von FunN anpassen: + Vector superParamTypes = new Vector<>(); + for(Type pT : paramTypes){ + superParamTypes.add(new SuperWildcardType(pT.getOffset(), pT)); + } Type retType = method_body.getType(); ExtendsWildcardType extRetType = new ExtendsWildcardType(retType.getOffset(), retType); - ret.add(new SingleConstraint(new FunN(extRetType, paramTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); + + ret.add(new SingleConstraint(new FunN(extRetType, superParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java index 8531ee818..70677904c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java @@ -69,7 +69,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer, { if(obj instanceof ExtendsWildcardType) { - return this.extendsType.equals(((ExtendsWildcardType)obj).get_ExtendsType()); + return super.equals(obj); } else { diff --git a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java index 289154cc3..fdeadd182 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java @@ -56,22 +56,6 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I return new SuperWildcardType(getOffset(), superType.clone()); } - /** - * Author: Arne Lüdtke
- * Vergleicht mit einem anderen Objekt. - * @param obj - Object to compare. - */ - public boolean equals(Object obj) - { - if(obj instanceof SuperWildcardType) - { - return this.superType.equals(((SuperWildcardType)obj).get_SuperType()); - } - else - { - return false; - } - } /** * Author: Arne Lüdtke
@@ -129,4 +113,21 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I return new JavaCodeResult("? super " + this.superType.printJavaCode(result)); } + /** + * Author: Arne Lüdtke
+ * Vergleicht mit einem anderen Objekt. + * @param obj - Object to compare. + */ + public boolean equals(Object obj) + { + if(obj instanceof SuperWildcardType) + { + return super.equals(obj); + } + else + { + return false; + } + } + } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java index 56312b900..f8d07f9a8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java @@ -42,24 +42,6 @@ public class WildcardType extends Type{ return new WildcardType(this.getParent(), getOffset()); } - /** - * Author: Arne Lüdtke
- * Vergleicht mit einem anderen Objekt. - * @param obj - Object to compare. - */ - public boolean equals(Object obj) - { - //Luar 06-11-29 If Block erstellt, falls weitere Einschränkungen notwendig werden. - if(obj instanceof WildcardType && !(obj instanceof SuperWildcardType || obj instanceof ExtendsWildcardType)) - { - return true; - } - else - { - return false; - } - } - /** * Author: Arne Lüdtke
* Gibt die passende FreshWildcardType Klasse zurück. @@ -93,4 +75,18 @@ public class WildcardType extends Type{ public JavaCodeResult printJavaCode(ResultSet resultSet) { throw new NotImplementedException(); } + + public boolean equals(Object obj) + { + if(obj instanceof WildcardType) + { + return ((WildcardType)obj).GetWildcardType().equals(this.GetWildcardType()); + } + else + { + return false; + } + } + + } From b44584bc7e36128fc740b8300e900f5e416bd8a1 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sun, 4 Jan 2015 19:34:23 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Tests=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/plugindevelopment/TypeInsertTests/OL.jav | 16 ++++++++++++++++ .../plugindevelopment/TypeInsertTests/OL.java | 17 +++++++++++++++++ .../TypeInsertTests/OverloadingExample.jav | 13 +++++++++++++ .../TypeInsertTests/OverloadingExample.java | 16 ++++++++++++++++ .../TypeInsertTests/OverloadingRecursive.jav | 8 ++++++++ .../TypeInsertTests/OverloadingRecursive.java | 18 ++++++++++++++++++ .../WildcardTestForLambda2.jav | 5 +++++ .../WildcardTestForLambda2.java | 19 +++++++++++++++++++ 8 files changed, 112 insertions(+) create mode 100755 test/plugindevelopment/TypeInsertTests/OL.jav create mode 100644 test/plugindevelopment/TypeInsertTests/OL.java create mode 100644 test/plugindevelopment/TypeInsertTests/OverloadingExample.jav create mode 100644 test/plugindevelopment/TypeInsertTests/OverloadingExample.java create mode 100644 test/plugindevelopment/TypeInsertTests/OverloadingRecursive.jav create mode 100644 test/plugindevelopment/TypeInsertTests/OverloadingRecursive.java create mode 100644 test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.jav create mode 100644 test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.java diff --git a/test/plugindevelopment/TypeInsertTests/OL.jav b/test/plugindevelopment/TypeInsertTests/OL.jav new file mode 100755 index 000000000..66e95aeb3 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OL.jav @@ -0,0 +1,16 @@ +class OL { + + Integer m(Integer x) { return x + x; } + + Boolean m(Boolean x) {return x || x; } +} + +class Main { + + main(x) { + ol; + ol = new OL(); + return ol.m(x); + } + +} diff --git a/test/plugindevelopment/TypeInsertTests/OL.java b/test/plugindevelopment/TypeInsertTests/OL.java new file mode 100644 index 000000000..4e50e1741 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OL.java @@ -0,0 +1,17 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class OL { + private static final String TEST_FILE = "OL.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Integer main"); + mustContain.add("Boolean main"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingExample.jav b/test/plugindevelopment/TypeInsertTests/OverloadingExample.jav new file mode 100644 index 000000000..5ac198d8b --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OverloadingExample.jav @@ -0,0 +1,13 @@ +class Example { + test(){ + variable1; + variable2; + variable1 = this; + variable2 = variable1.intValue(); + return variable1.intValue(); + } + + int intValue(){ + return 1; + } +} diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingExample.java b/test/plugindevelopment/TypeInsertTests/OverloadingExample.java new file mode 100644 index 000000000..45088fd7e --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OverloadingExample.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class OverloadingExample { + private static final String TEST_FILE = "OverloadingExample.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Example variable"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingRecursive.jav b/test/plugindevelopment/TypeInsertTests/OverloadingRecursive.jav new file mode 100644 index 000000000..70829c746 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OverloadingRecursive.jav @@ -0,0 +1,8 @@ +class OverloadingRecursive{ + + + m (f) { + f.apply(f); + } +} + diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingRecursive.java b/test/plugindevelopment/TypeInsertTests/OverloadingRecursive.java new file mode 100644 index 000000000..6c394ab42 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OverloadingRecursive.java @@ -0,0 +1,18 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class OverloadingRecursive { + + private static final String TEST_FILE = "OverloadingRecursive.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + + //mustContain.add("Fun0>> op"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.jav b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.jav new file mode 100644 index 000000000..adae1646d --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.jav @@ -0,0 +1,5 @@ +class LambdaTest{ + +op = (f) -> f.apply(this); + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.java b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.java new file mode 100644 index 000000000..c302fbdb1 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/WildcardTestForLambda2.java @@ -0,0 +1,19 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class WildcardTestForLambda2 { + + private static final String TEST_FILE = "WildcardTestForLambda2.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + + //mustContain.add("Fun0>> op"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +}