First implementation of generating a bridge method
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 45s
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 45s
This commit is contained in:
parent
e2bf09548f
commit
bb11d24101
@ -332,6 +332,39 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
// Generate dispatch method
|
||||
var firstParam = firstMethod.signature().parameters().get(0);
|
||||
var cases = new ArrayList<TargetSwitch.Case>();
|
||||
TargetExpression expr = new TargetLocalVar(firstParam.pattern().type(), firstParam.pattern().name());
|
||||
|
||||
var classType = new TargetRefType(clazz.getClassName().getClassName());
|
||||
|
||||
for (var method : res) {
|
||||
TargetExpression caseBody = new TargetMethodCall(
|
||||
method.signature().returnType(),
|
||||
new TargetThis(classType),
|
||||
List.of(expr),
|
||||
classType,
|
||||
method.name(),
|
||||
false, false, method.isPrivate()
|
||||
);
|
||||
|
||||
if (method.signature().returnType() != null) {
|
||||
caseBody = new TargetReturn(caseBody);
|
||||
}
|
||||
var body = new TargetBlock(List.of(caseBody));
|
||||
var case_ = new TargetSwitch.Case(List.of(method.signature().parameters().getFirst().pattern()), body);
|
||||
|
||||
cases.add(case_);
|
||||
}
|
||||
|
||||
var stmt = new TargetSwitch(expr, cases, null);
|
||||
var block = new TargetBlock(List.of(stmt));
|
||||
|
||||
var parameters = List.of(new MethodParameter(firstParam.pattern().type(), firstParam.pattern().name()));
|
||||
var signature = new TargetMethod.Signature(firstMethod.signature().generics(), parameters, firstMethod.signature().returnType());
|
||||
var bridgeMethod = new TargetMethod(firstMethod.access(), firstMethod.name(), block, signature, firstMethod.txSignature());
|
||||
|
||||
res.add(bridgeMethod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,10 @@ public record TargetMethod(int access, String name, TargetBlock block, Signature
|
||||
return (access & Opcodes.ACC_STATIC) != 0;
|
||||
}
|
||||
|
||||
public boolean isPrivate() {
|
||||
return (access & Opcodes.ACC_PRIVATE) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof TargetMethod otherMethod)) return false;
|
||||
|
Loading…
Reference in New Issue
Block a user