diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 5978aaf26..eeff2a45b 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -71,6 +71,9 @@ public class JavaTXCompiler { public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); private final DirectoryClassLoader classLoader; + private Map, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>(); + + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile), null); } @@ -127,7 +130,9 @@ public class JavaTXCompiler { allClasses.addAll(sf.getClasses()); } allClasses.addAll(importedClasses); - return new TYPE(sourceFiles.values(), allClasses).getConstraints(); + TYPE ty = new TYPE(sourceFiles.values(), allClasses); + methCallargTypesRetType = ty.getMethCallargTypesRetType(); + return ty.getConstraints(); } void addMethods(SourceFile sf, ClassOrInterface cl, List importedClasses, ClassOrInterface objectClass) { @@ -725,6 +730,7 @@ public class JavaTXCompiler { unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks); System.out.println("RESULT Final: " + li.getResults()); + System.out.println("Constraints for Generated Generics: " + methCallargTypesRetType); logFile.write("RES_FINAL: " + li.getResults().toString() + "\n"); logFile.flush(); return li.getResults(); @@ -753,6 +759,7 @@ public class JavaTXCompiler { return x; // wenn nichts veraendert wurde wird x zurueckgegeben }).collect(Collectors.toCollection(HashSet::new)); System.out.println("RESULT Final: " + results); + System.out.println("Constraints for Generated Generics: " + methCallargTypesRetType); logFile.write("RES_FINAL: " + results.toString() + "\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index 6ebb9404b..a402ea53b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -10,10 +10,6 @@ public class Constraint extends HashSet { private static final long serialVersionUID = 1L; private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt - /* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt - * es Probleme beim Generated Generics - */ - public boolean isStatement = false; private Constraint extendConstraint = null; @@ -47,7 +43,7 @@ public class Constraint extends HashSet { } public String toString() { - return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement + return super.toString() + "\nisInherited = " + isInherited //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) + "\n" ; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 685ac9f62..05b0050a5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.statement.Statement; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; @@ -14,6 +15,8 @@ public class TYPE { private final Collection sfs; private final TypeInferenceInformation typeInferenceInformation; + + private Map, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>(); public TYPE(Collection sourceFiles, Collection allAvailableClasses){ sfs = sourceFiles; @@ -21,6 +24,10 @@ public class TYPE { } + public Map, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() { + return methCallargTypesRetType; + } + public ConstraintSet getConstraints() { ConstraintSet ret = new ConstraintSet(); for(SourceFile sf : sfs) @@ -72,6 +79,7 @@ public class TYPE { TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m); TYPEStmt methodScope = new TYPEStmt(blockInfo); m.block.accept(methodScope); + methCallargTypesRetType.putAll(methodScope.getMethCallargTypesRetType()); return methodScope.getConstraints(); } @@ -81,6 +89,7 @@ public class TYPE { //for(Statement stmt : m.fieldInitializations)stmt.accept(methodScope); ConstraintSet ret = this.getConstraintsMethod(m, info, currentClass); ret.addAll(methodScope.getConstraints()); + methCallargTypesRetType.putAll(methodScope.getMethCallargTypesRetType()); return ret; } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index ddc2dc923..eb6f5b755 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -30,6 +30,9 @@ public class TYPEStmt implements StatementVisitor{ private final TypeInferenceBlockInformation info; private final ConstraintSet constraintsSet = new ConstraintSet(); + + + Map, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>(); public TYPEStmt(TypeInferenceBlockInformation info){ this.info = info; @@ -38,6 +41,10 @@ public class TYPEStmt implements StatementVisitor{ public ConstraintSet getConstraints() { return constraintsSet; } + + public Map, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() { + return methCallargTypesRetType; + } /** * Erstellt einen neuen GenericResolver @@ -166,6 +173,14 @@ public class TYPEStmt implements StatementVisitor{ //Es wird in OderConstraints davon ausgegangen dass die Bedingungen für die Typen der Argumente links stehen //und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler) public void visit(MethodCall methodCall) { + Map, RefTypeOrTPHOrWildcardOrGeneric> argTypesRetType = new HashMap<>(); + argTypesRetType.put(methodCall.getArgumentList() + .getArguments() + .stream() + .map(x -> x.getType()) + .collect(Collectors.toCollection(HashSet::new)), + methodCall.getType()); + methCallargTypesRetType.put(methodCall.name, argTypesRetType); methodCall.receiver.accept(this); //Overloading: Set> methodConstraints = new HashSet<>(); @@ -181,7 +196,6 @@ public class TYPEStmt implements StatementVisitor{ ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : x) .collect(Collectors.toCollection(() -> new Constraint(oneMethodConstraint.isInherited()))); - extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement; oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint); @@ -598,7 +612,6 @@ public class TYPEStmt implements StatementVisitor{ //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE - methodConstraint.isStatement = forMethod.getStatement(); methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));