Fix not looking up the tph in equality

This commit is contained in:
Daniel Holle 2023-06-13 10:28:20 +02:00
parent 7556b9f590
commit fe2b3accb3

View File

@ -47,8 +47,9 @@ public class ASTToTargetAST {
}
@Override
void generics(ClassOrInterface owner, Method method, Set<ResultPair<?, ?>> result, HashSet<TypePlaceholder> referenced) {
void generics(ClassOrInterface owner, Method method, Set<ResultPair<?, ?>> result, Set<TypePlaceholder> referenced) {
eliminateInfima(result, referenced);
eliminateInnerTypeVariables(referenced, result);
}
@Override
@ -64,18 +65,19 @@ public class ASTToTargetAST {
}
@Override
void generics(ClassOrInterface owner, Method method, Set<ResultPair<?, ?>> result, HashSet<TypePlaceholder> referenced) {
void generics(ClassOrInterface owner, Method method, Set<ResultPair<?, ?>> result, Set<TypePlaceholder> referenced) {
eliminateCycles(result, referenced);
eliminateInfima(result, referenced);
equalizeTypeVariables(result, referenced);
eliminateInnerTypeVariables(referenced, result);
}
@Override
void generics(ClassOrInterface classOrInterface, Set<ResultPair<?, ?>> result, Set<TypePlaceholder> referenced) {
eliminateCycles(result, referenced);
eliminateInfima(result, referenced);
eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced);
equalizeTypeVariables(result, referenced);
eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced);
}
}
@ -172,7 +174,7 @@ public class ASTToTargetAST {
static Set<ResultPair<?, ?>> transitiveClosure(Set<ResultPair<?, ?>> generics) {
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
HashSet<ResultPair<?, ?>> toAdd = new HashSet<>();
Set<ResultPair<?, ?>> toAdd = new HashSet<>();
int sizeBefore;
do {
sizeBefore = all.size();
@ -221,7 +223,7 @@ public class ASTToTargetAST {
//Anfang es werden Paare von TPHs gespeichert, die bei den Generated Generics ueber die Methodengrenzen hinweg
//betrachtet werden muessen
//Definition 7.2 (Family of generated generics). T1 <. R1 <.^ R2 <. T2
Set<RefTypeOrTPHOrWildcardOrGeneric> T1s =
Set<TypePlaceholder> T1s =
methodCall.getArgumentList()
.getArguments()
.stream()
@ -230,10 +232,10 @@ public class ASTToTargetAST {
.stream().filter(x -> x instanceof TypePlaceholder)
.map(tph -> equality.getOrDefault(tph, (TypePlaceholder) tph))
.collect(Collectors.toCollection(HashSet::new));
RefTypeOrTPHOrWildcardOrGeneric T2 = superType;
if (T2 instanceof TypePlaceholder tph) T2 = equality.getOrDefault(tph, tph);
Set<TypePlaceholder> T2s = new HashSet<>();
findTphs(superType, T2s);
System.out.println("T1s: " + T1s + " T2: " + T2);
System.out.println("T1s: " + T1s + " T2s: " + T2s);
//Ende
superType = methodCall.receiverType;
@ -264,6 +266,7 @@ public class ASTToTargetAST {
// Loop from hell
outer:
for (var R1 : typeVariables) {
R1 = equality.getOrDefault(R1, R1);
if (typeVariablesOfClass.contains(R1)) continue;
for (var generic : all) if (generic instanceof PairTPHsmallerTPH ptph) {
var l = equality.getOrDefault(ptph.left, ptph.left);
@ -276,13 +279,17 @@ public class ASTToTargetAST {
continue;
for (var R2 : typeVariables) {
R2 = equality.getOrDefault(R2, R2);
for (var pair2 : simplifiedConstraints) {
var l3 = equality.getOrDefault(pair2.left, pair2.left);
var r3 = equality.getOrDefault(pair2.right, pair2.right);
if (!(r3.equals(R2) && l3.equals(r)))
continue;
if (R1.equals(R2)) continue;
if (!T1s.contains(R1) || !R2.equals(T2)) continue;
T2s = T2s.stream().map(tph -> equality.getOrDefault(tph, tph)).collect(Collectors.toSet());
T1s = T1s.stream().map(tph -> equality.getOrDefault(tph, tph)).collect(Collectors.toSet());
if (!T1s.contains(R1) || !T2s.contains(R2)) continue;
var newPair = new PairTPHsmallerTPH(R1, R2);
newPairs.add(newPair);
@ -466,7 +473,7 @@ public class ASTToTargetAST {
});
}
abstract void generics(ClassOrInterface owner, Method method, Set<ResultPair<?,?>> result, HashSet<TypePlaceholder> javaTypeVariablesOfClass);
abstract void generics(ClassOrInterface owner, Method method, Set<ResultPair<?,?>> result, Set<TypePlaceholder> javaTypeVariablesOfClass);
Set<ResultPair<?, ?>> family(ClassOrInterface owner, Method method) {
if (familyOfMethods.containsKey(method))
@ -492,8 +499,8 @@ public class ASTToTargetAST {
}
Set<ResultPair<?, ?>> generics(ClassOrInterface owner, Method method) {
//if (computedGenericsOfMethods.containsKey(method))
// return computedGenericsOfMethods.get(method);
if (computedGenericsOfMethods.containsKey(method))
return computedGenericsOfMethods.get(method);
var classGenerics = generics(owner);
@ -520,7 +527,6 @@ public class ASTToTargetAST {
generics(owner, method, result, referenced);
usedTPHsOfMethods.put(method, usedTphs);
eliminateInnerTypeVariables(referenced, result);
addMissingObjectBounds(result, classGenerics, usedTphs);
System.out.println(this.getClass().getSimpleName() + " " + method.name + ": " + result);