From 506fd0dc0e1105a4487a340504524146fa656a9a Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 7 Mar 2023 16:34:34 +0100 Subject: [PATCH] new file: ../../AllgemeinTest/Assign.jav modified: ../../AllgemeinTest/Pair.jav modified: ../../AllgemeinTest/UseWildcardPair.jav modified: ../../../src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java ? extends Object nochmals angepasst modified: ../../../src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: ../../../src/test/java/AllgemeinTest.java --- resources/AllgemeinTest/Assign.jav | 10 +++++++++ resources/AllgemeinTest/Pair.jav | 22 ++++++++++++------- resources/AllgemeinTest/UseWildcardPair.jav | 2 +- .../SyntaxTreeGenerator/TypeGenerator.java | 2 +- .../typeinference/typeAlgo/TYPEStmt.java | 3 ++- src/test/java/AllgemeinTest.java | 3 ++- 6 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 resources/AllgemeinTest/Assign.jav diff --git a/resources/AllgemeinTest/Assign.jav b/resources/AllgemeinTest/Assign.jav new file mode 100644 index 00000000..001fca71 --- /dev/null +++ b/resources/AllgemeinTest/Assign.jav @@ -0,0 +1,10 @@ +class Assign { + + assign(x, y) { + x = y; + } + + assign2(x, y) { + assign(x,y); + } +} \ No newline at end of file diff --git a/resources/AllgemeinTest/Pair.jav b/resources/AllgemeinTest/Pair.jav index fc2de47c..b7c5e7a9 100644 --- a/resources/AllgemeinTest/Pair.jav +++ b/resources/AllgemeinTest/Pair.jav @@ -1,22 +1,28 @@ import java.util.Vector; import java.lang.Boolean; +import java.lang.Object; class Pair { U a; T b; make(x) { - var ret = new Pair<>(); - ret.a = x.elementAt(0); - ret.b = x.elementAt(1); - return ret; + var ret = new Pair<>(); + ret.a = x.elementAt(0); + ret.b = x.elementAt(1); + return ret; } - /* - compare(p) { - - return p.a = p.b; + + eq(a, b) { + b = a; + return a == b; } + compare( p) { + return eq(p.a, p.b); + //return p.a == p.b; + } +/* void m(Pair p, List b) { //this.compare(p); //1, type incorrect diff --git a/resources/AllgemeinTest/UseWildcardPair.jav b/resources/AllgemeinTest/UseWildcardPair.jav index 42c64816..dc91e4e0 100644 --- a/resources/AllgemeinTest/UseWildcardPair.jav +++ b/resources/AllgemeinTest/UseWildcardPair.jav @@ -6,7 +6,7 @@ class UseWildcardPair{ void m(Pair p, Vector b) { p.compare(p); //1, type incorrect - p.compare(p.make(b)); //2, OK + p.compare(p.make(b)); //2, OK } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index 4a577e90..c30dad85 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -170,7 +170,7 @@ public class TypeGenerator { return new SuperWildcardType(convert(wildcardContext.wildcardBounds().referenceType(), reg, generics), wildcardContext.getStart()); } }else{ - return new ExtendsWildcardType(new RefType(new JavaClassName("java.lang.Object"), new NullToken()), wildcardContext.getStart()); + return new ExtendsWildcardType(ASTFactory.createObjectType(), wildcardContext.getStart()); } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 198b0f4c..64f8976c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -171,7 +171,8 @@ public class TYPEStmt implements StatementVisitor{ methodCall.receiver.accept(this); //Overloading: Set> methodConstraints = new HashSet<>(); - for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){ + for(MethodAssumption m : + this.getMethods(methodCall.name, methodCall.arglist, info)){ GenericsResolver resolver = getResolverInstance(); Set> oneMethodConstraints = generateConstraint(methodCall, m, info, resolver); methodConstraints.addAll(oneMethodConstraints); diff --git a/src/test/java/AllgemeinTest.java b/src/test/java/AllgemeinTest.java index ad389c7a..db7ae185 100644 --- a/src/test/java/AllgemeinTest.java +++ b/src/test/java/AllgemeinTest.java @@ -52,8 +52,9 @@ public class AllgemeinTest { //String className = "VectorNotObject"; //String className = "WildcardCaptureConversionTest"; //String className = "CaptureConversion"; - String className = "Pair"; + //String className = "Pair"; //String className = "UseWildcardPair"; + String className = "Assign"; //PL 2019-10-24: genutzt fuer unterschiedliche Tests path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav"; //path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";