mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-24 00:09:48 +00:00
Version 0.8-preview
Add initial modlauncher support Bump ASM version and remove renamed ASM for modlauncher interop Conform static accessor target when transforming accessor, Fixes #342 Detect staticness mismatch on accessors, Fixes #341 Allow Invoker to invoke constructors, Closes #339 Remove commons-io and replace with guava, Fixes #327 Fix refmap generation for non-obfuscated derived classes, Fixes #326 Specify locale for case conversions, Fixes #315 Handle accessor overlap more intelligently, Fixes #307 Add SuppressWarnings support to Annotation Processor, Closes #306 Allow mixins applied to a class to be retrieved easily, Closes #302 Conform refmap entries as they are added to the mapper, fixes #296 Fold in misc lvt generation fixes from fabricmc, closes #295 Fail fast when final method is accidentally hidden by mixin, fixes #293 Fix bug handling 2-slot args in cb injector and args gen, fixes #287 Handle accessor mixin types correctly in mixins, Fixes #305, Fixes #288
This commit is contained in:
1 parent
ab935e061f
commit
fd2f2c79c5
246 files changed
+10899
-3125
No files matched your search
@@ -33,7 +33,8 @@ import javax.lang.model.element.VariableElement;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
@@ -373,7 +374,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), method, annotation.asMirror());
|
||||
}
|
||||
} catch (InvalidConstraintException ex) {
|
||||
this.ap.printMessage(Kind.WARNING, ex.getMessage(), method, annotation.asMirror());
|
||||
this.ap.printMessage(Kind.WARNING, ex.getMessage(), method, annotation.asMirror(), "constraints");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +421,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
this.validateMethodVisibility(method, annotation, type, target, targetMethod);
|
||||
}
|
||||
} else if (!merge) {
|
||||
this.printMessage(Kind.WARNING, "Cannot find target for " + type + " method in " + target, method, annotation);
|
||||
this.printMessage(Kind.WARNING, "Cannot find target for " + type + " method in " + target, method, annotation, "target");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,9 +436,9 @@ abstract class AnnotatedMixinElementHandler {
|
||||
Visibility visMethod = TypeUtils.getVisibility(method);
|
||||
String visibility = "visibility of " + visTarget + " method in " + target;
|
||||
if (visTarget.ordinal() > visMethod.ordinal()) {
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation);
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation, "visibility");
|
||||
} else if (visTarget == Visibility.PRIVATE && visMethod.ordinal() > visTarget.ordinal()) {
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation);
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation, "visibility");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +469,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
}
|
||||
|
||||
if (targetField == null) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, annotation.asMirror());
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, annotation.asMirror(), "target");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,26 +478,35 @@ abstract class AnnotatedMixinElementHandler {
|
||||
* Checks whether the referenced method exists in all targets and raises
|
||||
* warnings where appropriate
|
||||
*/
|
||||
protected final void validateReferencedTarget(ExecutableElement method, AnnotationHandle inject, MemberInfo reference, String type) {
|
||||
String signature = reference.toDescriptor();
|
||||
protected final void validateReferencedTarget(ExecutableElement method, AnnotationHandle inject, ITargetSelector reference, String type) {
|
||||
if (!(reference instanceof ITargetSelectorByName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ITargetSelectorByName nameRef = (ITargetSelectorByName)reference;
|
||||
String signature = nameRef.toDescriptor();
|
||||
|
||||
for (TypeHandle target : this.mixin.getTargets()) {
|
||||
if (target.isImaginary()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MethodHandle targetMethod = target.findMethod(reference.name, signature);
|
||||
MethodHandle targetMethod = target.findMethod(nameRef.getName(), signature);
|
||||
if (targetMethod == null) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target method for " + type + " in " + target, method, inject.asMirror());
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target method for " + type + " in " + target, method, inject.asMirror(), "target");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation) {
|
||||
this.printMessage(kind, msg, e, annotation, null);
|
||||
}
|
||||
|
||||
private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation, String suppressedBy) {
|
||||
if (annotation == null) {
|
||||
this.ap.printMessage(kind, msg, e);
|
||||
this.ap.printMessage(kind, msg, e, suppressedBy);
|
||||
} else {
|
||||
this.ap.printMessage(kind, msg, e, annotation.asMirror());
|
||||
this.ap.printMessage(kind, msg, e, annotation.asMirror(), suppressedBy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+83
-7
@@ -25,15 +25,18 @@
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.gen.AccessorInfo;
|
||||
import org.spongepowered.asm.mixin.gen.AccessorInfo.AccessorName;
|
||||
import org.spongepowered.asm.mixin.gen.AccessorInfo.AccessorType;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
@@ -41,6 +44,7 @@ import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
|
||||
@@ -61,11 +65,11 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
*/
|
||||
static class AnnotatedElementAccessor extends AnnotatedElement<ExecutableElement> {
|
||||
|
||||
private final boolean shouldRemap;
|
||||
protected final boolean shouldRemap;
|
||||
|
||||
private final TypeMirror returnType;
|
||||
protected final TypeMirror returnType;
|
||||
|
||||
private String targetName;
|
||||
protected String targetName;
|
||||
|
||||
public AnnotatedElementAccessor(ExecutableElement element, AnnotationHandle annotation, boolean shouldRemap) {
|
||||
super(element, annotation);
|
||||
@@ -73,6 +77,9 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
this.returnType = this.getElement().getReturnType();
|
||||
}
|
||||
|
||||
public void attach(TypeHandle target) {
|
||||
}
|
||||
|
||||
public boolean shouldRemap() {
|
||||
return this.shouldRemap;
|
||||
}
|
||||
@@ -100,7 +107,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
return TypeUtils.getInternalName(this.getTargetType());
|
||||
}
|
||||
|
||||
public MemberInfo getContext() {
|
||||
public ITargetSelectorRemappable getContext() {
|
||||
return new MemberInfo(this.getTargetName(), null, this.getAccessorDesc());
|
||||
}
|
||||
|
||||
@@ -115,21 +122,66 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
public String getTargetName() {
|
||||
return this.targetName;
|
||||
}
|
||||
|
||||
public TypeMirror getReturnType() {
|
||||
return this.returnType;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return this.element.getModifiers().contains(Modifier.STATIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.targetName != null ? this.targetName : "<invalid>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoker element
|
||||
*/
|
||||
static class AnnotatedElementInvoker extends AnnotatedElementAccessor {
|
||||
|
||||
private AccessorType type = AccessorType.METHOD_PROXY;
|
||||
|
||||
public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation, boolean shouldRemap) {
|
||||
super(element, annotation, shouldRemap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attach(TypeHandle target) {
|
||||
this.type = AccessorType.METHOD_PROXY;
|
||||
if (this.returnType.getKind() != TypeKind.DECLARED) {
|
||||
return;
|
||||
}
|
||||
|
||||
String specifiedName = this.getAnnotationValue();
|
||||
if (specifiedName != null) {
|
||||
if (Constants.CTOR.equals(specifiedName) || target.getName().equals(specifiedName.replace('.', '/'))) {
|
||||
this.type = AccessorType.OBJECT_FACTORY;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
AccessorName accessorName = AccessorName.of(this.getSimpleName(), false);
|
||||
if (accessorName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String prefix : AccessorType.OBJECT_FACTORY.getExpectedPrefixes()) {
|
||||
if (prefix.equals(accessorName.prefix)
|
||||
&& (Constants.CTOR.equals(accessorName.name) || target.getSimpleName().equals(accessorName.name))) {
|
||||
this.type = AccessorType.OBJECT_FACTORY;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRemap() {
|
||||
return (this.type == AccessorType.METHOD_PROXY || this.getAnnotationValue() != null) && super.shouldRemap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessorDesc() {
|
||||
@@ -138,7 +190,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
|
||||
@Override
|
||||
public AccessorType getAccessorType() {
|
||||
return AccessorType.METHOD_PROXY;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,7 +268,15 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
elem.setTargetName(targetName);
|
||||
|
||||
for (TypeHandle target : this.mixin.getTargets()) {
|
||||
if (elem.getAccessorType() == AccessorType.METHOD_PROXY) {
|
||||
try {
|
||||
elem.attach(target);
|
||||
} catch (Exception ex) {
|
||||
elem.printMessage(this.ap, Kind.ERROR, ex.getMessage());
|
||||
continue;
|
||||
}
|
||||
if (elem.getAccessorType() == AccessorType.OBJECT_FACTORY) {
|
||||
this.registerFactoryForTarget((AnnotatedElementInvoker)elem, target);
|
||||
} else if (elem.getAccessorType() == AccessorType.METHOD_PROXY) {
|
||||
this.registerInvokerForTarget((AnnotatedElementInvoker)elem, target);
|
||||
} else {
|
||||
this.registerAccessorForTarget(elem, target);
|
||||
@@ -288,6 +348,22 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
}
|
||||
}
|
||||
|
||||
private void registerFactoryForTarget(AnnotatedElementInvoker elem, TypeHandle target) {
|
||||
if (!elem.getReturnType().equals(target.getType())) {
|
||||
throw new RuntimeException("Invalid Factory @Invoker return type, expected " + target.getType());
|
||||
}
|
||||
if (!elem.isStatic()) {
|
||||
throw new RuntimeException("Factory @Invoker must be static");
|
||||
}
|
||||
|
||||
if (!elem.shouldRemap()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ObfuscationData<String> obfData = this.obf.getDataProvider().getObfClass(elem.getAnnotationValue().replace('.', '/'));
|
||||
this.obf.getReferenceManager().addClassMapping(this.mixin.getClassRef(), elem.getAnnotationValue(), obfData);
|
||||
}
|
||||
|
||||
private String getAccessorTargetName(AnnotatedElementAccessor elem) {
|
||||
String value = elem.getAnnotationValue();
|
||||
if (Strings.isNullOrEmpty(value)) {
|
||||
|
||||
+65
-45
@@ -35,9 +35,13 @@ import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorConstructor;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
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.ReferenceManager.ReferenceConflictException;
|
||||
@@ -152,18 +156,24 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
}
|
||||
|
||||
for (String reference : elem.getAnnotation().<String>getList("method")) {
|
||||
MemberInfo targetMember = MemberInfo.parse(reference);
|
||||
if (targetMember.name == null) {
|
||||
continue;
|
||||
}
|
||||
ITargetSelector targetSelector = TargetSelector.parse(reference);
|
||||
|
||||
try {
|
||||
targetMember.validate();
|
||||
targetSelector.validate();
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
elem.printMessage(this.ap, Kind.ERROR, ex.getMessage());
|
||||
}
|
||||
|
||||
if (!(targetSelector instanceof ITargetSelectorRemappable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetMember.desc != null) {
|
||||
ITargetSelectorRemappable targetMember = (ITargetSelectorRemappable)targetSelector;
|
||||
if (targetMember.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetMember.getDesc() != null) {
|
||||
this.validateReferencedTarget(elem.getElement(), elem.getAnnotation(), targetMember, elem.toString());
|
||||
}
|
||||
|
||||
@@ -179,7 +189,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
}
|
||||
}
|
||||
|
||||
private boolean registerInjector(AnnotatedElementInjector elem, String reference, MemberInfo targetMember, TypeHandle target) {
|
||||
private boolean registerInjector(AnnotatedElementInjector elem, String reference, ITargetSelectorRemappable targetMember, TypeHandle target) {
|
||||
String desc = target.findDescriptor(targetMember);
|
||||
if (desc == null) {
|
||||
Kind error = this.mixin.isMultiTarget() ? Kind.ERROR : Kind.WARNING;
|
||||
@@ -194,8 +204,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
String targetName = elem + " target " + targetMember.name;
|
||||
MappingMethod targetMethod = target.getMappingMethod(targetMember.name, desc);
|
||||
String targetName = elem + " target " + targetMember.getName();
|
||||
MappingMethod targetMethod = target.getMappingMethod(targetMember.getName(), desc);
|
||||
ObfuscationData<MappingMethod> obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
|
||||
if (obfData.isEmpty()) {
|
||||
if (target.isSimulated()) {
|
||||
@@ -212,17 +222,19 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
IReferenceManager refMap = this.obf.getReferenceManager();
|
||||
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()) || target.isSimulated()) {
|
||||
if ((targetMember.getOwner() == null && this.mixin.isMultiTarget()) || target.isSimulated()) {
|
||||
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripOwnerData(obfData);
|
||||
}
|
||||
refMap.addMethodMapping(this.classRef, reference, obfData);
|
||||
} catch (ReferenceConflictException ex) {
|
||||
String conflictType = this.mixin.isMultiTarget() ? "Multi-target" : "Target";
|
||||
|
||||
if (elem.hasCoerceArgument() && targetMember.owner == null && targetMember.desc == null) {
|
||||
MemberInfo oldMember = MemberInfo.parse(ex.getOld());
|
||||
MemberInfo newMember = MemberInfo.parse(ex.getNew());
|
||||
if (oldMember.name.equals(newMember.name)) {
|
||||
if (elem.hasCoerceArgument() && targetMember.getOwner() == null && targetMember.getDesc() == null) {
|
||||
ITargetSelector oldMember = TargetSelector.parse(ex.getOld());
|
||||
ITargetSelector newMember = TargetSelector.parse(ex.getNew());
|
||||
String oldName = oldMember instanceof ITargetSelectorByName ? ((ITargetSelectorByName)oldMember).getName() : oldMember.toString();
|
||||
String newName = newMember instanceof ITargetSelectorByName ? ((ITargetSelectorByName)newMember).getName() : newMember.toString();
|
||||
if (oldName != null && oldName.equals(newName)) {
|
||||
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripDescriptors(obfData);
|
||||
refMap.setAllowConflicts(true);
|
||||
refMap.addMethodMapping(this.classRef, reference, obfData);
|
||||
@@ -271,31 +283,34 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
return;
|
||||
}
|
||||
|
||||
MemberInfo member = MemberInfo.parse(reference);
|
||||
String target = member.toCtorType();
|
||||
|
||||
if (target != null) {
|
||||
String desc = member.toCtorDesc();
|
||||
MappingMethod m = new MappingMethod(target, ".", desc != null ? desc : "()V");
|
||||
ObfuscationData<MappingMethod> remapped = this.obf.getDataProvider().getRemappedMethod(m);
|
||||
if (remapped.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find class mapping for " + subject + " '" + target + "'", elem.getElement(),
|
||||
elem.getAnnotation().asMirror());
|
||||
return;
|
||||
}
|
||||
|
||||
ObfuscationData<String> mappings = new ObfuscationData<String>();
|
||||
for (ObfuscationType type : remapped) {
|
||||
MappingMethod mapping = remapped.get(type);
|
||||
if (desc == null) {
|
||||
mappings.put(type, mapping.getOwner());
|
||||
} else {
|
||||
mappings.put(type, mapping.getDesc().replace(")V", ")L" + mapping.getOwner() + ";"));
|
||||
}
|
||||
}
|
||||
ITargetSelector selector = TargetSelector.parse(reference);
|
||||
if (selector instanceof ITargetSelectorConstructor) {
|
||||
ITargetSelectorConstructor member = (ITargetSelectorConstructor)selector;
|
||||
String target = member.toCtorType();
|
||||
|
||||
this.obf.getReferenceManager().addClassMapping(this.classRef, reference, mappings);
|
||||
}
|
||||
if (target != null) {
|
||||
String desc = member.toCtorDesc();
|
||||
MappingMethod m = new MappingMethod(target, ".", desc != null ? desc : "()V");
|
||||
ObfuscationData<MappingMethod> remapped = this.obf.getDataProvider().getRemappedMethod(m);
|
||||
if (remapped.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find class mapping for " + subject + " '" + target + "'", elem.getElement(),
|
||||
elem.getAnnotation().asMirror(), "mapping");
|
||||
return;
|
||||
}
|
||||
|
||||
ObfuscationData<String> mappings = new ObfuscationData<String>();
|
||||
for (ObfuscationType type : remapped) {
|
||||
MappingMethod mapping = remapped.get(type);
|
||||
if (desc == null) {
|
||||
mappings.put(type, mapping.getOwner());
|
||||
} else {
|
||||
mappings.put(type, mapping.getDesc().replace(")V", ")L" + mapping.getOwner() + ";"));
|
||||
}
|
||||
}
|
||||
|
||||
this.obf.getReferenceManager().addClassMapping(this.classRef, reference, mappings);
|
||||
}
|
||||
}
|
||||
|
||||
elem.notifyRemapped();
|
||||
}
|
||||
@@ -304,13 +319,18 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
if (reference == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ITargetSelector targetSelector = TargetSelector.parse(reference);
|
||||
if (!(targetSelector instanceof ITargetSelectorRemappable)) {
|
||||
return;
|
||||
}
|
||||
ITargetSelectorRemappable targetMember = (ITargetSelectorRemappable)targetSelector;
|
||||
|
||||
// JDT supports hanging the error on the @At annotation directly, doing this in javac doesn't work
|
||||
AnnotationMirror errorsOn = (this.ap.getCompilerEnvironment() == CompilerEnvironment.JDT ? elem.getAt() : elem.getAnnotation()).asMirror();
|
||||
|
||||
MemberInfo targetMember = MemberInfo.parse(reference);
|
||||
if (!targetMember.isFullyQualified()) {
|
||||
String missing = targetMember.owner == null ? (targetMember.desc == null ? "owner and signature" : "owner") : "signature";
|
||||
String missing = targetMember.getOwner() == null ? (targetMember.getDesc() == null ? "owner and signature" : "owner") : "signature";
|
||||
this.ap.printMessage(Kind.ERROR, subject + " is not fully qualified, missing " + missing, elem.getElement(), errorsOn);
|
||||
return;
|
||||
}
|
||||
@@ -326,16 +346,16 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
ObfuscationData<MappingField> obfFieldData = this.obf.getDataProvider().getObfFieldRecursive(targetMember);
|
||||
if (obfFieldData.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn);
|
||||
errorsOn, "mapping");
|
||||
return;
|
||||
}
|
||||
this.obf.getReferenceManager().addFieldMapping(this.classRef, reference, targetMember, obfFieldData);
|
||||
} else {
|
||||
ObfuscationData<MappingMethod> obfMethodData = this.obf.getDataProvider().getObfMethodRecursive(targetMember);
|
||||
if (obfMethodData.isEmpty()) {
|
||||
if (targetMember.owner == null || !targetMember.owner.startsWith("java/lang/")) {
|
||||
if (targetMember.getOwner() == null || !targetMember.getOwner().startsWith("java/lang/")) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find method mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn);
|
||||
errorsOn, "mapping");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -25,6 +25,7 @@
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
@@ -85,16 +86,16 @@ class AnnotatedMixinElementHandlerOverwrite extends AnnotatedMixinElementHandler
|
||||
|
||||
String javadoc = this.ap.getJavadocProvider().getJavadoc(elem.getElement());
|
||||
if (javadoc == null) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", elem.getElement());
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", elem.getElement(), "overwrite");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!javadoc.toLowerCase().contains("@author")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", elem.getElement());
|
||||
if (!javadoc.toLowerCase(Locale.ROOT).contains("@author")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", elem.getElement(), "overwrite");
|
||||
}
|
||||
|
||||
if (!javadoc.toLowerCase().contains("@reason")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", elem.getElement());
|
||||
if (!javadoc.toLowerCase(Locale.ROOT).contains("@reason")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", elem.getElement(), "overwrite");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
@@ -79,7 +81,7 @@ class AnnotatedMixinElementHandlerShadow extends AnnotatedMixinElementHandler {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getElementType().name().toLowerCase();
|
||||
return this.getElementType().name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public ShadowElementName setObfuscatedName(IMapping<?> name) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -49,7 +50,6 @@ import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
@@ -74,6 +74,7 @@ import org.spongepowered.tools.obfuscation.validation.ParentValidator;
|
||||
import org.spongepowered.tools.obfuscation.validation.TargetValidator;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
/**
|
||||
* Mixin info manager, stores all of the mixin info during processing and also
|
||||
@@ -173,7 +174,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
if (tokens != null) {
|
||||
Pattern tokenPattern = Pattern.compile("^([A-Z0-9\\-_\\.]+)=([0-9]+)$");
|
||||
|
||||
String[] tokenValues = tokens.replaceAll("\\s", "").toUpperCase().split("[;,]");
|
||||
String[] tokenValues = tokens.replaceAll("\\s", "").toUpperCase(Locale.ROOT).split("[;,]");
|
||||
for (String tokenValue : tokenValues) {
|
||||
Matcher tokenMatcher = tokenPattern.matcher(tokenValue);
|
||||
if (tokenMatcher.matches()) {
|
||||
@@ -244,6 +245,24 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
|
||||
return this.getProperties().getProperty(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOption(String option, boolean defaultValue) {
|
||||
String value = this.getOption(option);
|
||||
return value != null ? Boolean.parseBoolean(value) : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOptions(String option) {
|
||||
Builder<String> list = ImmutableList.<String>builder();
|
||||
String value = this.getOption(option);
|
||||
if (value != null) {
|
||||
for (String part : value.split(",")) {
|
||||
list.add(part);
|
||||
}
|
||||
}
|
||||
return list.build();
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
if (this.properties == null) {
|
||||
@@ -354,7 +373,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
}
|
||||
|
||||
AnnotationHandle accessor = AnnotationHandle.of(method, Accessor.class);
|
||||
mixinClass.registerAccessor(method, accessor, this.shouldRemap(mixinClass, accessor));
|
||||
mixinClass.registerAccessor(method, accessor, AnnotatedMixins.shouldRemap(mixinClass, accessor));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,7 +390,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
}
|
||||
|
||||
AnnotationHandle invoker = AnnotationHandle.of(method, Invoker.class);
|
||||
mixinClass.registerInvoker(method, invoker, this.shouldRemap(mixinClass, invoker));
|
||||
mixinClass.registerInvoker(method, invoker, AnnotatedMixins.shouldRemap(mixinClass, invoker));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +407,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
}
|
||||
|
||||
AnnotationHandle overwrite = AnnotationHandle.of(method, Overwrite.class);
|
||||
mixinClass.registerOverwrite(method, overwrite, this.shouldRemap(mixinClass, overwrite));
|
||||
mixinClass.registerOverwrite(method, overwrite, AnnotatedMixins.shouldRemap(mixinClass, overwrite));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,7 +424,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
return;
|
||||
}
|
||||
|
||||
mixinClass.registerShadow(field, shadow, this.shouldRemap(mixinClass, shadow));
|
||||
mixinClass.registerShadow(field, shadow, AnnotatedMixins.shouldRemap(mixinClass, shadow));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,7 +441,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
return;
|
||||
}
|
||||
|
||||
mixinClass.registerShadow(method, shadow, this.shouldRemap(mixinClass, shadow));
|
||||
mixinClass.registerShadow(method, shadow, AnnotatedMixins.shouldRemap(mixinClass, shadow));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,7 +459,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
return;
|
||||
}
|
||||
|
||||
InjectorRemap remap = new InjectorRemap(this.shouldRemap(mixinClass, inject));
|
||||
InjectorRemap remap = new InjectorRemap(AnnotatedMixins.shouldRemap(mixinClass, inject));
|
||||
mixinClass.registerInjector(method, inject, remap);
|
||||
remap.dispatchPendingMessages(this);
|
||||
}
|
||||
@@ -484,15 +503,25 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldRemap(AnnotatedMixin mixinClass, AnnotationHandle annotation) {
|
||||
private static boolean shouldRemap(AnnotatedMixin mixinClass, AnnotationHandle annotation) {
|
||||
return annotation.getBoolean("remap", mixinClass.remap());
|
||||
}
|
||||
|
||||
private static boolean shouldSuppress(Element element, String suppressedBy) {
|
||||
if (element == null || suppressedBy == null) {
|
||||
return false;
|
||||
}
|
||||
if (AnnotationHandle.of(element, SuppressWarnings.class).<String>getList().contains(suppressedBy)) {
|
||||
return true;
|
||||
}
|
||||
return AnnotatedMixins.shouldSuppress(element.getEnclosingElement(), suppressedBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Diagnostic.Kind kind, CharSequence msg) {
|
||||
public void printMessage(Kind kind, CharSequence msg) {
|
||||
if (this.env == CompilerEnvironment.JAVAC || kind != Kind.NOTE) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg);
|
||||
}
|
||||
@@ -502,9 +531,19 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element element) {
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, String suppressedBy) {
|
||||
if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message to the AP messager
|
||||
@@ -514,6 +553,16 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, String suppressedBy) {
|
||||
if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@@ -522,6 +571,16 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value, String suppressedBy) {
|
||||
if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a TypeHandle representing another type in the current processing
|
||||
* environment
|
||||
|
||||
@@ -111,8 +111,9 @@ public abstract class MixinValidator implements IMixinValidator {
|
||||
*
|
||||
* @param warning Message
|
||||
* @param element Element to attach the warning to
|
||||
* @param suppressedBy {@link SuppressWarnings} value to support
|
||||
*/
|
||||
protected final void warning(String warning, Element element) {
|
||||
protected final void warning(String warning, Element element, String suppressedBy) {
|
||||
this.messager.printMessage(Kind.WARNING, warning, element);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping.Type;
|
||||
@@ -62,13 +63,13 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public <T> ObfuscationData<T> getObfEntryRecursive(final MemberInfo targetMember) {
|
||||
MemberInfo currentTarget = targetMember;
|
||||
ObfuscationData<String> obfTargetNames = this.getObfClass(currentTarget.owner);
|
||||
public <T> ObfuscationData<T> getObfEntryRecursive(final ITargetSelectorRemappable targetMember) {
|
||||
ITargetSelectorRemappable currentTarget = targetMember;
|
||||
ObfuscationData<String> obfTargetNames = this.getObfClass(currentTarget.getOwner());
|
||||
ObfuscationData<T> obfData = this.getObfEntry(currentTarget);
|
||||
try {
|
||||
while (obfData.isEmpty()) {
|
||||
TypeHandle targetType = this.ap.getTypeProvider().getTypeHandle(currentTarget.owner);
|
||||
TypeHandle targetType = this.ap.getTypeProvider().getTypeHandle(currentTarget.getOwner());
|
||||
if (targetType == null) {
|
||||
return obfData;
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* <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) {
|
||||
private <T> ObfuscationData<T> getObfEntryUsing(ITargetSelectorRemappable targetMember, TypeHandle targetClass) {
|
||||
return targetClass == null ? new ObfuscationData<T>() : this.<T>getObfEntry(targetMember.move(targetClass.getName()));
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember) {
|
||||
public <T> ObfuscationData<T> getObfEntry(ITargetSelectorRemappable targetMember) {
|
||||
if (targetMember.isField()) {
|
||||
return (ObfuscationData<T>)this.getObfField(targetMember);
|
||||
}
|
||||
@@ -147,7 +148,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingMethod> getObfMethodRecursive(MemberInfo targetMember) {
|
||||
public ObfuscationData<MappingMethod> getObfMethodRecursive(ITargetSelectorRemappable targetMember) {
|
||||
return this.<MappingMethod>getObfEntryRecursive(targetMember);
|
||||
}
|
||||
|
||||
@@ -157,16 +158,16 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingMethod> getObfMethod(MemberInfo method) {
|
||||
public ObfuscationData<MappingMethod> getObfMethod(ITargetSelectorRemappable method) {
|
||||
return this.getRemappedMethod(method, method.isConstructor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObfuscationData<MappingMethod> getRemappedMethod(MemberInfo method) {
|
||||
public ObfuscationData<MappingMethod> getRemappedMethod(ITargetSelectorRemappable method) {
|
||||
return this.getRemappedMethod(method, true);
|
||||
}
|
||||
|
||||
private ObfuscationData<MappingMethod> getRemappedMethod(MemberInfo method, boolean remapDescriptor) {
|
||||
private ObfuscationData<MappingMethod> getRemappedMethod(ITargetSelectorRemappable method, boolean remapDescriptor) {
|
||||
ObfuscationData<MappingMethod> data = new ObfuscationData<MappingMethod>();
|
||||
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
@@ -222,9 +223,9 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* @param method Method to remap
|
||||
* @return data
|
||||
*/
|
||||
public ObfuscationData<MappingMethod> remapDescriptor(ObfuscationData<MappingMethod> data, MemberInfo method) {
|
||||
public ObfuscationData<MappingMethod> remapDescriptor(ObfuscationData<MappingMethod> data, ITargetSelectorRemappable method) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MemberInfo obfMethod = env.remapDescriptor(method);
|
||||
ITargetSelectorRemappable obfMethod = env.remapDescriptor(method);
|
||||
if (obfMethod != null) {
|
||||
data.put(env.getType(), obfMethod.asMethodMapping());
|
||||
}
|
||||
@@ -239,7 +240,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingField> getObfFieldRecursive(MemberInfo targetMember) {
|
||||
public ObfuscationData<MappingField> getObfFieldRecursive(ITargetSelectorRemappable targetMember) {
|
||||
return this.<MappingField>getObfEntryRecursive(targetMember);
|
||||
}
|
||||
|
||||
@@ -248,7 +249,7 @@ public class ObfuscationDataProvider implements IObfuscationDataProvider {
|
||||
* #getObfField(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ObfuscationData<MappingField> getObfField(MemberInfo field) {
|
||||
public ObfuscationData<MappingField> getObfField(ITargetSelectorRemappable field) {
|
||||
return this.getObfField(field.asFieldMapping());
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
@@ -182,14 +183,14 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
* Get an obfuscation mapping for a method
|
||||
*/
|
||||
@Override
|
||||
public MappingMethod getObfMethod(MemberInfo method) {
|
||||
public MappingMethod getObfMethod(ITargetSelectorRemappable method) {
|
||||
MappingMethod obfd = this.getObfMethod(method.asMethodMapping());
|
||||
if (obfd != null || !method.isFullyQualified()) {
|
||||
return obfd;
|
||||
}
|
||||
|
||||
// Get a type handle for the declared method owner
|
||||
TypeHandle type = this.ap.getTypeProvider().getTypeHandle(method.owner);
|
||||
TypeHandle type = this.ap.getTypeProvider().getTypeHandle(method.getOwner());
|
||||
if (type == null || type.isImaginary()) {
|
||||
return null;
|
||||
}
|
||||
@@ -202,7 +203,7 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
|
||||
// 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));
|
||||
return this.getObfMethod(method.move(superClassName.replace('.', '/')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,8 +221,9 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
public MappingMethod getObfMethod(MappingMethod method, boolean lazyRemap) {
|
||||
if (this.initMappings()) {
|
||||
boolean remapped = true;
|
||||
boolean superRef = false;
|
||||
MappingMethod mapping = null;
|
||||
for (MappingMethod md = method; md != null && mapping == null; md = md.getSuper()) {
|
||||
for (MappingMethod md = method; md != null && mapping == null; md = md.getSuper(), superRef = true) {
|
||||
mapping = this.mappingProvider.getMethodMapping(md);
|
||||
}
|
||||
|
||||
@@ -232,6 +234,11 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
}
|
||||
mapping = method.copy();
|
||||
remapped = false;
|
||||
} else if (superRef) {
|
||||
// If we mapped via super and owner class is non-obf, restore the
|
||||
// original owner
|
||||
String obfOwner = this.getObfClass(method.getOwner());
|
||||
mapping = mapping.move(obfOwner != null ? obfOwner : method.getOwner());
|
||||
}
|
||||
String remappedOwner = this.getObfClass(mapping.getOwner());
|
||||
if (remappedOwner == null || remappedOwner.equals(method.getOwner()) || remappedOwner.equals(mapping.getOwner())) {
|
||||
@@ -253,10 +260,10 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
* @return remapped method or null if no remapping occurred
|
||||
*/
|
||||
@Override
|
||||
public MemberInfo remapDescriptor(MemberInfo method) {
|
||||
public ITargetSelectorRemappable remapDescriptor(ITargetSelectorRemappable method) {
|
||||
boolean transformed = false;
|
||||
|
||||
String owner = method.owner;
|
||||
String owner = method.getOwner();
|
||||
if (owner != null) {
|
||||
String newOwner = this.remapper.map(owner);
|
||||
if (newOwner != null) {
|
||||
@@ -265,16 +272,16 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
}
|
||||
}
|
||||
|
||||
String desc = method.desc;
|
||||
String desc = method.getDesc();
|
||||
if (desc != null) {
|
||||
String newDesc = ObfuscationUtil.mapDescriptor(method.desc, this.remapper);
|
||||
if (!newDesc.equals(method.desc)) {
|
||||
String newDesc = ObfuscationUtil.mapDescriptor(method.getDesc(), this.remapper);
|
||||
if (!newDesc.equals(method.getDesc())) {
|
||||
desc = newDesc;
|
||||
transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return transformed ? new MemberInfo(method.name, owner, desc, method.matchAll) : null;
|
||||
return transformed ? new MemberInfo(method.getName(), owner, desc, method.getMatchCount() > 1) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,7 +300,7 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
@Override
|
||||
public MappingField getObfField(MemberInfo field) {
|
||||
public MappingField getObfField(ITargetSelectorRemappable field) {
|
||||
return this.getObfField(field.asFieldMapping(), true);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ package org.spongepowered.tools.obfuscation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
@@ -112,7 +113,7 @@ public final class ObfuscationType {
|
||||
public boolean isDefault() {
|
||||
String defaultEnv = this.options.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV);
|
||||
return (defaultEnv == null && this.key.equals(ObfuscationServiceMCP.SEARGE))
|
||||
|| (defaultEnv != null && this.key.equals(defaultEnv.toLowerCase()));
|
||||
|| (defaultEnv != null && this.key.equals(defaultEnv.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
@@ -190,11 +191,12 @@ public class ReferenceManager implements IReferenceManager {
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addMethodMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingMethod> obfMethodData) {
|
||||
public void addMethodMapping(String className, String reference, ITargetSelectorRemappable context,
|
||||
ObfuscationData<MappingMethod> obfMethodData) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingMethod obfMethod = obfMethodData.get(env.getType());
|
||||
if (obfMethod != null) {
|
||||
MemberInfo remappedReference = context.remapUsing(obfMethod, true);
|
||||
ITargetSelectorRemappable remappedReference = context.remapUsing(obfMethod, true);
|
||||
this.addMapping(env.getType(), className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
@@ -207,11 +209,11 @@ public class ReferenceManager implements IReferenceManager {
|
||||
* org.spongepowered.tools.obfuscation.ObfuscationData)
|
||||
*/
|
||||
@Override
|
||||
public void addFieldMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingField> obfFieldData) {
|
||||
public void addFieldMapping(String className, String reference, ITargetSelectorRemappable context, ObfuscationData<MappingField> obfFieldData) {
|
||||
for (ObfuscationEnvironment env : this.environments) {
|
||||
MappingField obfField = obfFieldData.get(env.getType());
|
||||
if (obfField != null) {
|
||||
MemberInfo remappedReference = MemberInfo.fromMapping(obfField.transform(env.remapDescriptor(context.desc)));
|
||||
MemberInfo remappedReference = MemberInfo.fromMapping(obfField.transform(env.remapDescriptor(context.getDesc())));
|
||||
this.addMapping(env.getType(), className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public final class SupportedOptions {
|
||||
public static final String OVERWRITE_ERROR_LEVEL = "overwriteErrorLevel";
|
||||
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";
|
||||
public static final String DEPENDENCY_TARGETS_FILE = "dependencyTargetsFile";
|
||||
public static final String MAPPING_TYPES = "mappingTypes";
|
||||
|
||||
private SupportedOptions() {}
|
||||
|
||||
@@ -61,7 +62,8 @@ public final class SupportedOptions {
|
||||
SupportedOptions.DISABLE_OVERWRITE_CHECKER,
|
||||
SupportedOptions.OVERWRITE_ERROR_LEVEL,
|
||||
SupportedOptions.DEFAULT_OBFUSCATION_ENV,
|
||||
SupportedOptions.DEPENDENCY_TARGETS_FILE
|
||||
SupportedOptions.DEPENDENCY_TARGETS_FILE,
|
||||
SupportedOptions.MAPPING_TYPES
|
||||
);
|
||||
options.addAll(
|
||||
ObfuscationServices.getInstance().getSupportedOptions()
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.fg3;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
|
||||
import org.spongepowered.tools.obfuscation.mapping.fg3.MappingProviderTSrg;
|
||||
import org.spongepowered.tools.obfuscation.mapping.fg3.MappingWriterTSrg;
|
||||
|
||||
/**
|
||||
* A ForgeGradle 3.+ obfuscation environment
|
||||
*/
|
||||
public class ObfuscationEnvironmentFG3 extends ObfuscationEnvironment {
|
||||
|
||||
private MappingProviderTSrg provider;
|
||||
|
||||
protected ObfuscationEnvironmentFG3(ObfuscationType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMappingProvider getMappingProvider(Messager messager, Filer filer) {
|
||||
return this.provider = new MappingProviderTSrg(messager, filer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMappingWriter getMappingWriter(Messager messager, Filer filer) {
|
||||
String outputBehaviour = this.ap.getOption(ObfuscationServiceFG3.TSRG_OUTPUT_BEHAVIOUR);
|
||||
return new MappingWriterTSrg(messager, filer, this.provider, outputBehaviour != null && outputBehaviour.equalsIgnoreCase("merge"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.fg3;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.SupportedOptions;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.service.IObfuscationService;
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Obfuscation service for ForgeGradle 3.+
|
||||
*/
|
||||
public class ObfuscationServiceFG3 implements IObfuscationService {
|
||||
|
||||
public static final String SEARGE = "searge";
|
||||
|
||||
public static final String REOBF_TSRG_FILE = "reobfTsrgFile";
|
||||
public static final String OUT_TSRG_SRG_FILE = "outTsrgFile";
|
||||
public static final String OUT_REFMAP_FILE = "outRefMapFile";
|
||||
public static final String TSRG_OUTPUT_BEHAVIOUR = "mergeBehaviour";
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedOptions() {
|
||||
return ImmutableSet.<String>of(
|
||||
ObfuscationServiceFG3.REOBF_TSRG_FILE,
|
||||
ObfuscationServiceFG3.OUT_TSRG_SRG_FILE,
|
||||
ObfuscationServiceFG3.OUT_REFMAP_FILE,
|
||||
ObfuscationServiceFG3.TSRG_OUTPUT_BEHAVIOUR
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes(IMixinAnnotationProcessor ap) {
|
||||
Builder<ObfuscationTypeDescriptor> list = ImmutableList.<ObfuscationTypeDescriptor>builder();
|
||||
if (ap.getOptions(SupportedOptions.MAPPING_TYPES).contains("tsrg")) {
|
||||
list.add(
|
||||
new ObfuscationTypeDescriptor(
|
||||
ObfuscationServiceFG3.SEARGE,
|
||||
ObfuscationServiceFG3.REOBF_TSRG_FILE,
|
||||
null,
|
||||
ObfuscationServiceFG3.OUT_TSRG_SRG_FILE,
|
||||
ObfuscationEnvironmentFG3.class
|
||||
)
|
||||
);
|
||||
}
|
||||
return list.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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 javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
/**
|
||||
* An extended {@link Messager} which supports messages that can be suppressed
|
||||
* using the standard Java {@link SuppressWarnings} annotation.
|
||||
*/
|
||||
public interface IMessagerSuppressible extends Messager {
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* element.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the element to use as a position hint
|
||||
* @param suppressedBy the {@link SuppressWarnings} value which will silence
|
||||
* this message
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, String suppressedBy);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* annotation mirror of the annotated element.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the annotated element
|
||||
* @param a the annotation to use as a position hint
|
||||
* @param suppressedBy the {@link SuppressWarnings} value which will silence
|
||||
* this message
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, String suppressedBy);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* annotation value inside the annotation mirror of the annotated
|
||||
* element.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the annotated element
|
||||
* @param a the annotation containing the annotation value
|
||||
* @param v the annotation value to use as a position hint
|
||||
* @param suppressedBy the {@link SuppressWarnings} value which will silence
|
||||
* this message
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind,CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, String suppressedBy);
|
||||
|
||||
|
||||
}
|
||||
+1
-2
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
|
||||
import org.spongepowered.asm.util.ITokenProvider;
|
||||
@@ -32,7 +31,7 @@ import org.spongepowered.asm.util.ITokenProvider;
|
||||
/**
|
||||
* Interface for annotation processor core
|
||||
*/
|
||||
public interface IMixinAnnotationProcessor extends Messager, IOptionProvider {
|
||||
public interface IMixinAnnotationProcessor extends IMessagerSuppressible, IOptionProvider {
|
||||
|
||||
/**
|
||||
* Detected compiler argument, specifies the behaviour of some operations
|
||||
|
||||
+8
-8
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
@@ -48,7 +48,7 @@ public interface IObfuscationDataProvider {
|
||||
* original owner class
|
||||
* or String for fields)
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntryRecursive(MemberInfo targetMember);
|
||||
public abstract <T> ObfuscationData<T> getObfEntryRecursive(ITargetSelectorRemappable targetMember);
|
||||
|
||||
/**
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
@@ -58,7 +58,7 @@ public interface IObfuscationDataProvider {
|
||||
* @return obfuscation data (by type) for the supplied member
|
||||
* or String for fields)
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember);
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(ITargetSelectorRemappable targetMember);
|
||||
|
||||
/**
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
@@ -80,14 +80,14 @@ public interface IObfuscationDataProvider {
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethodRecursive(MemberInfo method);
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethodRecursive(ITargetSelectorRemappable method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*
|
||||
* @param method method to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethod(MemberInfo method);
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethod(ITargetSelectorRemappable method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method if an explicit mapping exists.
|
||||
@@ -95,7 +95,7 @@ public interface IObfuscationDataProvider {
|
||||
*
|
||||
* @param method method to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getRemappedMethod(MemberInfo method);
|
||||
public abstract ObfuscationData<MappingMethod> getRemappedMethod(ITargetSelectorRemappable method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
@@ -122,14 +122,14 @@ public interface IObfuscationDataProvider {
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfFieldRecursive(MemberInfo field);
|
||||
public abstract ObfuscationData<MappingField> getObfFieldRecursive(ITargetSelectorRemappable field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*
|
||||
* @param field field to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfField(MemberInfo field);
|
||||
public abstract ObfuscationData<MappingField> getObfField(ITargetSelectorRemappable field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
|
||||
+4
-4
@@ -26,7 +26,7 @@ package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
|
||||
@@ -45,7 +45,7 @@ public interface IObfuscationEnvironment {
|
||||
* @param method method to locate a mapping for
|
||||
* @return remapped method or null if no mapping exists
|
||||
*/
|
||||
public abstract MappingMethod getObfMethod(MemberInfo method);
|
||||
public abstract MappingMethod getObfMethod(ITargetSelectorRemappable method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method, returns null if no mapping
|
||||
@@ -78,7 +78,7 @@ public interface IObfuscationEnvironment {
|
||||
* @param field field to locate a mapping for
|
||||
* @return remapped field or null if no mapping exists
|
||||
*/
|
||||
public abstract MappingField getObfField(MemberInfo field);
|
||||
public abstract MappingField getObfField(ITargetSelectorRemappable field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field, returns null if no mapping
|
||||
@@ -119,7 +119,7 @@ public interface IObfuscationEnvironment {
|
||||
* @param method method to remap
|
||||
* @return remapped method or null if no remapping occurred
|
||||
*/
|
||||
public abstract MemberInfo remapDescriptor(MemberInfo method);
|
||||
public abstract ITargetSelectorRemappable remapDescriptor(ITargetSelectorRemappable method);
|
||||
|
||||
/**
|
||||
* Remap a single descriptor in the context of this environment
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An object which can provide option values to consumers
|
||||
*/
|
||||
@@ -37,4 +39,22 @@ public interface IOptionProvider {
|
||||
*/
|
||||
public abstract String getOption(String option);
|
||||
|
||||
/**
|
||||
* Fetch the value of the specified option, if available. If the option is
|
||||
* not available, return the specified default value
|
||||
*
|
||||
* @param option Name of the option to fetch
|
||||
* @param defaultValue Default value to return if the option is not present
|
||||
* @return Option value or default if absent
|
||||
*/
|
||||
public abstract boolean getOption(String option, boolean defaultValue);
|
||||
|
||||
/**
|
||||
* Fetch the values of the specified comma-separated option, if available
|
||||
*
|
||||
* @param option Name of the option to fetch
|
||||
* @return Option value or null if absent
|
||||
*/
|
||||
public abstract List<String> getOptions(String option);
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
@@ -75,7 +75,7 @@ public interface IReferenceManager {
|
||||
|
||||
/**
|
||||
* Adds a method mapping to the internal refmap, generates refmap entries
|
||||
* using the supplied parsed memberinfo as context
|
||||
* using the supplied parsed target selector as context
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
@@ -83,11 +83,12 @@ public interface IReferenceManager {
|
||||
* supplied obfuscation data
|
||||
* @param obfMethodData Method data to add for this mapping
|
||||
*/
|
||||
public abstract void addMethodMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingMethod> obfMethodData);
|
||||
public abstract void addMethodMapping(String className, String reference, ITargetSelectorRemappable context,
|
||||
ObfuscationData<MappingMethod> obfMethodData);
|
||||
|
||||
/**
|
||||
* Adds a field mapping to the internal refmap, generates refmap entries
|
||||
* using the supplied parsed memberinfo as context
|
||||
* using the supplied parsed target selector as context
|
||||
*
|
||||
* @param className Mixin class name which owns the refmap entry
|
||||
* @param reference Original reference, as it appears in the annotation
|
||||
@@ -95,7 +96,8 @@ public interface IReferenceManager {
|
||||
* supplied obfuscation data
|
||||
* @param obfFieldData Field data to add for this mapping
|
||||
*/
|
||||
public abstract void addFieldMapping(String className, String reference, MemberInfo context, ObfuscationData<MappingField> obfFieldData);
|
||||
public abstract void addFieldMapping(String className, String reference, ITargetSelectorRemappable context,
|
||||
ObfuscationData<MappingField> obfFieldData);
|
||||
|
||||
/**
|
||||
* Adds a class mapping to the internal refmap
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.mapping.fg3;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
|
||||
|
||||
/**
|
||||
* A MappingMethod which computes transformed descriptor on demand using the
|
||||
* supplied mapping provider. This means we only need to compute transformed
|
||||
* descriptors for methods which are actually used.
|
||||
*/
|
||||
public class MappingMethodLazy extends MappingMethod {
|
||||
|
||||
private static final Pattern PATTERN_CLASSNAME = Pattern.compile("L([^;]+);");
|
||||
|
||||
private final String originalDesc;
|
||||
|
||||
private final IMappingProvider mappingProvider;
|
||||
|
||||
private String newDesc;
|
||||
|
||||
public MappingMethodLazy(String owner, String simpleName, String originalDesc, IMappingProvider mappingProvider) {
|
||||
super(owner, simpleName, "{" + originalDesc + "}"); // descriptor provided since it's used for hash generation
|
||||
this.originalDesc = originalDesc;
|
||||
this.mappingProvider = mappingProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
if (this.newDesc == null) {
|
||||
this.newDesc = this.generateDescriptor();
|
||||
}
|
||||
return this.newDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String desc = this.getDesc();
|
||||
return String.format("%s%s%s", this.getName(), desc != null ? " " : "", desc != null ? desc : "");
|
||||
}
|
||||
|
||||
private String generateDescriptor() {
|
||||
StringBuffer desc = new StringBuffer();
|
||||
Matcher matcher = MappingMethodLazy.PATTERN_CLASSNAME.matcher(this.originalDesc);
|
||||
while (matcher.find()) {
|
||||
String remapped = this.mappingProvider.getClassMapping(matcher.group(1));
|
||||
if (remapped != null) {
|
||||
matcher.appendReplacement(desc, Matcher.quoteReplacement("L" + remapped + ";"));
|
||||
} else {
|
||||
matcher.appendReplacement(desc, Matcher.quoteReplacement("L" + matcher.group(1) + ";"));
|
||||
}
|
||||
}
|
||||
matcher.appendTail(desc);
|
||||
return desc.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.mapping.fg3;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.mcp.MappingFieldSrg;
|
||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingProvider;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* TSRG Mapping provider
|
||||
*/
|
||||
public class MappingProviderTSrg extends MappingProvider {
|
||||
|
||||
private List<String> inputMappings = Collections.<String>emptyList();
|
||||
|
||||
public MappingProviderTSrg(Messager messager, Filer filer) {
|
||||
super(messager, filer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(final File input) throws IOException {
|
||||
// Locally scoped to avoid synthetic accessor
|
||||
final BiMap<String, String> packageMap = this.packageMap;
|
||||
final BiMap<String, String> classMap = this.classMap;
|
||||
final BiMap<MappingField, MappingField> fieldMap = this.fieldMap;
|
||||
final BiMap<MappingMethod, MappingMethod> methodMap = this.methodMap;
|
||||
|
||||
String fromClass = null, toClass = null;
|
||||
this.inputMappings = Files.readLines(input, Charset.defaultCharset());
|
||||
|
||||
for (String line : this.inputMappings) {
|
||||
if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] parts = line.split(" ");
|
||||
if (line.startsWith("\t")) {
|
||||
if (fromClass == null) {
|
||||
throw new IllegalStateException("Error parsing TSRG file, found member declaration with no class: " + line);
|
||||
}
|
||||
parts[0] = parts[0].substring(1);
|
||||
if (parts.length == 2) {
|
||||
fieldMap.forcePut(new MappingField(fromClass, parts[0]), new MappingField(toClass, parts[1]));
|
||||
} else if (parts.length == 3) {
|
||||
methodMap.forcePut(new MappingMethod(fromClass, parts[0], parts[1]), new MappingMethodLazy(toClass, parts[2],
|
||||
parts[1], MappingProviderTSrg.this));
|
||||
} else {
|
||||
throw new IllegalStateException("Error parsing TSRG file, too many arguments: " + line);
|
||||
}
|
||||
} else if (parts.length > 1) {
|
||||
String from = parts[0];
|
||||
if (parts.length == 2) {
|
||||
String to = parts[1];
|
||||
if (from.endsWith("/")) {
|
||||
packageMap.forcePut(from.substring(0, from.length() - 1), to.substring(0, to.length() - 1));
|
||||
} else {
|
||||
classMap.forcePut(from, to);
|
||||
fromClass = from;
|
||||
toClass = to;
|
||||
}
|
||||
} else if (parts.length > 2) {
|
||||
String to = classMap.get(from);
|
||||
if (to == null) {
|
||||
throw new IllegalStateException("Error parsing TSRG file, found inline member before class mapping: " + line);
|
||||
}
|
||||
if (parts.length == 3) {
|
||||
fieldMap.forcePut(new MappingField(from, parts[1]), new MappingField(to, parts[2]));
|
||||
} else if (parts.length == 4) {
|
||||
methodMap.forcePut(new MappingMethod(from, parts[1], parts[2]), new MappingMethodLazy(to, parts[3], parts[2],
|
||||
MappingProviderTSrg.this));
|
||||
} else {
|
||||
throw new IllegalStateException("Error parsing TSRG file, too many arguments: " + line);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Error parsing TSRG, unrecognised directive: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField getFieldMapping(MappingField field) {
|
||||
// SRG fields do not have descriptors so strip the field descriptor before looking up
|
||||
if (field.getDesc() != null) {
|
||||
field = new MappingFieldSrg(field);
|
||||
}
|
||||
return this.fieldMap.get(field);
|
||||
}
|
||||
|
||||
List<String> getInputMappings() {
|
||||
return this.inputMappings;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.mapping.fg3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.annotation.processing.Messager;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationType;
|
||||
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet.Pair;
|
||||
import org.spongepowered.tools.obfuscation.mapping.mcp.MappingWriterSrg;
|
||||
|
||||
/**
|
||||
* Writer for SRG mappings
|
||||
*/
|
||||
public class MappingWriterTSrg extends MappingWriterSrg {
|
||||
|
||||
private final MappingProviderTSrg provider;
|
||||
private final boolean mergeExisting;
|
||||
|
||||
public MappingWriterTSrg(Messager messager, Filer filer, MappingProviderTSrg provider, boolean mergeExisting) {
|
||||
super(messager, filer);
|
||||
this.provider = provider;
|
||||
this.mergeExisting = mergeExisting;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PrintWriter openFileWriter(String output, ObfuscationType type) throws IOException {
|
||||
return this.openFileWriter(output, type + " composite mappings");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeHeader(PrintWriter writer) {
|
||||
if (this.mergeExisting) {
|
||||
for (String line : this.provider.getInputMappings()) {
|
||||
writer.println(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formatFieldMapping(Pair<MappingField> field) {
|
||||
return String.format("%s %s %s %s", field.from.getOwner(), field.from.getSimpleName(), field.to.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formatMethodMapping(Pair<MappingMethod> method) {
|
||||
return String.format("%s %s %s %s", method.from.getOwner(), method.from.getSimpleName(), method.from.getDesc(), method.to.getSimpleName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,8 @@ public class MappingWriterSrg extends MappingWriter {
|
||||
PrintWriter writer = null;
|
||||
|
||||
try {
|
||||
writer = this.openFileWriter(output, type + " output SRGs");
|
||||
writer = this.openFileWriter(output, type);
|
||||
this.writeHeader(writer);
|
||||
this.writeFieldMappings(writer, fields);
|
||||
this.writeMethodMappings(writer, methods);
|
||||
} catch (IOException ex) {
|
||||
@@ -71,6 +72,14 @@ public class MappingWriterSrg extends MappingWriter {
|
||||
}
|
||||
}
|
||||
|
||||
protected PrintWriter openFileWriter(String output, ObfuscationType type) throws IOException {
|
||||
return this.openFileWriter(output, type + " output SRGs");
|
||||
}
|
||||
|
||||
protected void writeHeader(PrintWriter writer) {
|
||||
// stub
|
||||
}
|
||||
|
||||
protected void writeFieldMappings(PrintWriter writer, MappingSet<MappingField> fields) {
|
||||
for (Pair<MappingField> field : fields) {
|
||||
writer.println(this.formatFieldMapping(field));
|
||||
|
||||
@@ -27,11 +27,14 @@ package org.spongepowered.tools.obfuscation.mcp;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.SupportedOptions;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.service.IObfuscationService;
|
||||
import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
/**
|
||||
* Default obfuscation service, provides MCP
|
||||
@@ -63,15 +66,20 @@ public class ObfuscationServiceMCP implements IObfuscationService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() {
|
||||
return ImmutableList.<ObfuscationTypeDescriptor>of(
|
||||
new ObfuscationTypeDescriptor(
|
||||
ObfuscationServiceMCP.SEARGE,
|
||||
ObfuscationServiceMCP.REOBF_SRG_FILE,
|
||||
ObfuscationServiceMCP.REOBF_EXTRA_SRG_FILES,
|
||||
ObfuscationServiceMCP.OUT_SRG_SRG_FILE,
|
||||
ObfuscationEnvironmentMCP.class
|
||||
),
|
||||
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes(IMixinAnnotationProcessor ap) {
|
||||
Builder<ObfuscationTypeDescriptor> list = ImmutableList.<ObfuscationTypeDescriptor>builder();
|
||||
if (!ap.getOptions(SupportedOptions.MAPPING_TYPES).contains("tsrg")) {
|
||||
list.add(
|
||||
new ObfuscationTypeDescriptor(
|
||||
ObfuscationServiceMCP.SEARGE,
|
||||
ObfuscationServiceMCP.REOBF_SRG_FILE,
|
||||
ObfuscationServiceMCP.REOBF_EXTRA_SRG_FILES,
|
||||
ObfuscationServiceMCP.OUT_SRG_SRG_FILE,
|
||||
ObfuscationEnvironmentMCP.class
|
||||
)
|
||||
);
|
||||
}
|
||||
list.add(
|
||||
new ObfuscationTypeDescriptor(
|
||||
ObfuscationServiceMCP.NOTCH,
|
||||
ObfuscationServiceMCP.REOBF_NOTCH_FILE,
|
||||
@@ -80,6 +88,7 @@ public class ObfuscationServiceMCP implements IObfuscationService {
|
||||
ObfuscationEnvironmentMCP.class
|
||||
)
|
||||
);
|
||||
return list.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ package org.spongepowered.tools.obfuscation.mirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mirror.mapping.ResolvableMappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mirror.mapping.MappingMethodResolvable;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class MethodHandle extends MemberHandle<MappingMethod> {
|
||||
public MappingMethod asMapping(boolean includeOwner) {
|
||||
if (includeOwner) {
|
||||
if (this.ownerHandle != null) {
|
||||
return new ResolvableMappingMethod(this.ownerHandle, this.getName(), this.getDesc());
|
||||
return new MappingMethodResolvable(this.ownerHandle, this.getName(), this.getDesc());
|
||||
}
|
||||
return new MappingMethod(this.getOwner(), this.getName(), this.getDesc());
|
||||
}
|
||||
|
||||
@@ -39,9 +39,10 @@ import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mirror.mapping.ResolvableMappingMethod;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.tools.obfuscation.mirror.mapping.MappingMethodResolvable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
@@ -122,6 +123,13 @@ public class TypeHandle {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the simple class name
|
||||
*/
|
||||
public final String getSimpleName() {
|
||||
return Bytecode.getSimpleName(this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enclosing package element
|
||||
*/
|
||||
@@ -255,20 +263,20 @@ public class TypeHandle {
|
||||
* @return this handle as a mapping method
|
||||
*/
|
||||
public MappingMethod getMappingMethod(String name, String desc) {
|
||||
return new ResolvableMappingMethod(this, name, desc);
|
||||
return new MappingMethodResolvable(this, name, desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a descriptor for the supplied MemberInfo
|
||||
* Find a descriptor for the supplied target selector
|
||||
*
|
||||
* @param memberInfo MemberInfo to use as search term
|
||||
* @param selector Target selector to use as search term
|
||||
* @return descriptor or null if no matching member could be located
|
||||
*/
|
||||
public String findDescriptor(MemberInfo memberInfo) {
|
||||
String desc = memberInfo.desc;
|
||||
public String findDescriptor(ITargetSelectorByName selector) {
|
||||
String desc = selector.getDesc();
|
||||
if (desc == null) {
|
||||
for (ExecutableElement method : this.<ExecutableElement>getEnclosedElements(ElementKind.METHOD)) {
|
||||
if (method.getSimpleName().toString().equals(memberInfo.name)) {
|
||||
if (method.getSimpleName().toString().equals(selector.getName())) {
|
||||
desc = TypeUtils.getDescriptor(method);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
|
||||
@@ -117,9 +117,9 @@ public class TypeHandleSimulated extends TypeHandle {
|
||||
* #findDescriptor(org.spongepowered.asm.mixin.injection.struct.MemberInfo)
|
||||
*/
|
||||
@Override
|
||||
public String findDescriptor(MemberInfo memberInfo) {
|
||||
public String findDescriptor(ITargetSelectorByName memberInfo) {
|
||||
// Identity, refs need to be FQ
|
||||
return memberInfo != null ? memberInfo.desc : null;
|
||||
return memberInfo != null ? memberInfo.getDesc() : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -37,6 +37,8 @@ import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeVariable;
|
||||
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
|
||||
/**
|
||||
@@ -51,7 +53,6 @@ public abstract class TypeUtils {
|
||||
private static final int MAX_GENERIC_RECURSION_DEPTH = 5;
|
||||
|
||||
private static final String OBJECT_SIG = "java.lang.Object";
|
||||
private static final String OBJECT_REF = "java/lang/Object";
|
||||
|
||||
// No instances for you
|
||||
private TypeUtils() {}
|
||||
@@ -185,6 +186,16 @@ public abstract class TypeUtils {
|
||||
return new SignaturePrinter("", descriptor).setFullyQualified(true).toDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the simple type name for the specified type
|
||||
*
|
||||
* @param type type mirror
|
||||
* @return type name
|
||||
*/
|
||||
public static String getSimpleName(TypeMirror type) {
|
||||
return Bytecode.getSimpleName(TypeUtils.getTypeName(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type name for the specified type
|
||||
*
|
||||
@@ -285,7 +296,7 @@ public abstract class TypeUtils {
|
||||
case SHORT: return "S";
|
||||
case VOID: return "V";
|
||||
// TODO figure out a better way to not crash when we get here
|
||||
case ERROR: return "L" + TypeUtils.OBJECT_REF + ";";
|
||||
case ERROR: return Constants.OBJECT_DESC;
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -300,7 +311,7 @@ public abstract class TypeUtils {
|
||||
*/
|
||||
public static String getInternalName(DeclaredType type) {
|
||||
if (type == null) {
|
||||
return TypeUtils.OBJECT_REF;
|
||||
return Constants.OBJECT;
|
||||
}
|
||||
return TypeUtils.getInternalName((TypeElement)type.asElement());
|
||||
}
|
||||
|
||||
+6
-6
@@ -33,11 +33,11 @@ import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
|
||||
* mapping allows references in superclasses to be resolved when necessary since
|
||||
* the hierarchy information is available.
|
||||
*/
|
||||
public final class ResolvableMappingMethod extends MappingMethod {
|
||||
public final class MappingMethodResolvable extends MappingMethod {
|
||||
|
||||
private final TypeHandle ownerHandle;
|
||||
|
||||
public ResolvableMappingMethod(TypeHandle owner, String name, String desc) {
|
||||
public MappingMethodResolvable(TypeHandle owner, String name, String desc) {
|
||||
super(owner.getName(), name, desc);
|
||||
this.ownerHandle = owner;
|
||||
}
|
||||
@@ -87,22 +87,22 @@ public final class ResolvableMappingMethod extends MappingMethod {
|
||||
* @return remapped method
|
||||
*/
|
||||
public MappingMethod move(TypeHandle newOwner) {
|
||||
return new ResolvableMappingMethod(newOwner, this.getSimpleName(), this.getDesc());
|
||||
return new MappingMethodResolvable(newOwner, this.getSimpleName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod remap(String newName) {
|
||||
return new ResolvableMappingMethod(this.ownerHandle, newName, this.getDesc());
|
||||
return new MappingMethodResolvable(this.ownerHandle, newName, this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod transform(String newDesc) {
|
||||
return new ResolvableMappingMethod(this.ownerHandle, this.getSimpleName(), newDesc);
|
||||
return new MappingMethodResolvable(this.ownerHandle, this.getSimpleName(), newDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod copy() {
|
||||
return new ResolvableMappingMethod(this.ownerHandle, this.getSimpleName(), this.getDesc());
|
||||
return new MappingMethodResolvable(this.ownerHandle, this.getSimpleName(), this.getDesc());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,8 @@ package org.spongepowered.tools.obfuscation.service;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
/**
|
||||
* Service interface for obfuscation services
|
||||
*/
|
||||
@@ -43,8 +45,9 @@ public interface IObfuscationService {
|
||||
* This method should return a collection of available obfuscation types
|
||||
* supported by this service
|
||||
*
|
||||
* @param ap Annotation Processor instance
|
||||
* @return available obfuscation types or null
|
||||
*/
|
||||
public abstract Collection<ObfuscationTypeDescriptor> getObfuscationTypes();
|
||||
public abstract Collection<ObfuscationTypeDescriptor> getObfuscationTypes(IMixinAnnotationProcessor ap);
|
||||
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public final class ObfuscationServices {
|
||||
|
||||
String serviceName = service.getClass().getSimpleName();
|
||||
// ap.printMessage(Kind.NOTE, "Preparing service " + serviceName);
|
||||
Collection<ObfuscationTypeDescriptor> obfTypes = service.getObfuscationTypes();
|
||||
Collection<ObfuscationTypeDescriptor> obfTypes = service.getObfuscationTypes(ap);
|
||||
if (obfTypes != null) {
|
||||
for (ObfuscationTypeDescriptor obfType : obfTypes) {
|
||||
try {
|
||||
@@ -109,7 +109,7 @@ public final class ObfuscationServices {
|
||||
*/
|
||||
public Set<String> getSupportedOptions() {
|
||||
Set<String> supportedOptions = new HashSet<String>();
|
||||
for (IObfuscationService provider : this.serviceLoader) {
|
||||
for (IObfuscationService provider : this.services) {
|
||||
Set<String> options = provider.getSupportedOptions();
|
||||
if (options != null) {
|
||||
supportedOptions.addAll(options);
|
||||
@@ -125,7 +125,7 @@ public final class ObfuscationServices {
|
||||
* @return service instance or null if no matching services were loaded
|
||||
*/
|
||||
public IObfuscationService getService(Class<? extends IObfuscationService> serviceClass) {
|
||||
for (IObfuscationService service : this.serviceLoader) {
|
||||
for (IObfuscationService service : this.services) {
|
||||
if (serviceClass.getName().equals(service.getClass().getName())) {
|
||||
return service;
|
||||
}
|
||||
|
||||
@@ -106,4 +106,5 @@ public class ObfuscationTypeDescriptor {
|
||||
public Class<? extends ObfuscationEnvironment> getEnvironmentType() {
|
||||
return this.environmentType;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user