Call visitAnnotableParameterCount (#1376)

This commit is contained in:
Joseph Burton
2025-09-30 13:38:13 +01:00
committed by GitHub
parent 312dcc7ca6
commit 7484a7fd95

View File

@@ -28,6 +28,7 @@ import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.RecordComponentVisitor;
import org.objectweb.asm.Type;
import org.objectweb.asm.TypePath;
@@ -240,8 +241,19 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement
}
return new MethodVisitor(Constants.ASM_VERSION, mv) {
int syntheticParameterCount = 0;
boolean visitedAnnotableParameterCount = false;
boolean hasAddedAnnotations = false;
@Override
public void visitParameter(String name, int access) {
if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
syntheticParameterCount++;
}
super.visitParameter(name, access);
}
@Override
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
if (methodData.annotationsToRemove().contains(Type.getType(descriptor).getInternalName())) {
@@ -271,6 +283,16 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement
return super.visitParameterAnnotation(parameter, descriptor, visible);
}
@Override
public void visitAnnotableParameterCount(int parameterCount, boolean visible) {
if (!visible && !methodData.parameters().isEmpty()) {
parameterCount = Math.max(parameterCount, Type.getArgumentCount(descriptor) - syntheticParameterCount);
visitedAnnotableParameterCount = true;
}
super.visitAnnotableParameterCount(parameterCount, visible);
}
@Override
public void visitCode() {
addMethodAnnotations();
@@ -306,6 +328,11 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement
}
}
if (!visitedAnnotableParameterCount && !methodData.parameters().isEmpty()) {
mv.visitAnnotableParameterCount(Type.getArgumentCount(descriptor) - syntheticParameterCount, false);
visitedAnnotableParameterCount = true;
}
methodData.parameters().forEach((paramIndex, paramData) -> {
for (AnnotationNode annotation : paramData.annotationsToAdd()) {
AnnotationVisitor av = mv.visitParameterAnnotation(paramIndex, annotation.desc, false);