ClassRemapper doesn't remap annotation values
I am remapping method names using a custom remapper class like this:
ClassNode updated = new ClassNode();
node.accept(new ClassRemapper(updated, new MyRemapper(...)));
MyRemapper
overrides mapMethodName
and therefore should update all references to a certain method. My sample class which is run through the ClassRemapper
:
public class AnnotationRemapTest {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public static @interface Description {
String desc() default "an unknown method";
}
@Description(desc = "the entry point method")
public static void main(String[] args) throws Exception {
Description d = (Description) AnnotationRemapTest.class.getDeclaredMethod("main", String[].class).getAnnotations()[0];
System.out.println("this method is: " + d.desc());
}
}
Everything works great, except that @Description(desc = "the entry point method")
is not updated. In my eyes it is missing a call to mapMethodName to update the annotation value name, which corresponds to its method name inside the annotation class.
Output after remapping:
public class AnnotationRemapTest {
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.METHOD })
public static @interface A {
public String n() default "an unknown method";
}
@A(desc = "the entry point method") // "desc" is left as "desc", while it should be updated to "n"
public static void main(String[] args) throws Exception {
A d = (A) AnnotationRemapTest.class.getDeclaredMethod("main", String[].class).getAnnotations()[0];
System.out.println("this method is: " + d.n());
}
}
In short: AnnotationRemapper
is missing calls to mapMethodName
to update annotation value names.