Skip to content

Commit

Permalink
Merge pull request #20576 from evanchooly/noSuchMethod
Browse files Browse the repository at this point in the history
Fix panache operation bytecode generation for Kotlin Hibernate Panache
  • Loading branch information
evanchooly authored Oct 12, 2021
2 parents deb9fe5 + 968a22b commit 939d253
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.ParameterizedType;
import org.jboss.jandex.Type;
import org.jboss.jandex.Type.Kind;
import org.jboss.jandex.TypeVariable;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
Expand All @@ -55,7 +56,7 @@
import io.quarkus.panache.common.deployment.TypeBundle;

/**
* kotlinc compiles default methods in to the implementing classes so we need to elide them first and then we can
* kotlinc compiles default methods in to the implementing classes, so we need to elide them first, and then we can
* generate new methods like we do elsewhere.
*/
public class KotlinPanacheClassOperationGenerationVisitor extends ClassVisitor {
Expand Down Expand Up @@ -199,7 +200,7 @@ protected String bridgeMethodDescriptor(MethodInfo method, Function<String, Stri
} else {
returnType = getDescriptor(method.returnType(), mapper);
}
return joiner.toString() + returnType;
return joiner + returnType;
}

private void checkCast(MethodVisitor mv, Type returnType, String operationReturnType) {
Expand Down Expand Up @@ -314,11 +315,6 @@ private void filterNonOverrides() {
AnnotationInstance generateBridge = method.annotation(DOTNAME_GENERATE_BRIDGE);
if (generateBridge != null) {
definedMethods.remove(method.name() + getDescriptor(method, m -> m));
AnnotationValue typeErased = generateBridge.value("targetReturnTypeErased");
if (typeErased != null && typeErased.asBoolean()) {
definedMethods.remove(method.name()
+ bridgeMethodDescriptor(method, type -> type));
}
}
});
}
Expand Down Expand Up @@ -430,7 +426,9 @@ private void invokeOperation(MethodVisitor mv, MethodInfo method) {

StringJoiner joiner = new StringJoiner("", "(", ")");
joiner.add(CLASS.descriptor());
descriptors(method, joiner);
for (Type parameter : method.parameters()) {
joiner.add(parameter.kind() == Kind.TYPE_VARIABLE ? OBJECT.descriptor() : getDescriptor(parameter, argMapper));
}

Type returnType = method.returnType();
String descriptor = getDescriptor(returnType, argMapper);
Expand Down Expand Up @@ -548,27 +546,24 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str
public void visitEnd() {
for (MethodInfo method : indexView.getClassByName(baseType.dotName()).methods()) {
String descriptor = getDescriptor(method, type -> typeArguments.getOrDefault(type, OBJECT).descriptor());
if (!definedMethods.containsKey(method.name() + descriptor)) {
AnnotationInstance bridge = method.annotation(DOTNAME_GENERATE_BRIDGE);
if (bridge != null) {

generate(method);
if (needsJvmBridge(method)) {
String bridgeDescriptor = bridgeMethodDescriptor(method, type -> {
ByteCodeType mapped = typeArguments.get(type);
return mapped != null ? mapped.descriptor() : type;
});
if (!definedMethods.containsKey(method.name() + bridgeDescriptor)) {
generateBridge(method, bridgeDescriptor);
}
AnnotationInstance bridge = method.annotation(DOTNAME_GENERATE_BRIDGE);
if (!definedMethods.containsKey(method.name() + descriptor) && bridge != null) {
generate(method);
if (needsJvmBridge(method)) {
String bridgeDescriptor = bridgeMethodDescriptor(method, type -> {
ByteCodeType mapped = typeArguments.get(type);
return mapped != null ? mapped.descriptor() : type;
});
if (!definedMethods.containsKey(method.name() + bridgeDescriptor)) {
generateBridge(method, bridgeDescriptor);
}

AnnotationValue targetReturnTypeErased = bridge.value("targetReturnTypeErased");
if (typeArguments.get("Id").isPrimitive() && targetReturnTypeErased != null
&& targetReturnTypeErased.asBoolean()) {
if (method.parameters().size() == 1
&& method.parameters().get(0).asTypeVariable().identifier().equals("Id")) {
generatePrimitiveBridge(method, descriptor);
}
AnnotationValue targetReturnTypeErased = bridge.value("targetReturnTypeErased");
if (typeArguments.get("Id").isPrimitive() && targetReturnTypeErased != null
&& targetReturnTypeErased.asBoolean()) {
if (method.parameters().size() == 1
&& method.parameters().get(0).asTypeVariable().identifier().equals("Id")) {
generatePrimitiveBridge(method, descriptor);
}
}
}
Expand Down

0 comments on commit 939d253

Please sign in to comment.