Fix overloading considering too many options, fix #348
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 44s
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 44s
This commit is contained in:
parent
fc22299af5
commit
e1e744152a
@ -34,6 +34,8 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
protected List<Generics> all;
|
protected List<Generics> all;
|
||||||
public Generics generics;
|
public Generics generics;
|
||||||
|
public List<Generics> currentMethodOverloads;
|
||||||
|
|
||||||
final Map<ClassOrInterface, Set<GenericTypeVar>> userDefinedGenerics = new HashMap<>();
|
final Map<ClassOrInterface, Set<GenericTypeVar>> userDefinedGenerics = new HashMap<>();
|
||||||
final Map<Method, Set<SignaturePair>> tphsInMethods = new HashMap<>();
|
final Map<Method, Set<SignaturePair>> tphsInMethods = new HashMap<>();
|
||||||
private Method currentMethod;
|
private Method currentMethod;
|
||||||
@ -354,11 +356,16 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
record MethodWithTphs(TargetMethod method, List<SignaturePairTarget> args) {}
|
record MethodWithTphs(TargetMethod method, List<SignaturePairTarget> args) {}
|
||||||
|
|
||||||
|
record Signature(TargetMethod.Signature java, TargetMethod.Signature tx, Generics generics) {}
|
||||||
|
|
||||||
private List<MethodWithTphs> convert(ClassOrInterface currentClass, Method method) {
|
private List<MethodWithTphs> convert(ClassOrInterface currentClass, Method method) {
|
||||||
generics = all.getFirst();
|
generics = all.getFirst();
|
||||||
List<MethodWithTphs> result = new ArrayList<>();
|
List<MethodWithTphs> result = new ArrayList<>();
|
||||||
this.currentMethod = method;
|
this.currentMethod = method;
|
||||||
|
|
||||||
|
List<Signature> signatures = new ArrayList<>();
|
||||||
|
HashMap<TargetMethod.Signature, List<Generics>> collectedGenerics = new HashMap<>();
|
||||||
|
|
||||||
for (var s : all) {
|
for (var s : all) {
|
||||||
generics = s;
|
generics = s;
|
||||||
var javaGenerics = this.generics.javaGenerics.generics(currentClass, method);
|
var javaGenerics = this.generics.javaGenerics.generics(currentClass, method);
|
||||||
@ -382,8 +389,19 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
|
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
|
||||||
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), this.generics.txGenerics));
|
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), this.generics.txGenerics));
|
||||||
var newMethod = new TargetMethod(method.modifier, method.name, convert(method.block), javaSignature, txSignature);
|
|
||||||
|
|
||||||
|
signatures.add(new Signature(javaSignature, txSignature, generics));
|
||||||
|
System.out.println(javaSignature);
|
||||||
|
var listOfGenerics = collectedGenerics.getOrDefault(javaSignature, new ArrayList<>());
|
||||||
|
listOfGenerics.add(generics);
|
||||||
|
collectedGenerics.put(javaSignature, listOfGenerics);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var signature : signatures) {
|
||||||
|
generics = signature.generics;
|
||||||
|
currentMethodOverloads = collectedGenerics.get(signature.java);
|
||||||
|
|
||||||
|
var newMethod = new TargetMethod(method.modifier, method.name, convert(method.block), signature.java, signature.tx);
|
||||||
var concreteParams = tphsInMethods.getOrDefault(method, new HashSet<>()).stream().map(sig -> new SignaturePairTarget(convert(sig.signature), convert(sig.parameter))).toList();
|
var concreteParams = tphsInMethods.getOrDefault(method, new HashSet<>()).stream().map(sig -> new SignaturePairTarget(convert(sig.signature), convert(sig.parameter))).toList();
|
||||||
|
|
||||||
result.add(new MethodWithTphs(newMethod, concreteParams));
|
result.add(new MethodWithTphs(newMethod, concreteParams));
|
||||||
|
@ -451,7 +451,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
var oldGenerics = converter.generics;
|
var oldGenerics = converter.generics;
|
||||||
|
|
||||||
// Set the generics to matching result set
|
// Set the generics to matching result set
|
||||||
for (var generics : converter.all) {
|
for (var generics : converter.currentMethodOverloads) {
|
||||||
var java = generics.javaGenerics();
|
var java = generics.javaGenerics();
|
||||||
var equals = true;
|
var equals = true;
|
||||||
for (var pair : l) {
|
for (var pair : l) {
|
||||||
|
@ -863,13 +863,13 @@ public class TestComplete {
|
|||||||
var rctor = R.getDeclaredConstructor(Number.class);
|
var rctor = R.getDeclaredConstructor(Number.class);
|
||||||
|
|
||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
var m = clazz.getDeclaredMethod("m", R);
|
var m = clazz.getDeclaredMethod("m", R, Integer.class);
|
||||||
|
|
||||||
var x = rctor.newInstance(10);
|
var x = rctor.newInstance(10);
|
||||||
var d = rctor.newInstance(20.0);
|
var d = rctor.newInstance(20.0);
|
||||||
|
|
||||||
assertEquals(m.invoke(instance, x), 50);
|
assertEquals(m.invoke(instance, x, 0), 50);
|
||||||
assertEquals(m.invoke(instance, d), 40.0);
|
assertEquals(m.invoke(instance, d, 0), 40.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user