From 1752418584f8b558b931f5364a50166f94add13c Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Tue, 14 Feb 2017 15:47:42 +0000
Subject: [PATCH] Support remap annotation for accessors & respect remap
setting of mixin
---
.../tools/obfuscation/AnnotatedMixin.java | 96 ++++++-------
.../AnnotatedMixinElementHandlerAccessor.java | 79 ++++++-----
.../tools/obfuscation/AnnotatedMixins.java | 132 +++++++++---------
.../spongepowered/asm/mixin/gen/Accessor.java | 25 +++-
.../spongepowered/asm/mixin/gen/Invoker.java | 25 +++-
5 files changed, 202 insertions(+), 155 deletions(-)
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
index f727506c..b5908dd4 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
@@ -58,29 +58,29 @@ import org.spongepowered.tools.obfuscation.struct.InjectorRemap;
* Information about a mixin stored during processing
*/
class AnnotatedMixin {
-
+
/**
* Mixin annotation
*/
private final AnnotationHandle annotation;
-
+
/**
- * Messager
+ * Messager
*/
private final Messager messager;
-
+
/**
* Type handle provider
*/
private final ITypeHandleProvider typeProvider;
-
+
/**
* Manager
*/
private final IObfuscationManager obf;
-
+
/**
- * Generated mappings
+ * Generated mappings
*/
private final IMappingConsumer mappings;
@@ -88,7 +88,7 @@ class AnnotatedMixin {
* Mixin class
*/
private final TypeElement mixin;
-
+
/**
* Mixin class
*/
@@ -98,50 +98,50 @@ class AnnotatedMixin {
* Specified targets
*/
private final List targets = new ArrayList();
-
+
/**
- * Target type (for single-target mixins)
+ * Target type (for single-target mixins)
*/
private final TypeHandle primaryTarget;
-
+
/**
* Mixin class "reference" (bytecode name)
*/
private final String classRef;
-
+
/**
* True if we will actually process remappings for this mixin
*/
private final boolean remap;
-
+
/**
* True if the target class is allowed to not exist at compile time, we will
* simulate the target in order to do as much validation as is feasible.
- *
+ *
* Implies remap=false
*/
private final boolean virtual;
-
+
/**
* Overwrite handler
*/
private final AnnotatedMixinElementHandlerOverwrite overwrites;
-
+
/**
* Shadow handler
*/
private final AnnotatedMixinElementHandlerShadow shadows;
-
+
/**
* Injector handler
*/
private final AnnotatedMixinElementHandlerInjector injectors;
-
+
/**
- * Accessor handler
+ * Accessor handler
*/
private final AnnotatedMixinElementHandlerAccessor accessors;
-
+
/**
* Soft implementation handler;
*/
@@ -160,7 +160,7 @@ class AnnotatedMixin {
this.primaryTarget = this.initTargets();
// this.remap = !this.virtual && this.annotation.getBoolean("remap", true) && this.targets.size() > 0;
this.remap = this.annotation.getBoolean("remap", true) && this.targets.size() > 0;
-
+
this.overwrites = new AnnotatedMixinElementHandlerOverwrite(ap, this);
this.shadows = new AnnotatedMixinElementHandlerShadow(ap, this);
this.injectors = new AnnotatedMixinElementHandlerInjector(ap, this);
@@ -174,13 +174,13 @@ class AnnotatedMixin {
break;
}
}
-
+
return this;
}
private TypeHandle initTargets() {
TypeHandle primaryTarget = null;
-
+
// Public targets, referenced by class
try {
for (TypeMirror target : this.annotation.getList()) {
@@ -196,7 +196,7 @@ class AnnotatedMixin {
} catch (Exception ex) {
this.printMessage(Kind.WARNING, "Error processing public targets: " + ex.getClass().getName() + ": " + ex.getMessage(), this);
}
-
+
// Private targets, referenced by name
try {
for (String privateTarget : this.annotation.getList("targets")) {
@@ -221,11 +221,11 @@ class AnnotatedMixin {
} catch (Exception ex) {
this.printMessage(Kind.WARNING, "Error processing private targets: " + ex.getClass().getName() + ": " + ex.getMessage(), this);
}
-
+
if (primaryTarget == null) {
this.printMessage(Kind.ERROR, "Mixin has no targets", this);
}
-
+
return primaryTarget;
}
@@ -241,10 +241,10 @@ class AnnotatedMixin {
if (!obfClassData.isEmpty()) {
this.obf.getReferenceManager().addClassMapping(this.classRef, reference, obfClassData);
}
-
+
this.addTarget(type);
}
-
+
private void addTarget(TypeHandle type) {
this.targets.add(type);
}
@@ -253,39 +253,39 @@ class AnnotatedMixin {
public String toString() {
return this.mixin.getSimpleName().toString();
}
-
+
public AnnotationHandle getAnnotation() {
return this.annotation;
}
-
+
/**
* Get the mixin class
*/
public TypeElement getMixin() {
return this.mixin;
}
-
+
/**
* Get the type handle for the mixin class
*/
public TypeHandle getHandle() {
return this.handle;
}
-
+
/**
* Get the mixin class reference
*/
public String getClassRef() {
return this.classRef;
}
-
+
/**
* Get whether this is an interface mixin
*/
public boolean isInterface() {
return this.mixin.getKind() == ElementKind.INTERFACE;
}
-
+
/**
* Get the primary target
*/
@@ -293,32 +293,32 @@ class AnnotatedMixin {
public TypeHandle getPrimaryTarget() {
return this.primaryTarget;
}
-
+
/**
* Get the mixin's targets
*/
public List getTargets() {
return this.targets;
}
-
+
/**
* Get whether this is a multi-target mixin
*/
public boolean isMultiTarget() {
return this.targets.size() > 1;
}
-
+
/**
* Get whether to remap annotations in this mixin
*/
public boolean remap() {
return this.remap;
}
-
+
public IMappingConsumer getMappings() {
return this.mappings;
}
-
+
public void registerOverwrite(ExecutableElement method, AnnotationHandle overwrite) {
this.overwrites.registerOverwrite(new AnnotatedElementOverwrite(method, overwrite));
}
@@ -333,21 +333,21 @@ class AnnotatedMixin {
public void registerInjector(ExecutableElement method, AnnotationHandle inject, InjectorRemap remap) {
this.injectors.registerInjector(new AnnotatedElementInjector(method, inject, remap));
-
+
List ats = inject.getAnnotationList("at");
for (AnnotationHandle at : ats) {
this.registerInjectionPoint(method, inject, at, remap, "@At(%s)");
}
-
+
List slices = inject.getAnnotationList("slice");
for (AnnotationHandle slice : slices) {
String id = slice.getValue("id", "");
-
+
AnnotationHandle from = slice.getAnnotation("from");
if (from != null) {
this.registerInjectionPoint(method, inject, from, remap, "@Slice[" + id + "](from=@At(%s))");
}
-
+
AnnotationHandle to = slice.getAnnotation("to");
if (to != null) {
this.registerInjectionPoint(method, inject, to, remap, "@Slice[" + id + "](to=@At(%s))");
@@ -359,16 +359,16 @@ class AnnotatedMixin {
this.injectors.registerInjectionPoint(new AnnotatedElementInjectionPoint(element, inject, at, remap), format);
}
- public void registerAccessor(ExecutableElement element, AnnotationHandle accessor) {
- this.accessors.registerAccessor(new AnnotatedElementAccessor(element, accessor));
+ public void registerAccessor(ExecutableElement element, AnnotationHandle accessor, boolean shouldRemap) {
+ this.accessors.registerAccessor(new AnnotatedElementAccessor(element, accessor, shouldRemap));
}
- public void registerInvoker(ExecutableElement element, AnnotationHandle invoker) {
- this.accessors.registerAccessor(new AnnotatedElementInvoker(element, invoker));
+ public void registerInvoker(ExecutableElement element, AnnotationHandle invoker, boolean shouldRemap) {
+ this.accessors.registerAccessor(new AnnotatedElementInvoker(element, invoker, shouldRemap));
}
public void registerSoftImplements(AnnotationHandle implementsAnnotation) {
this.softImplements.process(implementsAnnotation);
}
-
+
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandlerAccessor.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandlerAccessor.java
index d7cea344..823f86ad 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandlerAccessor.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandlerAccessor.java
@@ -59,16 +59,23 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
* Accessor element
*/
static class AnnotatedElementAccessor extends AnnotatedElement {
-
+
+ private final boolean shouldRemap;
+
private final TypeMirror returnType;
-
+
private String targetName;
-
- public AnnotatedElementAccessor(ExecutableElement element, AnnotationHandle annotation) {
+
+ public AnnotatedElementAccessor(ExecutableElement element, AnnotationHandle annotation, boolean shouldRemap) {
super(element, annotation);
+ this.shouldRemap = shouldRemap;
this.returnType = this.getElement().getReturnType();
}
-
+
+ public boolean shouldRemap() {
+ return this.shouldRemap;
+ }
+
public String getAnnotationValue() {
return this.getAnnotation().getValue();
}
@@ -83,19 +90,19 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
return null;
}
}
-
+
public String getTargetTypeName() {
return TypeUtils.getTypeName(this.getTargetType());
}
-
+
public String getAccessorDesc() {
return TypeUtils.getInternalName(this.getTargetType());
}
-
+
public MemberInfo getContext() {
return new MemberInfo(this.getTargetName(), null, this.getAccessorDesc());
}
-
+
public AccessorType getAccessorType() {
return this.returnType.getKind() == TypeKind.VOID ? AccessorType.FIELD_SETTER : AccessorType.FIELD_GETTER;
}
@@ -103,72 +110,72 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
public void setTargetName(String targetName) {
this.targetName = targetName;
}
-
+
public String getTargetName() {
return this.targetName;
}
-
+
@Override
public String toString() {
return this.targetName != null ? this.targetName : "";
}
}
-
+
/**
* Invoker element
*/
static class AnnotatedElementInvoker extends AnnotatedElementAccessor {
- public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation) {
- super(element, annotation);
+ public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation, boolean shouldRemap) {
+ super(element, annotation, shouldRemap);
}
-
+
@Override
public String getAccessorDesc() {
return TypeUtils.getDescriptor(this.getElement());
}
-
+
@Override
public AccessorType getAccessorType() {
return AccessorType.METHOD_PROXY;
}
-
+
@Override
public String getTargetTypeName() {
return TypeUtils.getJavaSignature(this.getElement());
}
-
+
}
-
+
public AnnotatedMixinElementHandlerAccessor(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
super(ap, mixin);
}
-
+
@Override
public ReferenceMapper getReferenceMapper() {
return null;
}
-
+
@Override
public String getClassRef() {
return this.mixin.getClassRef();
}
-
+
@Override
public IMixinInfo getMixin() {
throw new UnsupportedOperationException("MixinInfo not available at compile time");
}
-
+
@Override
public boolean getOption(Option option) {
throw new UnsupportedOperationException("Options not available at compile time");
}
-
+
@Override
public int getPriority() {
throw new UnsupportedOperationException("Priority not available at compile time");
}
-
+
@Override
public Target getTargetMethod(MethodNode into) {
throw new UnsupportedOperationException("Target not available at compile time");
@@ -176,7 +183,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
/**
* Register a new accessor
- *
+ *
* @param elem accessor element
*/
public void registerAccessor(AnnotatedElementAccessor elem) {
@@ -191,7 +198,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
return;
}
elem.setTargetName(targetName);
-
+
for (TypeHandle target : this.mixin.getTargets()) {
if (elem.getAccessorType() == AccessorType.METHOD_PROXY) {
this.registerInvokerForTarget((AnnotatedElementInvoker)elem, target);
@@ -208,13 +215,17 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
return;
}
+ if (!elem.shouldRemap()) {
+ return;
+ }
+
ObfuscationData obfData = this.obf.getDataProvider().getObfField(targetField.asMapping(false).move(target.getName()));
if (obfData.isEmpty()) {
String info = this.mixin.isMultiTarget() ? " in target " + target : "";
elem.printMessage(this.ap, Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Accessor target " + elem);
return;
}
-
+
obfData = AnnotatedMixinElementHandler.stripOwnerData(obfData);
try {
@@ -231,16 +242,20 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
elem.printMessage(this.ap, Kind.ERROR, "Could not locate @Invoker target " + elem + " in target " + target);
return;
}
-
+
+ if (!elem.shouldRemap()) {
+ return;
+ }
+
ObfuscationData obfData = this.obf.getDataProvider().getObfMethod(targetMethod.asMapping(false).move(target.getName()));
if (obfData.isEmpty()) {
String info = this.mixin.isMultiTarget() ? " in target " + target : "";
elem.printMessage(this.ap, Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Accessor target " + elem);
return;
}
-
+
obfData = AnnotatedMixinElementHandler.stripOwnerData(obfData);
-
+
try {
this.obf.getReferenceManager().addMethodMapping(this.mixin.getClassRef(), elem.getTargetName(), elem.getContext(), obfData);
} catch (ReferenceConflictException ex) {
@@ -248,7 +263,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
+ target + " conflicts with existing mapping " + ex.getOld());
}
}
-
+
private String getAccessorTargetName(AnnotatedElementAccessor elem) {
String value = elem.getAnnotationValue();
if (Strings.isNullOrEmpty(value)) {
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java
index eec3fbdd..3cbbae7b 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java
@@ -79,14 +79,14 @@ import com.google.common.collect.ImmutableList;
* manages access to the mappings
*/
final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITypeHandleProvider, IJavadocProvider {
-
+
private static final String MAPID_SYSTEM_PROPERTY = "mixin.target.mapid";
-
+
/**
* Singleton instances for each ProcessingEnvironment
*/
private static Map instances = new HashMap();
-
+
/**
* Detected compiler environment
*/
@@ -96,52 +96,52 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
* Local processing environment
*/
private final ProcessingEnvironment processingEnv;
-
+
/**
* Mixins during processing phase
*/
private final Map mixins = new HashMap();
-
+
/**
* Mixins created during this AP pass
*/
private final List mixinsForPass = new ArrayList();
-
+
/**
* Obfuscation manager
*/
private final IObfuscationManager obf;
-
+
/**
* Rule validators
*/
private final List validators;
-
+
/**
- * Resolved tokens for constraint validation
+ * Resolved tokens for constraint validation
*/
private final Map tokenCache = new HashMap();
-
+
/**
- * Serialisable mixin target map
+ * Serialisable mixin target map
*/
private final TargetMap targets;
-
+
/**
* Properties file used to specify options when AP options cannot be
* configured via the build script (eg. when using AP with MCP)
*/
private Properties properties;
-
+
/**
* Private constructor, get instances using {@link #getMixinsForEnvironment}
*/
private AnnotatedMixins(ProcessingEnvironment processingEnv) {
this.env = this.detectEnvironment(processingEnv);
this.processingEnv = processingEnv;
-
+
this.printMessage(Kind.NOTE, "SpongePowered MIXIN Annotation Processor Version=" + MixinBootstrap.VERSION);
-
+
this.targets = this.initTargetMap();
this.obf = new ObfuscationManager(this);
this.obf.init();
@@ -150,7 +150,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
new ParentValidator(this),
new TargetValidator(this)
);
-
+
this.initTokenCache(this.getOption(SupportedOptions.TOKENS));
}
@@ -171,7 +171,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
private void initTokenCache(String tokens) {
if (tokens != null) {
Pattern tokenPattern = Pattern.compile("^([A-Z0-9\\-_\\.]+)=([0-9]+)$");
-
+
String[] tokenValues = tokens.replaceAll("\\s", "").toUpperCase().split("[;,]");
for (String tokenValue : tokenValues) {
Matcher tokenMatcher = tokenPattern.matcher(tokenValue);
@@ -181,7 +181,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
}
}
}
-
+
@Override
public ITypeHandleProvider getTypeProvider() {
return this;
@@ -201,12 +201,12 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public IJavadocProvider getJavadocProvider() {
return this;
}
-
+
@Override
public ProcessingEnvironment getProcessingEnvironment() {
return this.processingEnv;
}
-
+
@Override
public CompilerEnvironment getCompilerEnvironment() {
return this.env;
@@ -217,7 +217,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
if (this.tokenCache.containsKey(token)) {
return this.tokenCache.get(token);
}
-
+
String option = this.getOption(token);
Integer value = null;
try {
@@ -225,7 +225,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
} catch (Exception ex) {
// npe or number format exception
}
-
+
this.tokenCache.put(token, value);
return value;
}
@@ -235,19 +235,19 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
if (option == null) {
return null;
}
-
+
String value = this.processingEnv.getOptions().get(option);
if (value != null) {
return value;
}
-
+
return this.getProperties().getProperty(option);
}
-
+
public Properties getProperties() {
if (this.properties == null) {
this.properties = new Properties();
-
+
try {
Filer filer = this.processingEnv.getFiler();
FileObject propertyFile = filer.getResource(StandardLocation.SOURCE_PATH, "", "mixin.properties");
@@ -260,15 +260,15 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
// ignore
}
}
-
+
return this.properties;
}
-
+
private CompilerEnvironment detectEnvironment(ProcessingEnvironment processingEnv) {
if (processingEnv.getClass().getName().contains("jdt")) {
return CompilerEnvironment.JDT;
}
-
+
return CompilerEnvironment.JAVAC;
}
@@ -287,7 +287,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
}
/**
- * Clear all registered mixins
+ * Clear all registered mixins
*/
public void clear() {
this.mixins.clear();
@@ -298,7 +298,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
*/
public void registerMixin(TypeElement mixinType) {
String name = mixinType.getQualifiedName().toString();
-
+
if (!this.mixins.containsKey(name)) {
AnnotatedMixin mixin = new AnnotatedMixin(this, mixinType);
this.targets.registerTargets(mixin);
@@ -307,7 +307,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.mixinsForPass.add(mixin);
}
}
-
+
/**
* Get a registered mixin
*/
@@ -321,27 +321,27 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public AnnotatedMixin getMixin(String mixinType) {
return this.mixins.get(mixinType);
}
-
+
public Collection getMixinsTargeting(TypeMirror targetType) {
return this.getMixinsTargeting((TypeElement)((DeclaredType)targetType).asElement());
}
-
+
public Collection getMixinsTargeting(TypeElement targetType) {
List minions = new ArrayList();
-
+
for (TypeReference mixin : this.targets.getMixinsTargeting(targetType)) {
TypeHandle handle = mixin.getHandle(this.processingEnv);
if (handle != null) {
minions.add(handle.getType());
}
}
-
+
return minions;
}
-
+
/**
* Register an {@link org.spongepowered.asm.mixin.gen.Accessor} method
- *
+ *
* @param mixinType Mixin class
* @param method Accessor method
*/
@@ -351,13 +351,14 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.printMessage(Kind.ERROR, "Found @Accessor annotation on a non-mixin method", method);
return;
}
-
- mixinClass.registerAccessor(method, AnnotationHandle.of(method, Accessor.class));
+
+ AnnotationHandle accessor = AnnotationHandle.of(method, Accessor.class);
+ mixinClass.registerAccessor(method, accessor, this.shouldRemap(mixinClass, accessor));
}
-
+
/**
* Register an {@link org.spongepowered.asm.mixin.gen.Accessor} method
- *
+ *
* @param mixinType Mixin class
* @param method Accessor method
*/
@@ -367,13 +368,14 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.printMessage(Kind.ERROR, "Found @Accessor annotation on a non-mixin method", method);
return;
}
-
- mixinClass.registerInvoker(method, AnnotationHandle.of(method, Invoker.class));
+
+ AnnotationHandle invoker = AnnotationHandle.of(method, Invoker.class);
+ mixinClass.registerInvoker(method, invoker, this.shouldRemap(mixinClass, invoker));
}
/**
* Register an {@link org.spongepowered.asm.mixin.Overwrite} method
- *
+ *
* @param mixinType Mixin class
* @param method Overwrite method
*/
@@ -383,13 +385,13 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.printMessage(Kind.ERROR, "Found @Overwrite annotation on a non-mixin method", method);
return;
}
-
+
mixinClass.registerOverwrite(method, AnnotationHandle.of(method, Overwrite.class));
}
/**
* Register a {@link org.spongepowered.asm.mixin.Shadow} field
- *
+ *
* @param mixinType Mixin class
* @param field Shadow field
* @param shadow {@link org.spongepowered.asm.mixin.Shadow} annotation
@@ -400,13 +402,13 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.printMessage(Kind.ERROR, "Found @Shadow annotation on a non-mixin field", field);
return;
}
-
+
mixinClass.registerShadow(field, shadow, this.shouldRemap(mixinClass, shadow));
}
/**
* Register a {@link org.spongepowered.asm.mixin.Shadow} method
- *
+ *
* @param mixinType Mixin class
* @param method Shadow method
* @param shadow {@link org.spongepowered.asm.mixin.Shadow} annotation
@@ -423,7 +425,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
/**
* Register a {@link org.spongepowered.asm.mixin.injection.Inject} method
- *
+ *
* @param mixinType Mixin class
* @param method Injector method
* @param inject {@link org.spongepowered.asm.mixin.injection.Inject}
@@ -440,11 +442,11 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
mixinClass.registerInjector(method, inject, remap);
remap.dispatchPendingMessages(this);
}
-
+
/**
* Register an {@link org.spongepowered.asm.mixin.Implements} declaration on
* a mixin class
- *
+ *
* @param mixin Annotated mixin
* @param implementsAnnotation
* {@link org.spongepowered.asm.mixin.Implements} annotation
@@ -458,23 +460,23 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
mixinClass.registerSoftImplements(implementsAnnotation);
}
-
+
/**
* Called from each AP class to notify the environment that a new pass is
- * starting
+ * starting
*/
public void onPassStarted() {
this.mixinsForPass.clear();
}
-
+
/**
- * Called from each AP when a pass is completed
+ * Called from each AP when a pass is completed
*/
public void onPassCompleted() {
if (!"true".equalsIgnoreCase(this.getOption(SupportedOptions.DISABLE_TARGET_EXPORT))) {
this.targets.write(true);
}
-
+
for (AnnotatedMixin mixin : this.mixinsForPass) {
mixin.runValidators(ValidationPass.LATE, this.validators);
}
@@ -493,7 +495,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.processingEnv.getMessager().printMessage(kind, msg);
}
}
-
+
/**
* Print a message to the AP messager
*/
@@ -501,7 +503,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element element) {
this.processingEnv.getMessager().printMessage(kind, msg, element);
}
-
+
/**
* Print a message to the AP messager
*/
@@ -509,7 +511,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation) {
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation);
}
-
+
/**
* Print a message to the AP messager
*/
@@ -517,7 +519,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) {
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation, value);
}
-
+
/**
* Get a TypeHandle representing another type in the current processing
* environment
@@ -525,7 +527,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
@Override
public TypeHandle getTypeHandle(String name) {
name = name.replace('/', '.');
-
+
Elements elements = this.processingEnv.getElementUtils();
TypeElement element = elements.getTypeElement(name);
if (element != null) {
@@ -535,7 +537,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
// probably bad package
}
}
-
+
int lastDotPos = name.lastIndexOf('.');
if (lastDotPos > -1) {
String pkg = name.substring(0, lastDotPos);
@@ -544,10 +546,10 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
return new TypeHandle(packageElement, name);
}
}
-
+
return null;
}
-
+
/**
* Returns a simulated TypeHandle for a non-existing type
*/
diff --git a/src/main/java/org/spongepowered/asm/mixin/gen/Accessor.java b/src/main/java/org/spongepowered/asm/mixin/gen/Accessor.java
index aa9b928d..6fa3ee2a 100644
--- a/src/main/java/org/spongepowered/asm/mixin/gen/Accessor.java
+++ b/src/main/java/org/spongepowered/asm/mixin/gen/Accessor.java
@@ -43,7 +43,7 @@ import org.spongepowered.asm.mixin.Shadow;
* greatly simplify mixins which only contain accessors, and provide for
* faster development than with access transformers since no re-decompile is
* needed to put the changes into effect.
- *
+ *
* Accessors can be used in regular mixins as a convenient way to generate
* getters and setters. They can also be used to create "Accessor Mixins"
* which are special mixins defined as interfaces which must
@@ -51,7 +51,7 @@ import org.spongepowered.asm.mixin.Shadow;
* normal mixins however, Accessor Mixins are accessible via user code
* and thus no surrogate "Duck" interface is required to expose the
* generated methods, the mixin itself acts as its own Duck.
- *
+ *
*
*/
@Target({ ElementType.METHOD })
@@ -63,14 +63,29 @@ public @interface Accessor {
* method name. If the annotated method starts with "get", "set" or "is"
* followed by a capital letter, then the prefix is stripped and the
* remainder of the method name is used as the target field name.
- *
+ *
* However sometimes it maye be desirable to name an accessor method
* differently to the target field name. In this case you may specify the
* field using its name.
- *
+ *
* @return name for the target field, or empty string to inflect using the
* annotated method name
*/
public String value() default "";
-
+
+ /**
+ * By default, the annotation processor will attempt to locate an
+ * obfuscation mapping for all {@link Accessor} methods since it is
+ * anticipated that in general the target field of a {@link Accessor}
+ * annotation will be an obfuscated field in the target class. However since
+ * it is possible that the target is not obfuscated, it may be desirable to
+ * suppress the compiler warning which would be generated. Setting this
+ * value to false will cause the annotation processor to skip
+ * remapping for this annotation.
+ *
+ * @return True to instruct the annotation processor to search for
+ * obfuscation mappings for this annotation
+ */
+ public boolean remap() default true;
+
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/gen/Invoker.java b/src/main/java/org/spongepowered/asm/mixin/gen/Invoker.java
index db3bfeff..489815f0 100644
--- a/src/main/java/org/spongepowered/asm/mixin/gen/Invoker.java
+++ b/src/main/java/org/spongepowered/asm/mixin/gen/Invoker.java
@@ -42,7 +42,7 @@ import org.spongepowered.asm.mixin.Shadow;
* greatly simplify mixins which only contain accessors, and provide for
* faster development than with access transformers since no re-decompile is
* needed to put the changes into effect.
- *
+ *
* Invokers can be used in regular mixins as a way to provide access to a
* private method without needing to shadow and then manually proxy the method
* call. They can also be used to create "Accessor Mixins" which are
@@ -51,7 +51,7 @@ import org.spongepowered.asm.mixin.Shadow;
* Accessor Mixins are accessible via user code and thus no surrogate
* "Duck" interface is required to expose the generated methods, the
* mixin itself acts as its own Duck.
- *
+ *
* - See also {@link Accessor}
*/
@Target({ ElementType.METHOD })
@@ -63,14 +63,29 @@ public @interface Invoker {
* method name. If the annotated method starts with "call" or "invoke"
* followed by a capital letter, then the prefix is stripped and the
* remainder of the method name is used as the target method name.
- *
+ *
* However sometimes it maye be desirable to name an accessor method
* differently to the target method. In this case you may specify the method
* using its name.
- *
+ *
* @return name for the target method, or empty string to inflect using the
* annotated method name
*/
public String value() default "";
-
+
+ /**
+ * By default, the annotation processor will attempt to locate an
+ * obfuscation mapping for all {@link Invoker} methods since it is
+ * anticipated that in general the target of a {@link Invoker} annotation
+ * will be an obfuscated method in the target class. However since it is
+ * possible that the target is not obfuscated, it may be desirable to
+ * suppress the compiler warning which would be generated. Setting this
+ * value to false will cause the annotation processor to skip
+ * remapping for this annotation.
+ *
+ * @return True to instruct the annotation processor to search for
+ * obfuscation mappings for this annotation
+ */
+ public boolean remap() default true;
+
}