forked from JavaTX/JavaCompilerCore
modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/Method.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java Pairs sammeln rueckgaengig gemacht
This commit is contained in:
parent
f2d6dae4c7
commit
bbdf220324
@ -9,7 +9,6 @@ import java.util.HashSet;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
@ -25,18 +24,8 @@ import de.dhbwstuttgart.syntaxtree.Field;
|
|||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
@ -52,32 +41,12 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
public class TPHExtractor extends AbstractASTWalker {
|
public class TPHExtractor extends AbstractASTWalker {
|
||||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
|
|
||||||
/*
|
|
||||||
* ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu
|
|
||||||
*/
|
|
||||||
public HashMap<String, Method> nameToMeth;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ordnet den Fieldnamen ihre jeweiligen Lambda-respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu
|
|
||||||
*/
|
|
||||||
public HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> nameToField;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ordnet den Variablennamen ihre jeweiligen Lambda-Respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu
|
|
||||||
* wird in jeder Methode neu initialisiert
|
|
||||||
* Einträge werden nicht geloescht, da das Java-Programm korrekt ist und in umgebenden Bloecken nicht die gleichen Variablen vorkommen können
|
|
||||||
*/
|
|
||||||
public HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> nameToLocalVar;
|
|
||||||
|
|
||||||
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
||||||
public final List<String> tphsClass = new ArrayList<>();
|
public final List<String> tphsClass = new ArrayList<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
|
|
||||||
Boolean inMethod = false;
|
Boolean inMethod = false;
|
||||||
boolean inLocalOrParamOrReturn = false;
|
boolean inLocalOrParamOrReturn = false;
|
||||||
Boolean inLambdaExpression = false;
|
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||||
@ -215,9 +184,8 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
this.nameToLocalVar = new HashMap<>();
|
|
||||||
String id = MethodUtility.createID(resolver,method);
|
String id = MethodUtility.createID(resolver,method);
|
||||||
methodAndTph = new MethodAndTPH(id, method.getReturnType());
|
methodAndTph = new MethodAndTPH(id);
|
||||||
|
|
||||||
inLocalOrParamOrReturn = true;
|
inLocalOrParamOrReturn = true;
|
||||||
method.getReturnType().accept(this);
|
method.getReturnType().accept(this);
|
||||||
@ -231,152 +199,23 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
ListOfMethodsAndTph.add(methodAndTph);
|
ListOfMethodsAndTph.add(methodAndTph);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
|
||||||
Optional<Constructor> optInitialConstructor = classOrInterface.getfieldInitializations();
|
|
||||||
this.nameToField = new HashMap<>();
|
|
||||||
if (optInitialConstructor.isPresent()) {
|
|
||||||
classOrInterface.getfieldInitializations()
|
|
||||||
.get()
|
|
||||||
.block
|
|
||||||
.statements
|
|
||||||
.stream()
|
|
||||||
.filter(s -> s instanceof Assign && ((Assign)s).rightSide instanceof LambdaExpression)
|
|
||||||
.forEach(as ->
|
|
||||||
this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName,
|
|
||||||
((AssignToField)(((Assign)as).lefSide)).getType())) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nameToMeth = new HashMap<>();
|
|
||||||
for(Method m : classOrInterface.getMethods()) {
|
|
||||||
this.nameToMeth.put(m.getName(), m);
|
|
||||||
}
|
|
||||||
super.visit(classOrInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Constructor cons) {
|
public void visit(Constructor cons) {
|
||||||
this.nameToLocalVar = new HashMap<>();
|
|
||||||
inMethod = false;
|
inMethod = false;
|
||||||
//super.visit(cons);
|
//super.visit(cons);
|
||||||
|
|
||||||
cons.getParameterList().accept(this);
|
cons.getParameterList().accept(this);
|
||||||
if(cons.block != null)
|
if(cons.block != null)
|
||||||
cons.block.accept(this);
|
cons.block.accept(this);
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
|
||||||
inLambdaExpression = true;
|
|
||||||
lambdaExpression.params.getFormalparalist().forEach(param -> {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(param.getType()).resolvedType;
|
|
||||||
if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) {
|
|
||||||
this.nameToLocalVar.put(param.getName(), param.getType());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
super.visit(lambdaExpression);
|
|
||||||
inLambdaExpression = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Assign assign) {
|
|
||||||
super.visit(assign);
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType;
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType;
|
|
||||||
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
|
||||||
if (right instanceof TypePlaceholder) {
|
|
||||||
methodAndTph.addPair(allPairs.stream().filter(
|
|
||||||
p -> (p.getLeft() instanceof TypePlaceholder &&
|
|
||||||
p.getRight() instanceof TypePlaceholder) &&
|
|
||||||
((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) &&
|
|
||||||
((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName())
|
|
||||||
).findFirst()
|
|
||||||
.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
// inLocalOrParamOrReturn = inMethod;
|
// inLocalOrParamOrReturn = inMethod;
|
||||||
super.visit(localVarDecl);
|
super.visit(localVarDecl);
|
||||||
RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(localVarDecl.getType()).resolvedType;
|
|
||||||
if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) {
|
|
||||||
this.nameToLocalVar.put(localVarDecl.getName(), localVarDecl.getType());
|
|
||||||
}
|
|
||||||
// inLocalOrParamOrReturn = false;
|
// inLocalOrParamOrReturn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(MethodCall methodCall) {
|
|
||||||
String fieldLocalvarOrMethName;
|
|
||||||
super.visit(methodCall);
|
|
||||||
if (nameToMeth.keySet().contains(fieldLocalvarOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile
|
|
||||||
|| (methodCall.name.equals("apply") &&
|
|
||||||
(methodCall.receiver instanceof ExpressionReceiver) &&
|
|
||||||
((((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) &&
|
|
||||||
nameToField.keySet().contains(fieldLocalvarOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName)
|
|
||||||
|| (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) &&
|
|
||||||
nameToLocalVar.keySet().contains(fieldLocalvarOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name)
|
|
||||||
)
|
|
||||||
//LOKALE VARIABLEN MUESSE NOCH IN nameToField EINGETRAGEN WERDEN
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt =
|
|
||||||
methodCall.name.equals("apply")
|
|
||||||
? (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar)
|
|
||||||
? ((RefType)(resultSet.resolveType((nameToField.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator()
|
|
||||||
: ((RefType)(resultSet.resolveType((nameToLocalVar.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator()
|
|
||||||
: nameToMeth.get(fieldLocalvarOrMethName)
|
|
||||||
.getParameterList()
|
|
||||||
.getFormalparalist()
|
|
||||||
.stream()
|
|
||||||
.map(p -> p.getType())
|
|
||||||
.iterator();
|
|
||||||
methodCall.getArgumentList()
|
|
||||||
.getArguments()
|
|
||||||
.forEach(x -> {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType;
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType;
|
|
||||||
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
|
||||||
if (right instanceof TypePlaceholder) {
|
|
||||||
methodAndTph.addPair(allPairs.stream().filter(
|
|
||||||
p -> (p.getLeft() instanceof TypePlaceholder &&
|
|
||||||
p.getRight() instanceof TypePlaceholder) &&
|
|
||||||
((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) &&
|
|
||||||
((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName())
|
|
||||||
).findFirst()
|
|
||||||
.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Return aReturn) {
|
|
||||||
super.visit(aReturn);
|
|
||||||
if (!inLambdaExpression) {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType;
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType;
|
|
||||||
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
|
||||||
if (right instanceof TypePlaceholder) {
|
|
||||||
methodAndTph.addPair(allPairs.stream().filter(
|
|
||||||
p -> (p.getLeft() instanceof TypePlaceholder &&
|
|
||||||
p.getRight() instanceof TypePlaceholder) &&
|
|
||||||
((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) &&
|
|
||||||
((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName())
|
|
||||||
).findFirst()
|
|
||||||
.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVar localVar) {
|
public void visit(LocalVar localVar) {
|
||||||
// inLocalOrParamOrReturn = inMethod;
|
// inLocalOrParamOrReturn = inMethod;
|
||||||
|
@ -66,7 +66,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GeneratedGenericsFinder implements ASTVisitor {
|
public class GeneratedGenericsFinder implements ASTVisitor {
|
||||||
private final TPHExtractor tphExtractor;
|
private final TPHExtractor tphExtractor = new TPHExtractor();
|
||||||
private Collection<ResultSet> listOfResultSets;
|
private Collection<ResultSet> listOfResultSets;
|
||||||
private SourceFile sf;
|
private SourceFile sf;
|
||||||
private List<String> tphsClass;
|
private List<String> tphsClass;
|
||||||
@ -86,7 +86,6 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
public GeneratedGenericsFinder(SourceFile sf, Collection<ResultSet> listOfResultSets) {
|
public GeneratedGenericsFinder(SourceFile sf, Collection<ResultSet> listOfResultSets) {
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
this.tphExtractor = new TPHExtractor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericGenratorResultForSourceFile findGeneratedGenerics() {
|
public GenericGenratorResultForSourceFile findGeneratedGenerics() {
|
||||||
|
@ -4,14 +4,10 @@ import de.dhbwstuttgart.bytecode.TPHExtractor;
|
|||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
public class FamilyOfGeneratedGenerics {
|
public class FamilyOfGeneratedGenerics {
|
||||||
@ -19,7 +15,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
|
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
|
||||||
public HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
|
public HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
|
||||||
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
||||||
//public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
||||||
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
||||||
|
|
||||||
private static final String objectType = Type.getInternalName(Object.class);
|
private static final String objectType = Type.getInternalName(Object.class);
|
||||||
@ -28,7 +24,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
this.allConstraints = tphExtractor.allCons;
|
this.allConstraints = tphExtractor.allCons;
|
||||||
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
||||||
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
||||||
//this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, null, tphExtractor.ListOfMethodsAndTph);
|
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
||||||
this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,20 +59,9 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return cs_cl;
|
return cs_cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs,
|
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
||||||
List<ClassConstraint> cs_cl,
|
|
||||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs,
|
|
||||||
ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> methodConstraints1Pairs,
|
|
||||||
List<MethodAndTPH> listOfMethodsAndTph) {
|
|
||||||
List<MethodConstraint> cs_m = new ArrayList<>();
|
List<MethodConstraint> cs_m = new ArrayList<>();
|
||||||
//List<MethodConstraint> methodConstraints1 =
|
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||||
typeOfTheMethodInClSigma(cs, posOfTphs);
|
|
||||||
|
|
||||||
List<MethodConstraint> methodConstraints1 =
|
|
||||||
methodConstraints1Pairs.stream()
|
|
||||||
.map(p -> new MethodConstraint(p.getLeft().getName(), p.getRight().getName(), Relation.EXTENDS))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
for (MethodConstraint cons: methodConstraints1) {
|
for (MethodConstraint cons: methodConstraints1) {
|
||||||
if (!checkForDuplicates(cons, cs_m)) {
|
if (!checkForDuplicates(cons, cs_m)) {
|
||||||
cs_m.add(cons);
|
cs_m.add(cons);
|
||||||
@ -137,7 +122,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod, method.getBasePairs(),listOfMethodsAndTph);
|
listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph);
|
||||||
tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod);
|
tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
@ -16,16 +15,9 @@ public class MethodAndTPH {
|
|||||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||||
// tphs of local variables and parameters
|
// tphs of local variables and parameters
|
||||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> basePairs = new ArrayList<>();
|
|
||||||
|
|
||||||
/*
|
public MethodAndTPH(String name) {
|
||||||
* Returntyp der zugehoerigen Methode in er abstrakten Syntax
|
|
||||||
*/
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
|
||||||
|
|
||||||
public MethodAndTPH(String name, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
|
||||||
this.id = name;
|
this.id = name;
|
||||||
this.returnType = returnType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getTphs() {
|
public ArrayList<String> getTphs() {
|
||||||
@ -47,16 +39,4 @@ public class MethodAndTPH {
|
|||||||
return localTphs;
|
return localTphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPair(ResultPair<TypePlaceholder, TypePlaceholder> p) {
|
|
||||||
basePairs.add(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
|
||||||
return returnType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> getBasePairs() {
|
|
||||||
return basePairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,6 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
public final Boolean isInherited;
|
public final Boolean isInherited;
|
||||||
|
|
||||||
/*
|
|
||||||
* its Constraints
|
|
||||||
* eingefuegt PL 2021-02-15
|
|
||||||
*/
|
|
||||||
public final ConstraintSet constraints = new ConstraintSet();
|
|
||||||
|
|
||||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||||
GenericDeclarationList gtvDeclarations, Token offset) {
|
GenericDeclarationList gtvDeclarations, Token offset) {
|
||||||
super(offset);
|
super(offset);
|
||||||
|
@ -46,12 +46,6 @@ public class SourceFile extends SyntaxTreeNode{
|
|||||||
return KlassenVektor;
|
return KlassenVektor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Method> getAllMethods() {
|
|
||||||
List<Method> ret = new ArrayList<>();
|
|
||||||
getClasses().forEach(cl -> ret.addAll(cl.getMethods()));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
|
@ -32,10 +32,8 @@ public class TYPE {
|
|||||||
|
|
||||||
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
ConstraintSet methConstrains;
|
|
||||||
for(Method m : cl.getMethods()){
|
for(Method m : cl.getMethods()){
|
||||||
ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
|
ret.addAll(getConstraintsMethod(m,info, cl));
|
||||||
m.constraints.addAll(methConstrains);
|
|
||||||
}
|
}
|
||||||
for(Constructor m : cl.getConstructors()){
|
for(Constructor m : cl.getConstructors()){
|
||||||
ret.addAll(getConstraintsConstructor(m,info, cl));
|
ret.addAll(getConstraintsConstructor(m,info, cl));
|
||||||
|
Loading…
Reference in New Issue
Block a user