From bb5945898a0bd490000f8a96089ade4edf61569b Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 13 Mar 2018 01:57:21 +0100 Subject: [PATCH 1/5] Bug in ASTFactory beseitigen --- pom.xml | 6 ++++ .../syntaxtree/factory/ASTFactory.java | 36 ++++++++++++------- test/javFiles/Vector.jav | 6 +--- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index ea7be6b3..1b97e501 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,12 @@ asm-all [4.0.0,) + diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index fa930f58..c438bc67 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -89,14 +89,21 @@ public class ASTFactory { return new Field(field.getName(), createType(field.getType(), jreClass, null), field.getModifiers(), new NullToken()); } + //private static RefType createType(Class classType) { + // return createClass(classType).getType(); + //} + private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) { String name = constructor.getName(); RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass, new JavaClassName(inClass.getName()), name); Parameter[] jreParams = constructor.getParameters(); + Type[] jreGenericParams = constructor.getGenericParameterTypes(); List params = new ArrayList<>(); - for(Parameter jreParam : jreParams){ - RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam.getType(),new JavaClassName(inClass.getName()), name); - params.add(new FormalParameter(jreParam.getName(),paramType, new NullToken())); + int i = 0; + for(Type jreParam : jreGenericParams){ + RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name); + params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken())); + i++; } ParameterList parameterList = new ParameterList(params, new NullToken()); Block block = new Block(new ArrayList(), new NullToken()); @@ -109,21 +116,26 @@ public class ASTFactory { } return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset, new ArrayList<>()); - } - - //private static RefType createType(Class classType) { - // return createClass(classType).getType(); - //} + } public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){ String name = jreMethod.getName(); RefTypeOrTPHOrWildcardOrGeneric returnType; - returnType = createType(jreMethod.getReturnType(),new JavaClassName(inClass.getName()), name); + Type jreRetType; + if(jreMethod.getGenericReturnType()!=null){ + jreRetType = jreMethod.getGenericReturnType(); + }else{ + jreRetType = jreMethod.getReturnType(); + } + returnType = createType(jreRetType,new JavaClassName(inClass.getName()), name); Parameter[] jreParams = jreMethod.getParameters(); + Type[] jreGenericParams = jreMethod.getGenericParameterTypes(); List params = new ArrayList<>(); - for(Parameter jreParam : jreParams){ - RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam.getType(),new JavaClassName(inClass.getName()), name); - params.add(new FormalParameter(jreParam.getName(),paramType, new NullToken())); + int i = 0; + for(Type jreParam : jreGenericParams){ + RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name); + params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken())); + i++; } ParameterList parameterList = new ParameterList(params, new NullToken()); Block block = new Block(new ArrayList(), new NullToken()); diff --git a/test/javFiles/Vector.jav b/test/javFiles/Vector.jav index ef3533a6..40072fe4 100644 --- a/test/javFiles/Vector.jav +++ b/test/javFiles/Vector.jav @@ -3,10 +3,6 @@ import java.util.Vector; class MyVector{ id(x){ - return id2(x); -} - -id2(x){ -return id(x); + return (x.elementAt(0)); } } \ No newline at end of file From 7a9c0a1e69df380e14075f54c6688e7e3390bafc Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 11:09:29 +0100 Subject: [PATCH 2/5] LambdaRunnableTest fix --- test/javFiles/LambdaRunnable.jav | 3 +++ test/visualisation/ToString.java | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 test/visualisation/ToString.java diff --git a/test/javFiles/LambdaRunnable.jav b/test/javFiles/LambdaRunnable.jav index 982680c3..37924ea2 100644 --- a/test/javFiles/LambdaRunnable.jav +++ b/test/javFiles/LambdaRunnable.jav @@ -1,3 +1,6 @@ +import java.lang.Runnable; +import java.lang.String; +import java.lang.System; public class LamRunnable{ diff --git a/test/visualisation/ToString.java b/test/visualisation/ToString.java new file mode 100644 index 00000000..00b8ddea --- /dev/null +++ b/test/visualisation/ToString.java @@ -0,0 +1,5 @@ +package visualisation; + +public class ToString { + +} From e1f579664a367978b10566465c3999afc87323c8 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 11:12:06 +0100 Subject: [PATCH 3/5] Fix Generics in MethodCall --- src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 8d87218d..0cadc085 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -349,7 +349,7 @@ public class TYPEStmt implements StatementVisitor{ */ methodConstraint.add(new Pair(forMethod.receiver.getType(), assumption.getReceiverType(resolver), PairOperator.SMALLERDOT)); - methodConstraint.add(new Pair(assumption.getReturnType(), forMethod.getType(), + methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver)); return methodConstraint; @@ -442,7 +442,7 @@ public class TYPEStmt implements StatementVisitor{ protected Constraint generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption, TypeInferenceBlockInformation info, GenericsResolver resolver){ Constraint methodConstraint = new Constraint(); - methodConstraint.add(new Pair(assumption.getReturnType(), forConstructor.getType(), + methodConstraint.add(new Pair(assumption.getReturnType(resolver), forConstructor.getType(), PairOperator.SMALLERDOT)); methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver)); return methodConstraint; From 77be216ee51a78bd83bee581ec00247e0742dd9d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 11:15:59 +0100 Subject: [PATCH 4/5] Fix --- .../typeinference/assumptions/FieldAssumption.java | 5 +++-- .../typeinference/assumptions/MethodAssumption.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java index 62867a26..e039dcbe 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.assumptions; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.TypeScope; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -25,7 +26,7 @@ public class FieldAssumption extends Assumption{ } public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) { - - return null; + //TODO + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index 4656318c..e17281e5 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -37,7 +37,8 @@ public class MethodAssumption extends Assumption{ return receiver; } - public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) { + if(retType instanceof GenericRefType)return resolver.resolve(retType); return retType; } From a71e56ea9793f9ffb05d99b9b8a7c159e6053a2d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 11:15:59 +0100 Subject: [PATCH 5/5] Fix --- .../typeinference/assumptions/FieldAssumption.java | 5 +++-- .../typeinference/assumptions/MethodAssumption.java | 3 ++- src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java | 2 +- test/typeinference/JavaTXCompilerTest.java | 4 ++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java index 62867a26..e039dcbe 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.assumptions; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.TypeScope; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -25,7 +26,7 @@ public class FieldAssumption extends Assumption{ } public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) { - - return null; + //TODO + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index 4656318c..e17281e5 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -37,7 +37,8 @@ public class MethodAssumption extends Assumption{ return receiver; } - public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) { + if(retType instanceof GenericRefType)return resolver.resolve(retType); return retType; } diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 0cadc085..19f212bf 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -393,7 +393,7 @@ public class TYPEStmt implements StatementVisitor{ for(Method m : cl.getMethods()){ if(m.getName().equals(name) && m.getParameterList().getFormalparalist().size() == numArgs){ - RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getReturnType()); + RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType()); ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info), createTypeScope(cl, m))); diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 87551476..3ba22bc6 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -49,6 +49,10 @@ public class JavaTXCompilerTest { execute(new File(rootDirectory+"Generics.jav")); } @Test + public void genericsMethodCall() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"MethodCallGenerics.jav")); + } + @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); }