Use family instead of generated generics

This commit is contained in:
Daniel Holle 2023-04-28 17:15:04 +02:00
parent 8fb4f062ec
commit b0cbac529e

View File

@ -245,7 +245,7 @@ public class ASTToTargetAST {
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
if (optMethod.isEmpty()) return;
var method = optMethod.get();
var generics = generics(owner, method);
var generics = family(owner, method);
// transitive and
var all = transitiveClosure(generics);
@ -293,7 +293,6 @@ public class ASTToTargetAST {
}
}
@Override
public void visit(LambdaExpression lambdaExpression) {
superType = new Void(new NullToken());
@ -355,6 +354,8 @@ public class ASTToTargetAST {
}
});
System.out.println(method.getName() + " " + result);
var closure = transitiveClosure((Set) simplifiedConstraints);
// Type variables with bounds that are also type variables of the class
for (var typeVariable : new HashSet<>(typeVariables)) {
@ -454,26 +455,39 @@ public class ASTToTargetAST {
abstract void generics(ClassOrInterface owner, Method method, Set<ResultPair<?,?>> result, HashSet<TypePlaceholder> javaTypeVariablesOfClass);
Set<ResultPair<?, ?>> generics(ClassOrInterface owner, Method method) {
if (computedGenericsOfMethods.containsKey(method))
return computedGenericsOfMethods.get(method);
Set<ResultPair<?, ?>> result = new HashSet<>();
computedGenericsOfMethods.put(method, result);
Set<ResultPair<?, ?>> family(ClassOrInterface owner, Method method) {
var result = new HashSet<ResultPair<?, ?>>();
var classGenerics = generics(owner);
HashSet<TypePlaceholder> javaTypeVariables = new HashSet<>();
HashSet<TypePlaceholder> typeVariablesOfClass = new HashSet<>();
for (var pair : classGenerics) {
typeVariablesOfClass.add((TypePlaceholder) pair.getLeft());
}
HashSet<TypePlaceholder> javaTypeVariables = new HashSet<>();
methodFindTypeVariables(method, javaTypeVariables);
methodFindConstraints(owner, method, javaTypeVariables, typeVariablesOfClass, result);
eliminateTransitives(result);
return result;
}
Set<ResultPair<?, ?>> generics(ClassOrInterface owner, Method method) {
if (computedGenericsOfMethods.containsKey(method))
return computedGenericsOfMethods.get(method);
var classGenerics = generics(owner);
HashSet<TypePlaceholder> typeVariablesOfClass = new HashSet<>();
for (var pair : classGenerics) {
typeVariablesOfClass.add((TypePlaceholder) pair.getLeft());
}
var result = family(owner, method);
computedGenericsOfMethods.put(method, result);
var referenced = new HashSet<TypePlaceholder>();
generics(owner, method, result, referenced);