mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Call visitAnnotableParameterCount (#1376)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user