diff --git a/checkstyle.xml b/checkstyle.xml
index f11b7e93..206877ad 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -76,7 +76,7 @@
-
+
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
index 4775084c..bfc2e522 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
@@ -98,15 +98,10 @@ class AnnotatedMixin {
*/
private final List targets = new ArrayList();
- /**
- * Target "reference" (bytecode name)
- */
- private final String targetRef;
-
/**
* Target type (for single-target mixins)
*/
- private final TypeHandle targetType;
+ private final TypeHandle primaryTarget;
/**
* Mixin class "reference" (bytecode name)
@@ -142,16 +137,7 @@ class AnnotatedMixin {
this.mixin = type;
this.handle = new TypeHandle(type);
this.classRef = type.getQualifiedName().toString().replace('.', '/');
-
- TypeHandle primaryTarget = this.initTargets();
- if (primaryTarget != null) {
- this.targetRef = primaryTarget.getName();
- this.targetType = primaryTarget;
- } else {
- this.targetRef = null;
- this.targetType = null;
- }
-
+ this.primaryTarget = this.initTargets();
this.remap = AnnotatedMixins.getRemapValue(this.annotation) && this.targets.size() > 0;
this.overwrites = new AnnotatedMixinOverwriteHandler(ap, this);
@@ -279,18 +265,12 @@ class AnnotatedMixin {
return this.mixin.getKind() == ElementKind.INTERFACE;
}
- /**
- * Get the primary target class reference
- */
- public String getPrimaryTargetRef() {
- return this.targetRef;
- }
-
/**
* Get the primary target
*/
+ @Deprecated
public TypeHandle getPrimaryTarget() {
- return this.targetType;
+ return this.primaryTarget;
}
/**
@@ -300,6 +280,13 @@ class AnnotatedMixin {
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
*/
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java
index f0e79d5d..9f8f1d55 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java
@@ -43,8 +43,10 @@ import org.spongepowered.asm.util.ConstraintParser.Constraint;
import org.spongepowered.asm.util.throwables.ConstraintViolationException;
import org.spongepowered.asm.util.throwables.InvalidConstraintException;
import org.spongepowered.tools.MirrorUtils;
+import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
+import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
/**
* Base class for module for {@link AnnotatedMixin} which handle different
@@ -249,10 +251,9 @@ abstract class AnnotatedMixinElementHandler {
*/
protected final IMixinAnnotationProcessor ap;
- /**
- * Manager
- */
protected final IObfuscationManager obf;
+
+ private IMappingConsumer mappings;
AnnotatedMixinElementHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
this.ap = ap;
@@ -261,15 +262,28 @@ abstract class AnnotatedMixinElementHandler {
this.obf = ap.getObfuscationManager();
}
- protected final boolean remapReference(String key, String target, Element element, AnnotationMirror inject, AnnotationMirror at) {
- if (target == null) {
+ private IMappingConsumer getMappings() {
+ if (this.mappings == null) {
+ IMappingConsumer mappingConsumer = this.mixin.getMappings();
+ if (mappingConsumer instanceof Mappings) {
+ this.mappings = ((Mappings)mappingConsumer).asUnique();
+ } else {
+ this.mappings = mappingConsumer;
+ }
+ }
+ return this.mappings;
+ }
+
+ protected final boolean remapReference(String key, String reference, Element element, AnnotationMirror inject, AnnotationMirror at) {
+ if (reference == null) {
return false;
}
- MemberInfo targetMember = MemberInfo.parse(target);
+ String annotation = "@At(" + key + ")";
+ MemberInfo targetMember = MemberInfo.parse(reference);
if (!targetMember.isFullyQualified()) {
String missing = "missing " + (targetMember.owner == null ? (targetMember.desc == null ? "owner and signature" : "owner") : "signature");
- this.ap.printMessage(Kind.ERROR, "@At(" + key + ") is not fully qualified, " + missing, element, inject);
+ this.ap.printMessage(Kind.ERROR, annotation + " is not fully qualified, " + missing, element, inject);
return false;
}
@@ -279,25 +293,42 @@ abstract class AnnotatedMixinElementHandler {
this.ap.printMessage(Kind.ERROR, ex.getMessage(), element, inject);
}
- if (targetMember.isField()) {
- ObfuscationData obfFieldData = this.obf.getDataProvider().getObfFieldRecursive(targetMember);
- if (obfFieldData.isEmpty()) {
- this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for @At(" + key + ") '" + target + "'", element, inject);
- return false;
- }
- this.obf.getReferenceManager().addFieldMapping(this.classRef, target, targetMember, obfFieldData);
- } else {
- ObfuscationData obfMethodData = this.obf.getDataProvider().getObfMethodRecursive(targetMember);
- if (obfMethodData.isEmpty()) {
- if (targetMember.owner == null || !targetMember.owner.startsWith("java/lang/")) {
- this.ap.printMessage(Kind.WARNING, "Cannot find method mapping for @At(" + key + ") '" + target + "'", element, inject);
+ try {
+ if (targetMember.isField()) {
+ ObfuscationData obfFieldData = this.obf.getDataProvider().getObfFieldRecursive(targetMember);
+ if (obfFieldData.isEmpty()) {
+ this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for " + annotation + " '" + reference + "'", element, inject);
+ return false;
}
+ this.obf.getReferenceManager().addFieldMapping(this.classRef, reference, targetMember, obfFieldData);
+ } else {
+ ObfuscationData obfMethodData = this.obf.getDataProvider().getObfMethodRecursive(targetMember);
+ if (obfMethodData.isEmpty()) {
+ if (targetMember.owner == null || !targetMember.owner.startsWith("java/lang/")) {
+ this.ap.printMessage(Kind.WARNING, "Cannot find method mapping for " + annotation + " '" + reference + "'", element, inject);
+ return false;
+ }
+ }
+ this.obf.getReferenceManager().addMethodMapping(this.classRef, reference, targetMember, obfMethodData);
}
- this.obf.getReferenceManager().addMethodMapping(this.classRef, target, targetMember, obfMethodData);
+ } catch (ReferenceConflictException ex) {
+ // Since references are fully-qualified, it shouldn't be possible for there to be multiple mappings, however
+ // we catch and log the error in case something weird happens in the mapping provider
+ this.ap.printMessage(Kind.ERROR, "Unexpected reference conflict for " + annotation + ": " + reference + " -> "
+ + ex.getNew() + " previously defined as " + ex.getOld(), element, inject);
+ return false;
}
+
return true;
}
-
+
+ protected final void addFieldMappings(String mcpName, String mcpSignature, ObfuscationData obfData) {
+ for (ObfuscationType type : obfData) {
+ MappingField obfField = obfData.get(type);
+ this.addFieldMapping(type, mcpName, obfField.getSimpleName(), mcpSignature, obfField.getDesc());
+ }
+ }
+
/**
* Add a field mapping to the local table
*/
@@ -311,7 +342,14 @@ abstract class AnnotatedMixinElementHandler {
protected final void addFieldMapping(ObfuscationType type, String mcpName, String obfName, String mcpSignature, String obfSignature) {
MappingField from = new MappingField(this.classRef, mcpName, mcpSignature);
MappingField to = new MappingField(this.classRef, obfName, obfSignature);
- this.mixin.getMappings().addFieldMapping(type, from, to);
+ this.getMappings().addFieldMapping(type, from, to);
+ }
+
+ protected final void addMethodMappings(String mcpName, String mcpSignature, ObfuscationData obfData) {
+ for (ObfuscationType type : obfData) {
+ MappingMethod obfMethod = obfData.get(type);
+ this.addMethodMapping(type, mcpName, obfMethod.getSimpleName(), mcpSignature, obfMethod.getDesc());
+ }
}
/**
@@ -327,24 +365,9 @@ abstract class AnnotatedMixinElementHandler {
protected final void addMethodMapping(ObfuscationType type, String mcpName, String obfName, String mcpSignature, String obfSignature) {
MappingMethod from = new MappingMethod(this.classRef, mcpName, mcpSignature);
MappingMethod to = new MappingMethod(this.classRef, obfName, obfSignature);
- this.mixin.getMappings().addMethodMapping(type, from, to);
+ this.getMappings().addMethodMapping(type, from, to);
}
- /**
- * Validate method for {@link org.spongepowered.asm.mixin.Shadow} and
- * {@link org.spongepowered.asm.mixin.Overwrite} registrations to check that
- * only a single target is registered. Mixins containing annotated methods
- * with these annotations cannot be multi-targetted.
- */
- protected final boolean validateSingleTarget(String annotation, Element element) {
- if (this.mixin.getPrimaryTargetRef() == null || this.mixin.getTargets().size() > 1) {
- this.ap.printMessage(Kind.ERROR, "Mixin with " + annotation + " members must have exactly one target.", element);
- this.ap.printMessage(Kind.ERROR, "Mixin with " + annotation + " members must have exactly one target.", this.mixin.getMixin());
- return false;
- }
- return true;
- }
-
/**
* Check constraints for the specified annotation based on token values in
* the current environment
@@ -416,7 +439,7 @@ abstract class AnnotatedMixinElementHandler {
* Checks whether the specified field exists in all targets and raises
* warnings where appropriate
*/
- protected final void validateTargetField(VariableElement field, AnnotationMirror shadow, AliasedElementName name, String type) {
+ protected final void validateTargetField(VariableElement field, AnnotationMirror annotation, AliasedElementName name, String type) {
String fieldType = field.asType().toString();
for (TypeHandle target : this.mixin.getTargets()) {
@@ -439,7 +462,7 @@ abstract class AnnotatedMixinElementHandler {
}
if (targetField == null) {
- this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, shadow);
+ this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, annotation);
}
}
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinInjectorHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinInjectorHandler.java
index b0a73b0e..c6e85baa 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinInjectorHandler.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinInjectorHandler.java
@@ -38,6 +38,7 @@ import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.tools.MirrorUtils;
+import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.struct.Message;
@@ -62,6 +63,11 @@ class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
return this.shouldRemap;
}
+ @Override
+ public String toString() {
+ return "@" + this.getAnnotation().getAnnotationType().asElement().getSimpleName();
+ }
+
}
/**
@@ -91,8 +97,8 @@ class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", elem.getElement());
}
- String originalReference = MirrorUtils.getAnnotationValue(elem.getAnnotation(), "method");
- MemberInfo targetMember = MemberInfo.parse(originalReference);
+ String reference = MirrorUtils.getAnnotationValue(elem.getAnnotation(), "method");
+ MemberInfo targetMember = MemberInfo.parse(reference);
if (targetMember.name == null) {
return null;
}
@@ -103,38 +109,69 @@ class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), elem.getAnnotation());
}
- String type = "@" + elem.getAnnotation().getAnnotationType().asElement().getSimpleName() + "";
if (targetMember.desc != null) {
- this.validateReferencedTarget(elem.getElement(), elem.getAnnotation(), targetMember, type);
+ this.validateReferencedTarget(elem.getElement(), elem.getAnnotation(), targetMember, elem.toString());
}
- if (!elem.shouldRemap() || !this.validateSingleTarget(type, elem.getElement())) {
+ if (!elem.shouldRemap()) {
return null;
}
- String desc = this.mixin.getPrimaryTarget().findDescriptor(targetMember);
+ for (TypeHandle target : this.mixin.getTargets()) {
+ Message message = this.registerInjector(elem, reference, targetMember, target);
+ if (message != null) {
+ return message;
+ }
+ }
+ return null;
+ }
+
+ private Message registerInjector(AnnotatedElementInjector elem, String reference, MemberInfo targetMember, TypeHandle target) {
+ String desc = target.findDescriptor(targetMember);
if (desc == null) {
- if (this.mixin.getPrimaryTarget().isImaginary()) {
- this.ap.printMessage(Kind.WARNING, type + " target requires method signature because enclosing type information is unavailable",
- elem.getElement(), elem.getAnnotation());
+ Kind error = this.mixin.isMultiTarget() ? Kind.ERROR : Kind.WARNING;
+ if (target.isImaginary()) {
+ this.ap.printMessage(error, elem + " target requires method signature because enclosing type information for "
+ + target + " is unavailable", elem.getElement(), elem.getAnnotation());
} else if (!Constants.CTOR.equals(targetMember.name)) {
- this.ap.printMessage(Kind.WARNING, "Unable to determine signature for " + type + " target method",
+ this.ap.printMessage(error, "Unable to determine signature for " + elem + " target method",
elem.getElement(), elem.getAnnotation());
}
return null;
- }
+ }
- MappingMethod targetMethod = new MappingMethod(this.mixin.getPrimaryTargetRef(), targetMember.name, desc);
+ String targetName = elem + " target " + targetMember.name;
+ MappingMethod targetMethod = new MappingMethod(target.getName(), targetMember.name, desc);
ObfuscationData obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
if (obfData.isEmpty()) {
Kind error = Constants.CTOR.equals(targetMember.name) ? Kind.WARNING : Kind.ERROR;
- return new Message(error, "No obfuscation mapping for " + type + " target " + targetMember.name, elem.getElement(), elem.getAnnotation());
+ return new Message(error, "No obfuscation mapping for " + targetName, elem.getElement(), elem.getAnnotation());
+ }
+
+ try {
+ // If the original owner is unspecified, and the mixin is multi-target, we strip the owner from the obf mappings
+ if (targetMember.owner == null && this.mixin.isMultiTarget()) {
+ obfData = AnnotatedMixinInjectorHandler.stripOwnerData(obfData);
+ }
+ this.obf.getReferenceManager().addMethodMapping(this.classRef, reference, obfData);
+ } catch (ReferenceConflictException ex) {
+ String conflictType = this.mixin.isMultiTarget() ? "Multi-target" : "Target";
+ this.ap.printMessage(Kind.ERROR, conflictType + " reference conflict for " + targetName + ": " + reference + " -> "
+ + ex.getNew() + " previously defined as " + ex.getOld(), elem.getElement(), elem.getAnnotation());
}
- this.obf.getReferenceManager().addMethodMapping(this.classRef, originalReference, obfData);
return null;
}
+ private static ObfuscationData stripOwnerData(ObfuscationData data) {
+ ObfuscationData stripped = new ObfuscationData();
+ for (ObfuscationType type : data) {
+ MappingMethod mappingMethod = data.get(type);
+ stripped.add(type, mappingMethod.move(null));
+ }
+ return stripped;
+ }
+
/**
* Register a {@link org.spongepowered.asm.mixin.injection.At} annotation
* and process the references
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinOverwriteHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinOverwriteHandler.java
index 69dcfaf8..cfaec902 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinOverwriteHandler.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinOverwriteHandler.java
@@ -32,6 +32,7 @@ import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.MirrorUtils;
+import org.spongepowered.tools.obfuscation.Mappings.MappingConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
/**
@@ -43,11 +44,22 @@ class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
* Overwrite element
*/
static class AnnotatedElementOverwrite extends AnnotatedElement {
+
+ private final String desc;
public AnnotatedElementOverwrite(ExecutableElement element, AnnotationMirror annotation) {
super(element, annotation);
+ this.desc = MirrorUtils.getDescriptor(element);
}
+ public String getSimpleName() {
+ return this.getElement().getSimpleName().toString();
+ }
+
+ public String getDesc() {
+ return this.desc;
+ }
+
}
AnnotatedMixinOverwriteHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
@@ -59,35 +71,14 @@ class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
this.validateTargetMethod(elem.getElement(), elem.getAnnotation(), name, "@Overwrite");
this.checkConstraints(elem.getElement(), elem.getAnnotation());
- if (!this.mixin.remap() || !this.validateSingleTarget("@Overwrite", elem.getElement())) {
+ if (!this.mixin.remap()) {
return;
}
- String mcpName = elem.getElement().getSimpleName().toString();
- String mcpSignature = MirrorUtils.generateSignature(elem.getElement());
- MappingMethod targetMethod = new MappingMethod(this.mixin.getPrimaryTargetRef(), mcpName, mcpSignature);
- ObfuscationData obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
-
- if (obfData.isEmpty()) {
- Kind error = Kind.ERROR;
-
- try {
- // Try to access isStatic from com.sun.tools.javac.code.Symbol
- Method md = elem.getElement().getClass().getMethod("isStatic");
- if (((Boolean)md.invoke(elem.getElement())).booleanValue()) {
- error = Kind.WARNING;
- }
- } catch (Exception ex) {
- // well, we tried
+ for (TypeHandle target : this.mixin.getTargets()) {
+ if (!this.registerOverwriteForTarget(elem, target)) {
+ return;
}
-
- this.ap.printMessage(error, "No obfuscation mapping for @Overwrite method", elem.getElement());
- return;
- }
-
- for (ObfuscationType type : obfData) {
- MappingMethod obfMethod = obfData.get(type);
- this.addMethodMapping(type, mcpName, obfMethod.getSimpleName(), mcpSignature, obfMethod.getDesc());
}
if (!"true".equalsIgnoreCase(this.ap.getOption(SupportedOptions.DISABLE_OVERWRITE_CHECKER))) {
@@ -110,4 +101,35 @@ class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
}
}
+ private boolean registerOverwriteForTarget(AnnotatedElementOverwrite elem, TypeHandle target) {
+ MappingMethod targetMethod = new MappingMethod(target.getName(), elem.getSimpleName(), elem.getDesc());
+ ObfuscationData obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
+
+ if (obfData.isEmpty()) {
+ Kind error = Kind.ERROR;
+
+ try {
+ // Try to access isStatic from com.sun.tools.javac.code.Symbol
+ Method md = elem.getElement().getClass().getMethod("isStatic");
+ if (((Boolean)md.invoke(elem.getElement())).booleanValue()) {
+ error = Kind.WARNING;
+ }
+ } catch (Exception ex) {
+ // well, we tried
+ }
+
+ this.ap.printMessage(error, "No obfuscation mapping for @Overwrite method", elem.getElement());
+ return false;
+ }
+
+ try {
+ this.addMethodMappings(elem.getSimpleName(), elem.getDesc(), obfData);
+ } catch (MappingConflictException ex) {
+ this.ap.printMessage(Kind.ERROR, "Mapping conflict for @Overwrite method: " + ex.getNew().getSimpleName() + " for target " + target
+ + " conflicts with existing mapping " + ex.getOld().getSimpleName(), elem.getElement(), elem.getAnnotation());
+ return false;
+ }
+ return true;
+ }
+
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinShadowHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinShadowHandler.java
index 1527cada..7805b293 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinShadowHandler.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinShadowHandler.java
@@ -35,6 +35,7 @@ import org.spongepowered.asm.obfuscation.mapping.IMapping.Type;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.MirrorUtils;
+import org.spongepowered.tools.obfuscation.Mappings.MappingConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
@@ -89,7 +90,7 @@ class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
}
public ShadowElementName setObfuscatedName(IMapping> name) {
- return this.setObfuscatedName(name.getName());
+ return this.setObfuscatedName(name.getSimpleName());
}
public ShadowElementName setObfuscatedName(String name) {
@@ -99,7 +100,7 @@ class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
public ObfuscationData getObfuscationData(IObfuscationDataProvider provider, String owner) {
return provider.getObfEntry(this.getMapping(owner, this.getName().toString(), this.getDesc()));
}
-
+
public abstract M getMapping(String owner, String name, String desc);
public abstract void addMapping(ObfuscationType type, IMapping> remapped);
@@ -124,6 +125,7 @@ class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
public void addMapping(ObfuscationType type, IMapping> remapped) {
AnnotatedMixinShadowHandler.this.addFieldMapping(type, this.setObfuscatedName(remapped), this.getDesc(), remapped.getDesc());
}
+
}
/**
@@ -152,24 +154,37 @@ class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
}
/**
- * Register a {@link org.spongepowered.asm.mixin.Shadow} field
+ * Register a {@link org.spongepowered.asm.mixin.Shadow} field or method
*/
public void registerShadow(AnnotatedElementShadow, ?> elem) {
this.validateTarget(elem.getElement(), elem.getAnnotation(), elem.getName(), "@Shadow");
- if (!elem.shouldRemap() || !this.validateSingleTarget("@Shadow", elem.getElement())) {
+ if (!elem.shouldRemap()) {
return;
}
- ObfuscationData extends IMapping>> obfData = elem.getObfuscationData(this.obf.getDataProvider(), this.mixin.getPrimaryTargetRef());
+ for (TypeHandle target : this.mixin.getTargets()) {
+ this.registerShadowForTarget(elem, target);
+ }
+ }
+
+ private void registerShadowForTarget(AnnotatedElementShadow, ?> elem, TypeHandle target) {
+ ObfuscationData extends IMapping>> obfData = elem.getObfuscationData(this.obf.getDataProvider(), target.getName());
if (obfData.isEmpty()) {
- this.ap.printMessage(Kind.WARNING, "Unable to locate obfuscation mapping for @Shadow " + elem, elem.getElement(), elem.getAnnotation());
+ String info = this.mixin.isMultiTarget() ? " in target " + target : "";
+ this.ap.printMessage(Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Shadow " + elem,
+ elem.getElement(), elem.getAnnotation());
return;
}
for (ObfuscationType type : obfData) {
- elem.addMapping(type, obfData.get(type));
+ try {
+ elem.addMapping(type, obfData.get(type));
+ } catch (MappingConflictException ex) {
+ this.ap.printMessage(Kind.ERROR, "Mapping conflict for @Shadow " + elem + ": " + ex.getNew().getSimpleName() + " for target "
+ + target + " conflicts with existing mapping " + ex.getOld().getSimpleName(), elem.getElement(), elem.getAnnotation());
+ }
}
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/Mappings.java b/src/ap/java/org/spongepowered/tools/obfuscation/Mappings.java
index b0a3c7fb..95cd7998 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/Mappings.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/Mappings.java
@@ -27,6 +27,7 @@ package org.spongepowered.tools.obfuscation;
import java.util.HashMap;
import java.util.Map;
+import org.spongepowered.asm.obfuscation.mapping.IMapping;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
@@ -37,6 +38,102 @@ import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet.P
*/
class Mappings implements IMappingConsumer {
+ /**
+ * Exception thrown by {@link UniqueMappings} when a conflict occurs
+ */
+ public static class MappingConflictException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final IMapping> oldMapping, newMapping;
+
+ public MappingConflictException(IMapping> oldMapping, IMapping> newMapping) {
+ this.oldMapping = oldMapping;
+ this.newMapping = newMapping;
+ }
+
+ public IMapping> getOld() {
+ return this.oldMapping;
+ }
+
+ public IMapping> getNew() {
+ return this.newMapping;
+ }
+
+ }
+
+ /**
+ * A wrapper for mapping consumer which ensures all mappings added are
+ * unique
+ */
+ static class UniqueMappings implements IMappingConsumer {
+
+ private final IMappingConsumer mappings;
+
+ private final Map> fields =
+ new HashMap>();
+ private final Map> methods =
+ new HashMap>();
+
+ public UniqueMappings(IMappingConsumer mappings) {
+ this.mappings = mappings;
+ }
+
+ @Override
+ public void clear() {
+ this.clearMaps();
+ this.mappings.clear();
+ }
+
+ protected void clearMaps() {
+ this.fields.clear();
+ this.methods.clear();
+ }
+
+ @Override
+ public void addFieldMapping(ObfuscationType type, MappingField from, MappingField to) {
+ if (!this.checkForExistingMapping(type, from, to, this.fields)) {
+ this.mappings.addFieldMapping(type, from, to);
+ }
+ }
+
+ @Override
+ public void addMethodMapping(ObfuscationType type, MappingMethod from, MappingMethod to) {
+ if (!this.checkForExistingMapping(type, from, to, this.methods)) {
+ this.mappings.addMethodMapping(type, from, to);
+ }
+ }
+
+ private > boolean checkForExistingMapping(ObfuscationType type, TMapping from, TMapping to,
+ Map> mappings) throws MappingConflictException {
+ Map existingMappings = mappings.get(type);
+ if (existingMappings == null) {
+ existingMappings = new HashMap();
+ mappings.put(type, existingMappings);
+ }
+ TMapping existing = existingMappings.get(from);
+ if (existing != null) {
+ if (existing.equals(to)) {
+ return true;
+ }
+ throw new MappingConflictException(existing, to);
+ }
+ existingMappings.put(from, to);
+ return false;
+ }
+
+ @Override
+ public MappingSet getFieldMappings(ObfuscationType type) {
+ return this.mappings.getFieldMappings(type);
+ }
+
+ @Override
+ public MappingSet getMethodMappings(ObfuscationType type) {
+ return this.mappings.getMethodMappings(type);
+ }
+
+ }
+
/**
* Stored (ordered) field mappings
*/
@@ -49,6 +146,7 @@ class Mappings implements IMappingConsumer {
private final Map> methodMappings =
new HashMap>();
+ private UniqueMappings unique;
public Mappings() {
this.init();
@@ -61,6 +159,13 @@ class Mappings implements IMappingConsumer {
}
}
+ public IMappingConsumer asUnique() {
+ if (this.unique == null) {
+ this.unique = new UniqueMappings(this);
+ }
+ return this.unique;
+ }
+
/**
* Get stored field mappings
*/
@@ -86,6 +191,9 @@ class Mappings implements IMappingConsumer {
public void clear() {
this.fieldMappings.clear();
this.methodMappings.clear();
+ if (this.unique != null) {
+ this.unique.clearMaps();
+ }
this.init();
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationDataProvider.java b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationDataProvider.java
index cf1b8ef0..62fc15c4 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationDataProvider.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationDataProvider.java
@@ -113,9 +113,9 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
public ObfuscationData getObfEntry(IMapping mapping) {
if (mapping != null) {
if (mapping.getType() == Type.FIELD) {
- return (ObfuscationData) this.getObfField((MappingField)mapping);
+ return (ObfuscationData)this.getObfField((MappingField)mapping);
} else if (mapping.getType() == Type.METHOD) {
- return (ObfuscationData) this.getObfMethod((MappingMethod)mapping);
+ return (ObfuscationData)this.getObfMethod((MappingMethod)mapping);
}
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationEnvironment.java b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationEnvironment.java
index 1d978e7a..78e696eb 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationEnvironment.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationEnvironment.java
@@ -45,16 +45,18 @@ import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet;
+import org.spongepowered.tools.obfuscation.interfaces.IObfuscationEnvironment;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
/**
- * Stores information relevant to a particular obfuscation environment.
+ * Provides access to information relevant to a particular obfuscation
+ * environment.
*
* We classify different types of possible obfuscation (eg. "searge",
* "notch") as obfuscation environments and store related information
- * such as the input mappings, generated refmap and generated mappings here.
+ * such as the input mappings here.
*/
-public abstract class ObfuscationEnvironment {
+public abstract class ObfuscationEnvironment implements IObfuscationEnvironment {
/**
* Remapping proxy for remapping descriptors
@@ -178,6 +180,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a method
*/
+ @Override
public MappingMethod getObfMethod(MemberInfo method) {
MappingMethod obfd = this.getObfMethod(method.asMethodMapping());
if (obfd != null || !method.isFullyQualified()) {
@@ -204,6 +207,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a method
*/
+ @Override
public MappingMethod getObfMethod(MappingMethod method) {
return this.getObfMethod(method, true);
}
@@ -211,6 +215,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a method
*/
+ @Override
public MappingMethod getObfMethod(MappingMethod method, boolean lazyRemap) {
if (this.initMappings()) {
boolean remapped = true;
@@ -243,6 +248,7 @@ public abstract class ObfuscationEnvironment {
* @param method method to remap
* @return remapped method or null if no remapping occurred
*/
+ @Override
public MemberInfo remapDescriptor(MemberInfo method) {
boolean transformed = false;
@@ -274,6 +280,7 @@ public abstract class ObfuscationEnvironment {
* @return remapped descriptor, may return the original descriptor if no
* remapping occurred
*/
+ @Override
public String remapDescriptor(String desc) {
return ObfuscationUtil.mapDescriptor(desc, this.remapper);
}
@@ -281,6 +288,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a field
*/
+ @Override
public MappingField getObfField(MemberInfo field) {
return this.getObfField(field.asFieldMapping(), true);
}
@@ -288,6 +296,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a field
*/
+ @Override
public MappingField getObfField(MappingField field) {
return this.getObfField(field, true);
}
@@ -295,6 +304,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a field
*/
+ @Override
public MappingField getObfField(MappingField field, boolean lazyRemap) {
if (!this.initMappings()) {
return null;
@@ -318,6 +328,7 @@ public abstract class ObfuscationEnvironment {
/**
* Get an obfuscation mapping for a class
*/
+ @Override
public String getObfClass(String className) {
if (!this.initMappings()) {
return null;
@@ -328,6 +339,7 @@ public abstract class ObfuscationEnvironment {
/**
* Write out generated mappings
*/
+ @Override
public void writeMappings(Collection consumers) {
MappingSet fields = new MappingSet();
MappingSet methods = new MappingSet();
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/ReferenceManager.java b/src/ap/java/org/spongepowered/tools/obfuscation/ReferenceManager.java
index 859a1efd..479723eb 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/ReferenceManager.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/ReferenceManager.java
@@ -45,6 +45,30 @@ import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
*/
public class ReferenceManager implements IReferenceManager {
+ /**
+ * Exception thrown when a reference conflict occurs
+ */
+ public static class ReferenceConflictException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String oldReference, newReference;
+
+ public ReferenceConflictException(String oldReference, String newReference) {
+ this.oldReference = oldReference;
+ this.newReference = newReference;
+ }
+
+ public String getOld() {
+ return this.oldReference;
+ }
+
+ public String getNew() {
+ return this.newReference;
+ }
+
+ }
+
/**
* Annotation processor
*/
@@ -189,7 +213,11 @@ public class ReferenceManager implements IReferenceManager {
}
protected void addMapping(ObfuscationType type, String className, String reference, String newReference) {
- this.refMapper.addMapping(type.getKey(), className, reference, newReference);
+ String oldReference = this.refMapper.addMapping(type.getKey(), className, reference, newReference);
+ if (oldReference != null && !oldReference.equals(newReference)) {
+ throw new ReferenceConflictException(oldReference, newReference);
+ }
+
if (type.isDefault()) {
this.refMapper.addMapping(null, className, reference, newReference);
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationEnvironment.java b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationEnvironment.java
new file mode 100644
index 00000000..19953291
--- /dev/null
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationEnvironment.java
@@ -0,0 +1,140 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.spongepowered.tools.obfuscation.interfaces;
+
+import java.util.Collection;
+
+import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
+import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
+import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
+import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
+
+/**
+ * An obfuscation environment provides facilities to fetch obfuscation mappings
+ * of a particular type and also manage writing generated mappings of that type
+ * to disk.
+ */
+public interface IObfuscationEnvironment {
+
+ /**
+ * Get an obfuscation mapping for a method, returns null if no mapping
+ * exists for the specified method in this environment.
+ *
+ * @param method method to locate a mapping for
+ * @return remapped method or null if no mapping exists
+ */
+ public abstract MappingMethod getObfMethod(MemberInfo method);
+
+ /**
+ * Get an obfuscation mapping for a method, returns null if no mapping
+ * exists for the specified method in this environment.
+ *
+ * @param method method to locate a mapping for
+ * @return remapped method or null if no mapping exists
+ */
+ public abstract MappingMethod getObfMethod(MappingMethod method);
+
+ /**
+ * Get an obfuscation mapping for a method, returns null if no mapping
+ * exists for the specified method in this environment.
+ *
+ * @param method method to locate a mapping for
+ * @param lazyRemap in general, if a mapping is not located, an attempt will
+ * be made to remap the owner and descriptor of the method to account
+ * for the fact that classes appearing in the descriptor may need to be
+ * remapped even if the method name is not. Setting lazyRemap
+ * to true disables this behaviour and simply fails fast if no
+ * mapping is located
+ * @return remapped method or null if no mapping exists
+ */
+ public abstract MappingMethod getObfMethod(MappingMethod method, boolean lazyRemap);
+
+ /**
+ * Get an obfuscation mapping for a field, returns null if no mapping
+ * exists for the specified field in this environment.
+ *
+ * @param field field to locate a mapping for
+ * @return remapped field or null if no mapping exists
+ */
+ public abstract MappingField getObfField(MemberInfo field);
+
+ /**
+ * Get an obfuscation mapping for a field, returns null if no mapping
+ * exists for the specified field in this environment.
+ *
+ * @param field field to locate a mapping for
+ * @return remapped field or null if no mapping exists
+ */
+ public abstract MappingField getObfField(MappingField field);
+
+ /**
+ * Get an obfuscation mapping for a field, returns null if no mapping
+ * exists for the specified field in this environment.
+ *
+ * @param field field to locate a mapping for
+ * @param lazyRemap in general, if a mapping is not located, an attempt will
+ * be made to remap the owner and descriptor of the field to account
+ * for the fact that classes appearing in the descriptor may need to be
+ * remapped even if the field name is not. Setting lazyRemap
+ * to true disables this behaviour and simply fails fast if no
+ * mapping is located
+ * @return remapped field or null if no mapping exists
+ */
+ public abstract MappingField getObfField(MappingField field, boolean lazyRemap);
+
+ /**
+ * Get an obfuscation mapping for a class, returns null if no mapping exists
+ * for the specified class in this environment.
+ *
+ * @param className Name of the class to remap (binary format)
+ * @return remapped class name
+ */
+ public abstract String getObfClass(String className);
+
+ /**
+ * Remap only the owner and descriptor of the specified method
+ *
+ * @param method method to remap
+ * @return remapped method or null if no remapping occurred
+ */
+ public abstract MemberInfo remapDescriptor(MemberInfo method);
+
+ /**
+ * Remap a single descriptor in the context of this environment
+ *
+ * @param desc descriptor to remap
+ * @return remapped descriptor, may return the original descriptor if no
+ * remapping occurred
+ */
+ public abstract String remapDescriptor(String desc);
+
+ /**
+ * Write out accumulated mappings
+ *
+ * @param consumers all consumers accumulated during the AP pass
+ */
+ public abstract void writeMappings(Collection consumers);
+
+}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java
index d439522d..296c0707 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java
@@ -67,6 +67,6 @@ public interface IObfuscationManager {
/**
* Write out generated refmap
*/
- void writeReferences();
+ public abstract void writeReferences();
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/mapping/IMappingProvider.java b/src/ap/java/org/spongepowered/tools/obfuscation/mapping/IMappingProvider.java
index 1bcf81e7..dabc9a89 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/mapping/IMappingProvider.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/mapping/IMappingProvider.java
@@ -31,7 +31,11 @@ import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
/**
- * A mapping provider supplies mapping information to the AP
+ * A mapping provider stores raw mapping information for use by the AP, access
+ * is delegated via the environment which provides enhanced lookup functionality
+ * such as resolving members recursively in super classes. The mapping provider
+ * is not required to provide such functionality and merely facilitates raw
+ * mapping lookups from a particular source.
*/
public interface IMappingProvider {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java
index adc746c9..e88d6409 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java
@@ -266,7 +266,7 @@ public class MemberInfo {
throw new MixinException("Cannot convert a non-method reference " + this + " to MethodMapping");
}
- return new MappingMethod(this.owner + "/" + this.name, this.desc);
+ return new MappingMethod(this.owner, this.name, this.desc);
}
public MappingField asFieldMapping() {
diff --git a/src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java b/src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java
index 81199606..840ed33d 100644
--- a/src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java
+++ b/src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java
@@ -176,10 +176,11 @@ public final class ReferenceMapper implements Serializable {
* @param className Class which owns this mapping, cannot be null
* @param reference Reference to remap, cannot be null
* @param newReference Remapped value, cannot be null
+ * @return replaced value, per the contract of {@link Map#put}
*/
- public void addMapping(String context, String className, String reference, String newReference) {
+ public String addMapping(String context, String className, String reference, String newReference) {
if (this.readOnly || reference == null || newReference == null || reference.equals(newReference)) {
- return;
+ return null;
}
Map> mappings = this.mappings;
if (context != null) {
@@ -194,7 +195,7 @@ public final class ReferenceMapper implements Serializable {
classMappings = new HashMap();
mappings.put(className, classMappings);
}
- classMappings.put(reference, newReference);
+ return classMappings.put(reference, newReference);
}
/**
diff --git a/src/main/java/org/spongepowered/asm/obfuscation/mapping/IMapping.java b/src/main/java/org/spongepowered/asm/obfuscation/mapping/IMapping.java
index f4b1b268..319dd8eb 100644
--- a/src/main/java/org/spongepowered/asm/obfuscation/mapping/IMapping.java
+++ b/src/main/java/org/spongepowered/asm/obfuscation/mapping/IMapping.java
@@ -41,24 +41,82 @@ public interface IMapping {
PACKAGE
}
+ /**
+ * Get the mapping type (field, method, class, package)
+ */
public abstract Type getType();
+ /**
+ * Create a clone of this mapping with a new owner
+ *
+ * @param newOwner new owner
+ * @return cloned mapping
+ */
public abstract TMapping move(String newOwner);
+ /**
+ * Create a clone of this mapping with a new name
+ *
+ * @param newName new name
+ * @return cloned mapping
+ */
public abstract TMapping remap(String newName);
+ /**
+ * Create a clone of this mapping with a new descriptor
+ *
+ * @param newDesc new descriptor
+ * @return cloned mapping
+ */
public abstract TMapping transform(String newDesc);
+ /**
+ * Create a clone of this mapping
+ *
+ * @return cloned mapping
+ */
public abstract TMapping copy();
+ /**
+ * Get the mapping name, for method mappings this includes the owner
+ *
+ * @return the mapping name, includes the owner for method mappings
+ */
public abstract String getName();
+ /**
+ * Get the base name of this member, for example the bare field, method or
+ * class name
+ *
+ * @return the base name of this mapping
+ */
public abstract String getSimpleName();
+ /**
+ * Get the owner of this member, for fields and methods this is the class
+ * name, for classes it is the package name, for packages it is undefined.
+ * Can return null.
+ *
+ * @return the parent of this mapping
+ */
public abstract String getOwner();
+ /**
+ * Get the descriptor of this member, for example the method descriptor or
+ * field type. For classes and packages this is undefined. Can return null
+ * since not all mapping types support descriptors.
+ *
+ * @return the mapping descriptor
+ */
public abstract String getDesc();
+ /**
+ * Get a representation of this mapping for serialisation. Individual
+ * writers are free to use their own mappings, this method is for
+ * convenience only.
+ *
+ * @return string representation of this mapping
+ */
public abstract String serialise();
}
diff --git a/src/main/java/org/spongepowered/asm/obfuscation/mapping/common/MappingMethod.java b/src/main/java/org/spongepowered/asm/obfuscation/mapping/common/MappingMethod.java
index 2525eb57..051925ca 100644
--- a/src/main/java/org/spongepowered/asm/obfuscation/mapping/common/MappingMethod.java
+++ b/src/main/java/org/spongepowered/asm/obfuscation/mapping/common/MappingMethod.java
@@ -33,16 +33,17 @@ import com.google.common.base.Objects;
*/
public class MappingMethod implements IMapping {
+ private final String owner;
private final String name;
private final String desc;
- public MappingMethod(String name, String desc) {
- this.name = name;
- this.desc = desc;
+ public MappingMethod(String fullyQualifiedName, String desc) {
+ this(MappingMethod.getOwnerFromName(fullyQualifiedName), MappingMethod.getBaseName(fullyQualifiedName), desc);
}
-
+
public MappingMethod(String owner, String simpleName, String desc) {
- this.name = MappingMethod.createName(owner, simpleName);
+ this.owner = owner;
+ this.name = simpleName;
this.desc = desc;
}
@@ -53,25 +54,20 @@ public class MappingMethod implements IMapping {
@Override
public String getName() {
- return this.name;
+ if (this.name == null) {
+ return null;
+ }
+ return (this.owner != null ? this.owner + "/" : "") + this.name;
}
@Override
public String getSimpleName() {
- if (this.name == null) {
- return null;
- }
- int pos = this.name.lastIndexOf('/');
- return pos > -1 ? this.name.substring(pos + 1) : this.name;
+ return this.name;
}
@Override
public String getOwner() {
- if (this.name == null) {
- return null;
- }
- int pos = this.name.lastIndexOf('/');
- return pos > -1 ? this.name.substring(0, pos) : null;
+ return this.owner;
}
@Override
@@ -91,12 +87,12 @@ public class MappingMethod implements IMapping {
@Override
public MappingMethod transform(String newDesc) {
- return new MappingMethod(this.getName(), newDesc);
+ return new MappingMethod(this.getOwner(), this.getSimpleName(), newDesc);
}
@Override
public MappingMethod copy() {
- return new MappingMethod(this.getName(), this.getDesc());
+ return new MappingMethod(this.getOwner(), this.getSimpleName(), this.getDesc());
}
@Override
@@ -122,11 +118,23 @@ public class MappingMethod implements IMapping {
@Override
public String toString() {
- return String.format("%s %s", this.name, this.desc);
+ return String.format("%s %s", this.getName(), this.getDesc());
}
- private static String createName(String owner, String simpleName) {
- return (owner != null ? owner + "/" : "") + simpleName;
+ private static String getBaseName(String name) {
+ if (name == null) {
+ return null;
+ }
+ int pos = name.lastIndexOf('/');
+ return pos > -1 ? name.substring(pos + 1) : name;
+ }
+
+ private static String getOwnerFromName(String name) {
+ if (name == null) {
+ return null;
+ }
+ int pos = name.lastIndexOf('/');
+ return pos > -1 ? name.substring(0, pos) : null;
}
}