Search for method mappings in superclasses during AP run, closes #33

This commit is contained in:
Mumfrey committed 2015-03-30 23:21:12 +01:00
1 parent a012596e98
commit fae89c3eb7
3 files changed
+55 -3

No files matched your search

@@ -468,14 +468,14 @@ class AnnotatedMixin {
}
remappedReference = MemberInfo.fromSrgField(obfField, targetMember.desc);
} else {
MethodData obfMethod = this.mixins.getObfMethod(targetMember.asMethodData());
MethodData obfMethod = this.mixins.getObfMethod(targetMember);
if (obfMethod == null) {
if (targetMember.owner == null || !targetMember.owner.startsWith("java/lang/")) {
this.mixins.printMessage(Kind.WARNING, "Cannot find method mapping for @At(" + key + ") '" + target + "'", element, inject);
}
return;
}
remappedReference = MemberInfo.fromSrgMethod(obfMethod);
remappedReference = targetMember.remapUsing(obfMethod, false);
}
this.mixins.getReferenceMapper().addMapping(this.classRef, target, remappedReference.toString());
@@ -46,6 +46,7 @@ import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
@@ -53,6 +54,7 @@ import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.tools.MirrorUtils;
import org.spongepowered.tools.obfuscation.IMixinValidator.ValidationPass;
@@ -524,6 +526,32 @@ class AnnotatedMixins implements Messager {
return null;
}
/**
* Get an obfuscation mapping for a method
*/
public MethodData getObfMethod(MemberInfo method) {
MethodData obfd = this.getObfMethod(method.asMethodData());
if (obfd != null || !method.isFullyQualified()) {
return obfd;
}
// Get a type handle for the declared method owner
TypeHandle type = this.getTypeHandle(method.owner);
if (type.isImaginary()) {
return null;
}
// See if we can get the superclass from the reference
TypeMirror superClass = type.getElement().getSuperclass();
if (superClass.getKind() != TypeKind.DECLARED) {
return null;
}
// Well we found it, let's inflect the class name and recurse the search
String superClassName = ((TypeElement)((DeclaredType)superClass).asElement()).getQualifiedName().toString();
return this.getObfMethod(new MemberInfo(method.name, superClassName.replace('.', '/'), method.desc, method.matchAll));
}
/**
* Get an obfuscation mapping for a method
@@ -167,13 +167,26 @@ public class MemberInfo {
*
* @param methodData MethodData object to copy values from
*/
public MemberInfo(MethodData methodData) {
private MemberInfo(MethodData methodData) {
int slashPos = methodData.name.lastIndexOf('/');
this.owner = methodData.name.substring(0, slashPos);
this.name = methodData.name.substring(slashPos + 1);
this.desc = methodData.sig;
this.matchAll = false;
}
/**
* Initialise a remapped MemberInfo using the supplied MethodData object
*
* @param methodData MethodData object to copy values from
*/
private MemberInfo(MemberInfo remapped, MethodData methodData, boolean setOwner) {
int slashPos = methodData.name.lastIndexOf('/');
this.owner = setOwner ? methodData.name.substring(0, slashPos) : remapped.owner;
this.name = methodData.name.substring(slashPos + 1);
this.desc = remapped.desc;
this.matchAll = false;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
@@ -305,6 +318,17 @@ public class MemberInfo {
&& (ordinal == 0 || this.matchAll);
}
/**
* Create a remapped version of this member using the supplied method data
*
* @param methodData Method data to use
* @param setOwner True to set the owner as well as the name
* @return New MethodInfo with remapped values
*/
public MemberInfo remapUsing(MethodData methodData, boolean setOwner) {
return new MemberInfo(this, methodData, setOwner);
}
/**
* Parse a MemberInfo from a string
*