Added "remap" arg to let reobf processing be skipped per-member basis

This commit is contained in:
Mumfrey committed 2015-01-05 16:11:17 +00:00
1 parent 3b3a16db75
commit fb64777a41
6 files changed
+74 -9

No files matched your search

@@ -141,6 +141,11 @@ class AnnotatedMixin {
*/
private final String classRef;
/**
* True if we will actually process remappings for this mixin
*/
private final boolean remap;
/**
* Stored (ordered) field mappings
*/
@@ -152,13 +157,16 @@ class AnnotatedMixin {
private final Set<String> methodMappings = new LinkedHashSet<String>();
public AnnotatedMixin(AnnotatedMixins mixins, TypeElement type) {
AnnotationMirror annotation = MirrorUtils.getAnnotation(type, Mixin.class);
this.mixins = mixins;
this.mixin = type;
this.classRef = type.getQualifiedName().toString().replace('.', '/');
this.remap = AnnotatedMixins.getRemapValue(annotation);
String targetRef = null;
TypeElement targetType = null;
List<AnnotationValue> targetList = MirrorUtils.<List<AnnotationValue>>getAnnotationValue(type, Mixin.class);
List<AnnotationValue> targetList = MirrorUtils.<List<AnnotationValue>>getAnnotationValue(annotation);
for (TypeMirror target : MirrorUtils.<TypeMirror>unfold(targetList)) {
Element element = ((DeclaredType)target).asElement();
String targetName = ((TypeElement)element).getQualifiedName().toString();
@@ -187,6 +195,13 @@ class AnnotatedMixin {
return this.targets;
}
/**
* Get whether to remap annotations in this mixin
*/
public boolean remap() {
return this.remap;
}
/**
* Get stored field mappings
*/
@@ -245,7 +245,10 @@ class AnnotatedMixins {
"Found @Shadow annotation on a non-mixin field " + field + " in " + mixinType);
return;
}
mixinClass.registerShadow(field, shadow);
if (this.shouldRemap(mixinClass, shadow)) {
mixinClass.registerShadow(field, shadow);
}
}
/**
@@ -262,7 +265,10 @@ class AnnotatedMixins {
"Found @Shadow annotation on a non-mixin method " + method + " in " + mixinType);
return;
}
mixinClass.registerShadow(method, shadow);
if (this.shouldRemap(mixinClass, shadow)) {
mixinClass.registerShadow(method, shadow);
}
}
/**
@@ -279,14 +285,28 @@ class AnnotatedMixins {
"Found @Inject annotation on a non-mixin method " + method + " in " + mixinType);
return;
}
mixinClass.registerInjector(method, inject);
List<AnnotationMirror> annotationValue = MirrorUtils.<List<AnnotationMirror>>getAnnotationValue(inject, "at");
for (AnnotationMirror at : annotationValue) {
mixinClass.registerInjectionPoint(at);
if (this.shouldRemap(mixinClass, inject)) {
mixinClass.registerInjector(method, inject);
List<AnnotationMirror> annotationValue = MirrorUtils.<List<AnnotationMirror>>getAnnotationValue(inject, "at");
for (AnnotationMirror at : annotationValue) {
mixinClass.registerInjectionPoint(at);
}
}
}
private boolean shouldRemap(AnnotatedMixin mixinClass, AnnotationMirror annotation) {
return mixinClass.remap() && AnnotatedMixins.getRemapValue(annotation);
}
/**
* Check whether we should remap the annotated member or skip it
*/
public static boolean getRemapValue(AnnotationMirror annotation) {
return MirrorUtils.<Boolean>getAnnotationValue(annotation, "remap", Boolean.TRUE).booleanValue();
}
/**
* Print a message to the AP messager
*/
@@ -45,4 +45,15 @@ public @interface Mixin {
* Priority for the mixin, relative to other mixins targetting the same classes
*/
public int priority() default 1000;
/**
* By default, the annotation processor will attempt to locate an obfuscation mapping for all {@link Shadow} and
* {@link org.spongepowered.asm.mixin.injection.Inject} annotated members since it is anticipated that in general the target of a {@link Mixin}
* will be an obfuscated class and all annotated members will need to be added to the obfuscation table. However since it is possible to also
* apply mixins to non-obfuscated targets it may be desirable to suppress the compiler warnings which would otherwise be generated. This can be
* done on an individual member basis by setting <code>remap</code> to <em>false</em> on the individual annotations, or disabled for the entire
* mixin by setting the value here to <em>false</em>. Doing so will cause the annotation processor to skip all annotations in this mixin when
* building the obfuscation table.
*/
public boolean remap() default true;
}
@@ -65,4 +65,12 @@ public @interface Shadow {
*/
public String prefix() default "shadow$";
/**
* By default, the annotation processor will attempt to locate an obfuscation mapping for all {@link Shadow} methods since it is anticipated that
* in general the target of a {@link Shadow} annotation will be an obfuscated field or method in the target class. However since it is possible
* to also apply mixins to non-obfuscated targets (or non-obfuscated methods in obfuscated targets, such as methods added by Forge) it may be
* desirable to suppress the compiler warning which would otherwise be generated. Setting this value to <em>false</em> will cause the annotation
* processor to skip this annotation when attempting to build the obfuscation table for the mixin.
*/
public boolean remap() default true;
}
@@ -58,4 +58,14 @@ public @interface Inject {
* Set to true to allow local variables to be captured from the target method as well as method parameters.
*/
// public boolean captureLocals() default false;
/**
* By default, the annotation processor will attempt to locate an obfuscation mapping for all {@link Inject} methods since it is anticipated that
* in general the target of a {@link Inject} annotation will be an obfuscated method in the target class. However since it is possible to also
* apply mixins to non-obfuscated targets (or non-obfuscated methods in obfuscated targets, such as methods added by Forge) it may be necessary
* to suppress the compiler error which would otherwise be generated. Setting this value to <em>false</em> will cause the annotation processor
* to skip this annotation when attempting to build the obfuscation table for the mixin.
*/
public boolean remap() default true;
}
@@ -118,7 +118,8 @@ public abstract class InjectionPoint {
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
boolean found = false;
@SuppressWarnings("unchecked") ArrayList<AbstractInsnNode>[] allNodes = new ArrayList[this.components.length];
@SuppressWarnings({ "unchecked", "rawtypes" })
ArrayList<AbstractInsnNode>[] allNodes = new ArrayList[this.components.length];
for (int i = 0; i < this.components.length; i++) {
allNodes[i] = new ArrayList<AbstractInsnNode>();