From b31da889023fb6f1617451d8d7b20e825238694d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 25 Sep 2017 01:14:02 +0200 Subject: [PATCH] =?UTF-8?q?Logik=20f=C3=BCr=20Generics=20implementieren.?= =?UTF-8?q?=20Unvollst=C3=A4ndig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/ClassOrInterface.java | 8 +- src/de/dhbwstuttgart/syntaxtree/Field.java | 17 ++- src/de/dhbwstuttgart/syntaxtree/Method.java | 2 +- .../typeinference/assumptions/Assumption.java | 15 +++ .../assumptions/FieldAssumption.java | 6 +- .../assumptions/MethodAssumption.java | 8 +- .../TypeInferenceBlockInformation.java | 24 ---- .../assumptions/TypeInferenceInformation.java | 2 +- .../assumptions/TypeScopeContainer.java | 32 ++++++ .../constraints/ConstraintsFactory.java | 35 ++++-- .../constraints/GenericsResolver.java | 12 ++ .../typeinference/typeAlgo/TYPEStmt.java | 106 +++++++++++++----- test/javFiles/Generics.jav | 1 - 13 files changed, 195 insertions(+), 73 deletions(-) create mode 100644 src/de/dhbwstuttgart/typeinference/assumptions/Assumption.java create mode 100644 src/de/dhbwstuttgart/typeinference/assumptions/TypeScopeContainer.java create mode 100644 src/de/dhbwstuttgart/typeinference/constraints/GenericsResolver.java diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index f377e820..4dd9081d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree; import de.dhbwstuttgart.core.IItemWithOffset; +import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -17,7 +18,7 @@ import java.util.List; /** * Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces */ -public class ClassOrInterface extends SyntaxTreeNode { +public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ protected int modifiers; protected JavaClassName name; private List fields = new ArrayList<>(); @@ -81,6 +82,11 @@ public class ClassOrInterface extends SyntaxTreeNode { return this.genericClassParameters; } + @Override + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + return null; + } + public List getConstructors() { return constructors; } diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index 82c3053f..421f0ff3 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -3,13 +3,12 @@ package de.dhbwstuttgart.syntaxtree; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import org.antlr.v4.runtime.Token; -public class Field extends SyntaxTreeNode{ +import java.util.ArrayList; + +public class Field extends SyntaxTreeNode implements TypeScope{ private String name; private RefTypeOrTPHOrWildcardOrGeneric type; - - - private GenericDeclarationList genericParameters; public Field(String name, RefTypeOrTPHOrWildcardOrGeneric type, int modifier, Token offset){ super(offset); @@ -29,5 +28,15 @@ public class Field extends SyntaxTreeNode{ public void accept(ASTVisitor visitor) { visitor.visit(this); } + + @Override + public Iterable getGenerics() { + return new ArrayList<>(); + } + + @Override + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + return type; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 67d81cb4..9e81605d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -22,7 +22,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Block; * @author janulrich * */ -public class Method extends Field implements IItemWithOffset, TypeScope +public class Method extends Field implements IItemWithOffset { public final Block block; private ParameterList parameterlist = new ParameterList(new ArrayList<>(), new NullToken()); diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/Assumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/Assumption.java new file mode 100644 index 00000000..2435f58b --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/assumptions/Assumption.java @@ -0,0 +1,15 @@ +package de.dhbwstuttgart.typeinference.assumptions; + +import de.dhbwstuttgart.syntaxtree.TypeScope; + +public class Assumption { + private final TypeScope typeScope; + + public Assumption(TypeScope typeScope) { + this.typeScope = typeScope; + } + + public TypeScope getTypeScope() { + return typeScope; + } +} diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java index d0a278a5..88b2bd4a 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/FieldAssumption.java @@ -1,13 +1,15 @@ package de.dhbwstuttgart.typeinference.assumptions; +import de.dhbwstuttgart.syntaxtree.TypeScope; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; -public class FieldAssumption { +public class FieldAssumption extends Assumption{ private RefTypeOrTPHOrWildcardOrGeneric receiverType; private RefTypeOrTPHOrWildcardOrGeneric type; public FieldAssumption(RefTypeOrTPHOrWildcardOrGeneric receiverType, - RefTypeOrTPHOrWildcardOrGeneric type){ + RefTypeOrTPHOrWildcardOrGeneric type, TypeScope scope){ + super(scope); this.type = type; this.receiverType = receiverType; } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index c878a85e..bbeff0d7 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -1,18 +1,22 @@ package de.dhbwstuttgart.typeinference.assumptions; import de.dhbwstuttgart.syntaxtree.ParameterList; +import de.dhbwstuttgart.syntaxtree.TypeScope; +import de.dhbwstuttgart.syntaxtree.statement.Assign; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import java.util.List; import java.util.stream.Collectors; -public class MethodAssumption { +public class MethodAssumption extends Assumption{ private RefType receiver; private RefTypeOrTPHOrWildcardOrGeneric retType; List params; - public MethodAssumption(RefType receiver, RefTypeOrTPHOrWildcardOrGeneric retType, List params){ + public MethodAssumption(RefType receiver, RefTypeOrTPHOrWildcardOrGeneric retType, + List params, TypeScope scope){ + super(scope); this.receiver = receiver; this.retType = retType; this.params = params; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java index b0d459df..54fe9bb5 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java @@ -33,28 +33,4 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation { public TypeScope getCurrentTypeScope() { return methodContext; } - - private class TypeScopeContainer implements TypeScope{ - ArrayList scopes = new ArrayList<>(); - Stack types = new Stack<>(); - public TypeScopeContainer(TypeScope scope1, TypeScope scope2){ - scopes.add(scope1); - scopes.add(scope2); - types.push(scope1.getReturnType()); - types.push(scope2.getReturnType()); - } - public void add(TypeScope scope){ - } - - @Override - public Iterable getGenerics() { - return Iterables.concat(scopes.stream(). - map(TypeScope::getGenerics).collect(Collectors.toList()).toArray(new Iterable[0])); - } - - @Override - public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { - return types.peek(); - } - } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceInformation.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceInformation.java index fe1c0cc9..017732a7 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceInformation.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceInformation.java @@ -45,7 +45,7 @@ public class TypeInferenceInformation { for(ClassOrInterface cl : classes){ for(Field m : cl.getFieldDecl()){ if(m.getName().equals(name)){ - ret.add(new FieldAssumption(cl.getType(), checkGTV(m.getType()))); + ret.add(new FieldAssumption(cl.getType(), checkGTV(m.getType()), new TypeScopeContainer(cl, m))); } } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeScopeContainer.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeScopeContainer.java new file mode 100644 index 00000000..c315fb52 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeScopeContainer.java @@ -0,0 +1,32 @@ +package de.dhbwstuttgart.typeinference.assumptions; + +import com.google.common.collect.Iterables; +import de.dhbwstuttgart.syntaxtree.GenericTypeVar; +import de.dhbwstuttgart.syntaxtree.TypeScope; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; + +import java.util.ArrayList; +import java.util.Stack; +import java.util.stream.Collectors; + +public class TypeScopeContainer implements TypeScope { + ArrayList scopes = new ArrayList<>(); + Stack types = new Stack<>(); + public TypeScopeContainer(TypeScope scope1, TypeScope scope2){ + scopes.add(scope1); + scopes.add(scope2); + types.push(scope1.getReturnType()); + types.push(scope2.getReturnType()); + } + + @Override + public Iterable getGenerics() { + return Iterables.concat(scopes.stream(). + map(TypeScope::getGenerics).collect(Collectors.toList()).toArray(new Iterable[0])); + } + + @Override + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + return types.peek(); + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java index 8ef71e7f..b299d57c 100644 --- a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java +++ b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java @@ -1,6 +1,8 @@ package de.dhbwstuttgart.typeinference.constraints; +import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; +import de.dhbwstuttgart.syntaxtree.TypeScope; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -9,27 +11,44 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class ConstraintsFactory { - public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2, PairOperator equalsdot, TypeInferenceBlockInformation info){ - //Check whether Generics are in the same class: - return new Pair(checkGeneric(t1, info), checkGeneric(t2, info), equalsdot); + + public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2, + PairOperator equalsdot, TypeScope currentScope, TypeScope additionalScope, + GenericsResolver resolver){ + //Check whether Generics are in the same class and resolve all other generics: + return new Pair(checkGeneric(t1, currentScope, additionalScope,resolver), + checkGeneric(t2, currentScope,additionalScope, resolver), equalsdot); } public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1, - RefTypeOrTPHOrWildcardOrGeneric t2, TypeInferenceBlockInformation info){ - return createPair(t1,t2,PairOperator.SMALLERDOT, info); + RefTypeOrTPHOrWildcardOrGeneric t2, TypeScope currentScope, TypeScope additionalScope, + GenericsResolver resolver){ + return createPair(t1,t2,PairOperator.SMALLERDOT, currentScope, additionalScope, resolver); } - private static RefTypeOrTPHOrWildcardOrGeneric checkGeneric(RefTypeOrTPHOrWildcardOrGeneric type, TypeInferenceBlockInformation info){ + private static RefTypeOrTPHOrWildcardOrGeneric checkGeneric(RefTypeOrTPHOrWildcardOrGeneric type, + TypeScope currentScope, TypeScope additionalScope, + GenericsResolver resolver){ if(type instanceof GenericRefType){ - for(GenericTypeVar genericTypeVar : info.getCurrentTypeScope().getGenerics()){ + //TODO: Für Generics müssen auch noch Constraints generiert werden + for(GenericTypeVar genericTypeVar : currentScope.getGenerics()){ if(genericTypeVar.getName().equals(((GenericRefType)type).getName())){ return new RefType(((GenericRefType)type).getName(),type.getOffset()); } } //Nicht in den Generics in diesem Kontext enthalten: - TypePlaceholder ret = TypePlaceholder.fresh(type.getOffset()); + TypePlaceholder ret = null; + for(GenericTypeVar genericTypeVar : additionalScope.getGenerics()){ + if(genericTypeVar.getName().equals(((GenericRefType)type).getName())){ + ret = resolver.resolve(genericTypeVar); + } + } + if(ret == null) + throw new DebugException("Der Generic " + ((GenericRefType) type).getName() + " kommt in keine TypeScope vor!"); return ret; }else{ return type; diff --git a/src/de/dhbwstuttgart/typeinference/constraints/GenericsResolver.java b/src/de/dhbwstuttgart/typeinference/constraints/GenericsResolver.java new file mode 100644 index 00000000..d72b6835 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/constraints/GenericsResolver.java @@ -0,0 +1,12 @@ +package de.dhbwstuttgart.typeinference.constraints; + +import de.dhbwstuttgart.syntaxtree.GenericTypeVar; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; + +/** + * Wird für Generics benötigt + * TODO: Erklörung! + */ +public interface GenericsResolver { + public TypePlaceholder resolve(GenericTypeVar generic); +} diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 73842ac9..79b6a503 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; +import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericsRegistry; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; @@ -17,16 +18,10 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; -import de.dhbwstuttgart.typeinference.constraints.Constraint; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory; -import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.constraints.*; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; public class TYPEStmt implements StatementVisitor{ @@ -42,6 +37,20 @@ public class TYPEStmt implements StatementVisitor{ return constraintsSet; } + private static GenericsResolver getResolverInstance(){ + Map map = new HashMap<>(); + return generic -> { + if(map.containsKey(generic))return map.get(generic); + TypePlaceholder ret = TypePlaceholder.fresh(generic.getOffset()); + map.put(generic, ret); + return ret; + }; + } + + private static TypeScope createTypeScope(ClassOrInterface cl, Method method) { + return null; + } + @Override public void visit(ArgumentList arglist) { for(int i = 0;i oderConstraints = new HashSet<>(); for(FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)){ Constraint constraint = new Constraint(); + GenericsResolver resolver = getResolverInstance(); constraint.add(ConstraintsFactory.createPair( - fieldVar.receiver.getType(),fieldAssumption.getReceiverType(), info)); + fieldVar.receiver.getType(),fieldAssumption.getReceiverType(), info.getCurrentTypeScope(), fieldAssumption.getTypeScope(), resolver)); constraint.add(ConstraintsFactory.createPair( - fieldVar.getType(),fieldAssumption.getType(), info)); + fieldVar.getType(),fieldAssumption.getType(), info.getCurrentTypeScope(), fieldAssumption.getTypeScope(), resolver)); oderConstraints.add(constraint); } if(oderConstraints.size() == 0) @@ -146,7 +156,9 @@ public class TYPEStmt implements StatementVisitor{ //Overloading: Set methodConstraints = new HashSet<>(); for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){ - methodConstraints.add(generateConstraint(methodCall, m, info)); + GenericsResolver resolver = getResolverInstance(); + TypeScope additionalScope = m.getTypeScope(); + methodConstraints.add(generateConstraint(methodCall, m, info, getResolverInstance())); } if(methodConstraints.size()<1){ throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset()); @@ -159,7 +171,7 @@ public class TYPEStmt implements StatementVisitor{ //Overloading: Set methodConstraints = new HashSet<>(); for(MethodAssumption m : this.getConstructors(info, (RefType) methodCall.getType(), methodCall.getArgumentList())){ - methodConstraints.add(generateConstructorConstraint(methodCall, m, info)); + methodConstraints.add(generateConstructorConstraint(methodCall, m, info, getResolverInstance())); } if(methodConstraints.size()<1){ throw new TypeinferenceException("Konstruktor in Klasse "+methodCall.getType().toString()+" ist nicht vorhanden!",methodCall.getOffset()); @@ -181,7 +193,8 @@ public class TYPEStmt implements StatementVisitor{ public void visit(Return returnExpr) { returnExpr.retexpr.accept(this); constraintsSet.addUndConstraint(ConstraintsFactory.createPair( - returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT, info)); + returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT, + info.getCurrentTypeScope(), createNullTypeScope(), getResolverInstance())); } @Override @@ -201,7 +214,23 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(This aThis) { - constraintsSet.addUndConstraint(ConstraintsFactory.createPair( aThis.getType(), info.getCurrentClass().getType(), PairOperator.EQUALSDOT, info)); + constraintsSet.addUndConstraint(ConstraintsFactory.createPair( + aThis.getType(), info.getCurrentClass().getType(), PairOperator.EQUALSDOT, info.getCurrentTypeScope(), + createNullTypeScope(), getResolverInstance())); + } + + private static TypeScope createNullTypeScope() { + return new TypeScope() { + @Override + public Iterable getGenerics() { + return null; + } + + @Override + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + return null; + } + }; } @Override @@ -249,20 +278,24 @@ public class TYPEStmt implements StatementVisitor{ METHOD CALL Section: */ - protected Constraint generateConstraint(MethodCall forMethod, MethodAssumption assumption, TypeInferenceBlockInformation info){ + protected Constraint generateConstraint(MethodCall forMethod, MethodAssumption assumption, + TypeInferenceBlockInformation info, GenericsResolver resolver){ Constraint methodConstraint = new Constraint(); - methodConstraint.add(ConstraintsFactory.createPair(forMethod.receiver.getType(), assumption.getReceiverType(), PairOperator.SMALLERDOT, info)); - methodConstraint.add(ConstraintsFactory.createPair(assumption.getReturnType(), forMethod.getType(), PairOperator.EQUALSDOT, info)); - methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info)); + methodConstraint.add(ConstraintsFactory.createPair(forMethod.receiver.getType(), assumption.getReceiverType(), + PairOperator.SMALLERDOT, info.getCurrentTypeScope(), assumption.getTypeScope(), resolver)); + methodConstraint.add(ConstraintsFactory.createPair(assumption.getReturnType(), forMethod.getType(), + PairOperator.EQUALSDOT, info.getCurrentTypeScope(), assumption.getTypeScope(), resolver)); + methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver)); return methodConstraint; } - protected Set generateParameterConstraints(MethodCall foMethod, MethodAssumption assumption, TypeInferenceBlockInformation info) { + protected Set generateParameterConstraints(MethodCall foMethod, MethodAssumption assumption, + TypeInferenceBlockInformation info, GenericsResolver resolver) { Set ret = new HashSet<>(); for(int i = 0;i getGenerics() { + throw new NotImplementedException(); + } + + @Override + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { + throw new NotImplementedException(); + } + })); } for(ClassOrInterface cl : info.getAvailableClasses()){ for(Method m : cl.getMethods()){ @@ -283,7 +327,8 @@ public class TYPEStmt implements StatementVisitor{ m.getParameterList().getFormalparalist().size() == numArgs){ RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getType()); - ret.add(new MethodAssumption(cl.getType(), retType, convertParams(m.getParameterList(),info))); + ret.add(new MethodAssumption(cl.getType(), retType, convertParams(m.getParameterList(),info), + createTypeScope(cl, m))); } } } @@ -317,7 +362,8 @@ public class TYPEStmt implements StatementVisitor{ if(cl.getClassName().equals(ofType.getName())){ for(Method m : cl.getConstructors()){ if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){ - ret.add(new MethodAssumption(cl.getType(), ofType, convertParams(m.getParameterList(), info))); + ret.add(new MethodAssumption(cl.getType(), ofType, convertParams(m.getParameterList(), + info), createTypeScope(cl, m))); } } } @@ -325,10 +371,12 @@ public class TYPEStmt implements StatementVisitor{ return ret; } - protected Constraint generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption, TypeInferenceBlockInformation info){ + protected Constraint generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption, + TypeInferenceBlockInformation info, GenericsResolver resolver){ Constraint methodConstraint = new Constraint(); - methodConstraint.add(ConstraintsFactory.createPair(assumption.getReturnType(), forConstructor.getType(), PairOperator.SMALLERDOT, info)); - methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info)); + methodConstraint.add(ConstraintsFactory.createPair(assumption.getReturnType(), forConstructor.getType(), + PairOperator.SMALLERDOT, info.getCurrentTypeScope(), assumption.getTypeScope(), resolver)); + methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver)); return methodConstraint; } diff --git a/test/javFiles/Generics.jav b/test/javFiles/Generics.jav index c49f5dfb..958025e6 100644 --- a/test/javFiles/Generics.jav +++ b/test/javFiles/Generics.jav @@ -17,5 +17,4 @@ auto test = new List(); auto test2 = new List(); ... //code, welcher möglicherweise test und test2 vertauscht test.add("hallo"); - */ \ No newline at end of file