Resolve obf mappings in interfaces as well as superclasses, fixes #171

This commit is contained in:
Mumfrey committed 2017-03-20 13:05:29 +00:00
1 parent 5accc9e81b
commit 4b7b5a05f4
5 files changed
+71 -20

No files matched your search

@@ -469,7 +469,7 @@ abstract class AnnotatedMixinElementHandler {
ObfuscationData<T> stripped = new ObfuscationData<T>();
for (ObfuscationType type : data) {
T mapping = data.get(type);
stripped.add(type, mapping.move(null));
stripped.put(type, mapping.move(null));
}
return stripped;
}
@@ -248,9 +248,9 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
for (ObfuscationType type : remapped) {
MappingMethod mapping = remapped.get(type);
if (desc == null) {
mappings.add(type, mapping.getOwner());
mappings.put(type, mapping.getOwner());
} else {
mappings.add(type, mapping.getDesc().replace(")V", ")L" + mapping.getOwner() + ";"));
mappings.put(type, mapping.getDesc().replace(")V", ")L" + mapping.getOwner() + ";"));
}
}
@@ -176,7 +176,7 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
ObfuscationData<MappingMethod> prefixed = new ObfuscationData<MappingMethod>();
for (ObfuscationType type : data) {
MappingMethod mapping = data.get(type);
prefixed.add(type, mapping.addPrefix(prefix));
prefixed.put(type, mapping.addPrefix(prefix));
}
return prefixed;
}
@@ -67,12 +67,27 @@ public class ObfuscationData<T> implements Iterable<ObfuscationType> {
}
/**
* Add an entry to the map
* Add an entry to the map, overwrites any previous entries. Since this
* method name poorly communicates its purpose, it is deprecated in favour
* of {@link #put}.
*
* @param type obfuscation type
* @param value new entry
*
* @deprecated Use {@link #put} instead
*/
@Deprecated
public void add(ObfuscationType type, T value) {
this.put(type, value);
}
/**
* Put an entry into this map, replaces any existing entries.
*
* @param type obfuscation type
* @param value entry
*/
public void put(ObfuscationType type, T value) {
this.data.put(type, value);
}
@@ -63,7 +63,6 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
*/
@Override
@SuppressWarnings("unchecked")
public <T> ObfuscationData<T> getObfEntryRecursive(final MemberInfo targetMember) {
MemberInfo currentTarget = targetMember;
ObfuscationData<String> obfTargetNames = this.getObfClass(currentTarget.owner);
@@ -74,19 +73,25 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
if (targetType == null) {
return obfData;
}
TypeHandle superClass = targetType.getSuperclass();
if (superClass == null) {
return obfData;
}
currentTarget = currentTarget.move(superClass.getName());
obfData = this.getObfEntry(currentTarget);
obfData = this.<T>getObfEntryUsing(currentTarget, superClass);
if (!obfData.isEmpty()) {
for (ObfuscationType type : obfData) {
String obfClass = obfTargetNames.get(type);
T obfMember = obfData.get(type);
obfData.add(type, (T)MemberInfo.fromMapping((IMapping<?>)obfMember).move(obfClass).asMapping());
return ObfuscationDataProvider.applyParents(obfTargetNames, obfData);
}
for (TypeHandle iface : targetType.getInterfaces()) {
obfData = this.<T>getObfEntryUsing(currentTarget, iface);
if (!obfData.isEmpty()) {
return ObfuscationDataProvider.applyParents(obfTargetNames, obfData);
}
}
if (superClass == null) {
break;
}
currentTarget = currentTarget.move(superClass.getName());
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -95,6 +100,20 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
return obfData;
}
/**
* Returns an obf entry for the specified member relocated into the
* specified target class. This is used by {@link #getObfEntryRecursive} to
* searh for matching obf entries in super classes an interfaces.
*
* @param targetMember target member to search for
* @param targetClass new target class to check, if the supplied argument is
* <tt>null</tt> then an empty dataset is returned
* @return obfuscation data for the relocated member
*/
private <T> ObfuscationData<T> getObfEntryUsing(MemberInfo targetMember, TypeHandle targetClass) {
return targetClass == null ? new ObfuscationData<T>() : this.<T>getObfEntry(targetMember.move(targetClass.getName()));
}
/* (non-Javadoc)
* @see org.spongepowered.tools.obfuscation.IObfuscationManager
* #getObfEntry(
@@ -154,7 +173,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
for (ObfuscationEnvironment env : this.environments) {
MappingMethod obfMethod = env.getObfMethod(method);
if (obfMethod != null) {
data.add(env.getType(), obfMethod);
data.put(env.getType(), obfMethod);
}
}
@@ -186,7 +205,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
for (ObfuscationEnvironment env : this.environments) {
MappingMethod obfMethod = env.getObfMethod(method);
if (obfMethod != null) {
data.add(env.getType(), obfMethod);
data.put(env.getType(), obfMethod);
}
}
@@ -208,7 +227,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
for (ObfuscationEnvironment env : this.environments) {
MemberInfo obfMethod = env.remapDescriptor(method);
if (obfMethod != null) {
data.add(env.getType(), obfMethod.asMethodMapping());
data.put(env.getType(), obfMethod.asMethodMapping());
}
}
@@ -248,7 +267,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
if (obfField.getDesc() == null && field.getDesc() != null) {
obfField = obfField.transform(env.remapDescriptor(field.getDesc()));
}
data.add(env.getType(), obfField);
data.put(env.getType(), obfField);
}
}
@@ -275,11 +294,28 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
for (ObfuscationEnvironment env : this.environments) {
String obfClass = env.getObfClass(className);
if (obfClass != null) {
data.add(env.getType(), obfClass);
data.put(env.getType(), obfClass);
}
}
return data;
}
/**
* Applies the supplied parent names to the supplied
*
* @param parents parent class names
* @param members members to reparent
* @return members for passthrough
*/
@SuppressWarnings("unchecked")
private static <T> ObfuscationData<T> applyParents(ObfuscationData<String> parents, ObfuscationData<T> members) {
for (ObfuscationType type : members) {
String obfClass = parents.get(type);
T obfMember = members.get(type);
members.put(type, (T)MemberInfo.fromMapping((IMapping<?>)obfMember).move(obfClass).asMapping());
}
return members;
}
}