Consider constructors when creating class generics

This commit is contained in:
Daniel Holle 2023-07-04 12:17:14 +02:00
parent b04201de42
commit 5c62191f3b
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.target.generate; package de.dhbwstuttgart.target.generate;
import com.google.common.collect.Streams;
import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.Constructor;
@ -18,6 +19,8 @@ import de.dhbwstuttgart.util.Pair;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public abstract class GenerateGenerics { public abstract class GenerateGenerics {
@ -145,6 +148,7 @@ public abstract class GenerateGenerics {
} else if (constraint instanceof PairTPHEqualTPH p) { } else if (constraint instanceof PairTPHEqualTPH p) {
equality.put(p.getLeft(), p.getRight()); equality.put(p.getLeft(), p.getRight());
} else if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) { } else if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) {
System.out.println(p.left + " = " + p.right);
concreteTypes.put(new TPH(p.left), p.right); concreteTypes.put(new TPH(p.left), p.right);
} }
} }
@ -761,14 +765,14 @@ public abstract class GenerateGenerics {
oldFamily.clear(); oldFamily.clear();
oldFamily.putAll(familyOfMethods); oldFamily.putAll(familyOfMethods);
familyOfMethods.clear(); familyOfMethods.clear();
for (var method : classOrInterface.getMethods()) { Stream.concat(classOrInterface.getMethods().stream(), classOrInterface.getConstructors().stream()).forEach(method -> {
family(classOrInterface, method); family(classOrInterface, method);
} });
} while(!oldFamily.equals(familyOfMethods)); } while(!oldFamily.equals(familyOfMethods));
for (var method : classOrInterface.getMethods()) { Stream.concat(classOrInterface.getMethods().stream(), classOrInterface.getConstructors().stream()).forEach(method -> {
generics(classOrInterface, method); generics(classOrInterface, method);
} });
} }
private void findChain(Set<TPH> referenced, Set<Pair> input, Set<Pair> output, TPH start, TPH end, Set<TPH> chain) { private void findChain(Set<TPH> referenced, Set<Pair> input, Set<Pair> output, TPH start, TPH end, Set<TPH> chain) {