mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-28 22:48:44 +00:00
Merge remote-tracking branch 'SpongePowered/0.8.3' into upstream_merge
# Conflicts: # build.gradle # gradle.properties # src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java # src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
This commit is contained in:
commit
0ce2d4f8c4
184 files changed
+9666
-1595
No files matched your search
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -38,9 +39,19 @@ import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Pseudo;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ISelectorContext;
|
||||
import org.spongepowered.asm.mixin.injection.struct.SelectorAnnotationContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
import org.spongepowered.asm.util.asm.IAnnotatedElement;
|
||||
import org.spongepowered.asm.util.asm.IAnnotationHandle;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerAccessor.AnnotatedElementAccessor;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerAccessor.AnnotatedElementInvoker;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerInjector.AnnotatedElementInjectionPoint;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerInjector.AnnotatedElementSliceInjectionPoint;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerInjector.AnnotatedElementInjector;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerOverwrite.AnnotatedElementOverwrite;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMessagerSuppressible;
|
||||
@@ -55,10 +66,12 @@ import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
|
||||
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
|
||||
import org.spongepowered.tools.obfuscation.struct.InjectorRemap;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Information about a mixin stored during processing
|
||||
*/
|
||||
class AnnotatedMixin {
|
||||
class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
|
||||
|
||||
/**
|
||||
* Mixin annotation
|
||||
@@ -225,6 +238,10 @@ class AnnotatedMixin {
|
||||
} else if (type == null) {
|
||||
this.printMessage(Kind.ERROR, "Mixin target " + softTarget + " could not be found", this);
|
||||
return null;
|
||||
} else if (type.isImaginary()) {
|
||||
this.printMessage(Kind.WARNING, "Mixin target " + softTarget + " could not be fully resolved.", this,
|
||||
SuppressedBy.UNRESOLVABLE_TARGET);
|
||||
return null;
|
||||
} else if (type.isPublic()) {
|
||||
SuppressedBy suppressedBy = (type.getPackage().isUnnamed()) ? SuppressedBy.DEFAULT_PACKAGE : SuppressedBy.PUBLIC_TARGET;
|
||||
this.printMessage(Kind.WARNING, "Mixin target " + softTarget + " is public and must be specified in value", this, suppressedBy);
|
||||
@@ -285,7 +302,7 @@ class AnnotatedMixin {
|
||||
/**
|
||||
* Get the mixin class
|
||||
*/
|
||||
public TypeElement getMixin() {
|
||||
public TypeElement getMixinElement() {
|
||||
return this.mixin;
|
||||
}
|
||||
|
||||
@@ -299,6 +316,7 @@ class AnnotatedMixin {
|
||||
/**
|
||||
* Get the mixin class reference
|
||||
*/
|
||||
@Override
|
||||
public String getClassRef() {
|
||||
return this.classRef;
|
||||
}
|
||||
@@ -365,45 +383,99 @@ class AnnotatedMixin {
|
||||
|
||||
public void registerInjector(ExecutableElement method, AnnotationHandle inject, InjectorRemap remap) {
|
||||
this.methods.remove(method);
|
||||
this.injectors.registerInjector(new AnnotatedElementInjector(method, inject, remap));
|
||||
AnnotatedElementInjector injectorElement = new AnnotatedElementInjector(method, inject, this, remap);
|
||||
this.injectors.registerInjector(injectorElement);
|
||||
|
||||
List<AnnotationHandle> ats = inject.getAnnotationList("at");
|
||||
for (AnnotationHandle at : ats) {
|
||||
this.registerInjectionPoint(method, inject, at, remap, "@At(%s)");
|
||||
List<IAnnotationHandle> ats = inject.getAnnotationList("at");
|
||||
for (IAnnotationHandle at : ats) {
|
||||
this.registerInjectionPoint(method, inject, "at", (AnnotationHandle)at, remap, "@At(%s)");
|
||||
}
|
||||
|
||||
List<AnnotationHandle> slices = inject.getAnnotationList("slice");
|
||||
for (AnnotationHandle slice : slices) {
|
||||
List<IAnnotationHandle> slices = inject.getAnnotationList("slice");
|
||||
for (IAnnotationHandle slice : slices) {
|
||||
String id = slice.<String>getValue("id", "");
|
||||
String coord = "slice";
|
||||
if (!Strings.isNullOrEmpty(id)) {
|
||||
coord += "." + id;
|
||||
}
|
||||
SelectorAnnotationContext sliceContext = new SelectorAnnotationContext(injectorElement, slice, coord);
|
||||
|
||||
AnnotationHandle from = slice.getAnnotation("from");
|
||||
IAnnotationHandle from = slice.getAnnotation("from");
|
||||
if (from != null) {
|
||||
this.registerInjectionPoint(method, inject, from, remap, "@Slice[" + id + "](from=@At(%s))");
|
||||
this.registerSliceInjectionPoint(method, inject, "from", (AnnotationHandle)from, remap, "@Slice[" + id + "](from=@At(%s))",
|
||||
sliceContext);
|
||||
}
|
||||
|
||||
AnnotationHandle to = slice.getAnnotation("to");
|
||||
IAnnotationHandle to = slice.getAnnotation("to");
|
||||
if (to != null) {
|
||||
this.registerInjectionPoint(method, inject, to, remap, "@Slice[" + id + "](to=@At(%s))");
|
||||
this.registerSliceInjectionPoint(method, inject, "to", (AnnotationHandle)to, remap, "@Slice[" + id + "](to=@At(%s))", sliceContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerInjectionPoint(ExecutableElement element, AnnotationHandle inject, AnnotationHandle at, InjectorRemap remap, String format) {
|
||||
this.injectors.registerInjectionPoint(new AnnotatedElementInjectionPoint(element, inject, at, remap), format);
|
||||
public void registerInjectionPoint(ExecutableElement element, AnnotationHandle inject, String selectorCoordinate, AnnotationHandle at,
|
||||
InjectorRemap remap, String format) {
|
||||
this.injectors.registerInjectionPoint(new AnnotatedElementInjectionPoint(element, inject, this, selectorCoordinate, at, remap), format);
|
||||
}
|
||||
|
||||
public void registerSliceInjectionPoint(ExecutableElement element, AnnotationHandle inject, String selectorCoordinate, AnnotationHandle at,
|
||||
InjectorRemap remap, String format, ISelectorContext parentContext) {
|
||||
this.injectors.registerInjectionPoint(new AnnotatedElementSliceInjectionPoint(element, inject, this, selectorCoordinate, at, remap,
|
||||
parentContext), format);
|
||||
}
|
||||
|
||||
public void registerAccessor(ExecutableElement element, AnnotationHandle accessor, boolean shouldRemap) {
|
||||
this.methods.remove(element);
|
||||
this.accessors.registerAccessor(new AnnotatedElementAccessor(element, accessor, shouldRemap));
|
||||
this.accessors.registerAccessor(new AnnotatedElementAccessor(element, accessor, this, shouldRemap));
|
||||
}
|
||||
|
||||
public void registerInvoker(ExecutableElement element, AnnotationHandle invoker, boolean shouldRemap) {
|
||||
this.methods.remove(element);
|
||||
this.accessors.registerAccessor(new AnnotatedElementInvoker(element, invoker, shouldRemap));
|
||||
this.accessors.registerAccessor(new AnnotatedElementInvoker(element, invoker, this, shouldRemap));
|
||||
}
|
||||
|
||||
public void registerSoftImplements(AnnotationHandle implementsAnnotation) {
|
||||
this.softImplements.process(implementsAnnotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceMapper getReferenceMapper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return this.getClassRef().replace('/', '.');
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClassRef() {
|
||||
return this.primaryTarget.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMixinInfo getMixin() {
|
||||
throw new UnsupportedOperationException("MixinInfo not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extensions getExtensions() {
|
||||
throw new UnsupportedOperationException("Mixin Extensions not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOption(Option option) {
|
||||
throw new UnsupportedOperationException("Options not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
throw new UnsupportedOperationException("Priority not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAnnotationHandle getAnnotation(Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationHandle.of(this.mixin, annotationClass);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
@@ -33,13 +34,17 @@ import javax.lang.model.element.VariableElement;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ISelectorContext;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.ConstraintParser;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
import org.spongepowered.asm.util.asm.IAnnotatedElement;
|
||||
import org.spongepowered.asm.util.asm.IAnnotationHandle;
|
||||
import org.spongepowered.asm.util.throwables.ConstraintViolationException;
|
||||
import org.spongepowered.asm.util.throwables.InvalidConstraintException;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMessagerSuppressible;
|
||||
@@ -64,7 +69,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
*
|
||||
* @param <E> type of inner element
|
||||
*/
|
||||
abstract static class AnnotatedElement<E extends Element> {
|
||||
abstract static class AnnotatedElement<E extends Element> implements IAnnotatedElement {
|
||||
|
||||
protected final E element;
|
||||
|
||||
@@ -102,8 +107,72 @@ abstract class AnnotatedMixinElementHandler {
|
||||
messager.printMessage(kind, msg, this.element, this.annotation.asMirror(), suppressedBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAnnotationHandle getAnnotation(Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationHandle.of(this.element, annotationClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract static class AnnotatedElementExecutable extends AnnotatedElement<ExecutableElement> implements ISelectorContext {
|
||||
|
||||
private final IMixinContext context;
|
||||
|
||||
private final String selectorCoordinate;
|
||||
|
||||
public AnnotatedElementExecutable(ExecutableElement element, AnnotationHandle annotation, IMixinContext context, String selectorCoordinate) {
|
||||
super(element, annotation);
|
||||
this.context = context;
|
||||
this.selectorCoordinate = selectorCoordinate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISelectorContext getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMixinContext getMixin() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMethod() {
|
||||
return new IAnnotatedElement() {
|
||||
@Override
|
||||
public IAnnotationHandle getAnnotation(Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationHandle.of(AnnotatedElementExecutable.this.getElement(), annotationClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return AnnotatedElementExecutable.this.getElement().getSimpleName().toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAnnotationHandle getSelectorAnnotation() {
|
||||
return this.getAnnotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectorCoordinate(boolean leaf) {
|
||||
return leaf ? this.selectorCoordinate : TypeUtils.getName(this.element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String remap(String reference) {
|
||||
return reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return TypeUtils.getName(this.element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A name of an element which may have aliases
|
||||
*/
|
||||
@@ -486,12 +555,12 @@ 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, ITargetSelector reference, String type) {
|
||||
if (!(reference instanceof ITargetSelectorByName)) {
|
||||
protected final void validateReferencedTarget(AnnotatedElementExecutable elem, String reference, ITargetSelector targetSelector, String subject) {
|
||||
if (!(targetSelector instanceof ITargetSelectorByName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ITargetSelectorByName nameRef = (ITargetSelectorByName)reference;
|
||||
ITargetSelectorByName nameRef = (ITargetSelectorByName)targetSelector;
|
||||
String signature = nameRef.toDescriptor();
|
||||
|
||||
for (TypeHandle target : this.mixin.getTargets()) {
|
||||
@@ -501,8 +570,8 @@ abstract class AnnotatedMixinElementHandler {
|
||||
|
||||
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(),
|
||||
SuppressedBy.TARGET);
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target method \"" + nameRef.getName() + nameRef.getDesc() + "\" for " + subject
|
||||
+ " in " + target, elem.getElement(), elem.getAnnotation().asMirror(), SuppressedBy.TARGET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-66
@@ -30,18 +30,12 @@ import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
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;
|
||||
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;
|
||||
@@ -60,21 +54,21 @@ import com.google.common.base.Strings;
|
||||
/**
|
||||
* A module for {@link AnnotatedMixin} which handles accessors
|
||||
*/
|
||||
public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler implements IMixinContext {
|
||||
class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler {
|
||||
|
||||
/**
|
||||
* Accessor element
|
||||
*/
|
||||
static class AnnotatedElementAccessor extends AnnotatedElement<ExecutableElement> {
|
||||
static class AnnotatedElementAccessor extends AnnotatedElementExecutable {
|
||||
|
||||
protected final boolean shouldRemap;
|
||||
|
||||
|
||||
protected final TypeMirror returnType;
|
||||
|
||||
protected String targetName;
|
||||
|
||||
public AnnotatedElementAccessor(ExecutableElement element, AnnotationHandle annotation, boolean shouldRemap) {
|
||||
super(element, annotation);
|
||||
public AnnotatedElementAccessor(ExecutableElement element, AnnotationHandle annotation, IMixinContext context, boolean shouldRemap) {
|
||||
super(element, annotation, context, "value");
|
||||
this.shouldRemap = shouldRemap;
|
||||
this.returnType = this.getElement().getReturnType();
|
||||
}
|
||||
@@ -105,12 +99,12 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
return TypeUtils.getTypeName(this.getTargetType());
|
||||
}
|
||||
|
||||
public String getAccessorDesc() {
|
||||
public String getTargetDesc() {
|
||||
return TypeUtils.getInternalName(this.getTargetType());
|
||||
}
|
||||
|
||||
public ITargetSelectorRemappable getContext() {
|
||||
return new MemberInfo(this.getTargetName(), null, this.getAccessorDesc());
|
||||
return new MemberInfo(this.getTargetName(), null, this.getTargetDesc());
|
||||
}
|
||||
|
||||
public AccessorType getAccessorType() {
|
||||
@@ -147,8 +141,8 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
|
||||
private AccessorType type = AccessorType.METHOD_PROXY;
|
||||
|
||||
public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation, boolean shouldRemap) {
|
||||
super(element, annotation, shouldRemap);
|
||||
public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation, IMixinContext context, boolean shouldRemap) {
|
||||
super(element, annotation, context, shouldRemap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,8 +180,8 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessorDesc() {
|
||||
return TypeUtils.getDescriptor(this.getElement());
|
||||
public String getTargetDesc() {
|
||||
return this.getDesc();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,56 +195,11 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public AnnotatedMixinElementHandlerAccessor(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
super(ap, mixin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceMapper getReferenceMapper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return this.mixin.getClassRef().replace('/', '.');
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassRef() {
|
||||
return this.mixin.getClassRef();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClassRef() {
|
||||
throw new UnsupportedOperationException("Target class not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMixinInfo getMixin() {
|
||||
throw new UnsupportedOperationException("MixinInfo not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extensions getExtensions() {
|
||||
throw new UnsupportedOperationException("Mixin Extensions not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOption(Option option) {
|
||||
throw new UnsupportedOperationException("Options not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
throw new UnsupportedOperationException("Priority not available at compile time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target getTargetMethod(MethodNode into) {
|
||||
throw new UnsupportedOperationException("Target not available at compile time");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new accessor
|
||||
*
|
||||
@@ -294,7 +243,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
return;
|
||||
}
|
||||
|
||||
targetField = new FieldHandle(target.getName(), elem.getTargetName(), elem.getDesc());
|
||||
targetField = new FieldHandle(target.getName(), elem.getTargetName(), elem.getTargetDesc());
|
||||
}
|
||||
|
||||
if (!elem.shouldRemap()) {
|
||||
@@ -326,7 +275,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
return;
|
||||
}
|
||||
|
||||
targetMethod = new MethodHandle(target, elem.getTargetName(), elem.getDesc());
|
||||
targetMethod = new MethodHandle(target, elem.getTargetName(), elem.getTargetDesc());
|
||||
}
|
||||
|
||||
if (!elem.shouldRemap()) {
|
||||
@@ -387,7 +336,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
}
|
||||
|
||||
private String inflectAccessorTarget(AnnotatedElementAccessor elem) {
|
||||
return AccessorInfo.inflectTarget(elem.getSimpleName(), elem.getAccessorType(), "", this, false);
|
||||
return AccessorInfo.inflectTarget(elem.getSimpleName(), elem.getAccessorType(), "", elem, false);
|
||||
}
|
||||
|
||||
}
|
||||
+135
-95
@@ -35,15 +35,18 @@ import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ISelectorContext;
|
||||
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.InvalidSelectorException;
|
||||
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.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.asm.IAnnotationHandle;
|
||||
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
|
||||
import org.spongepowered.tools.obfuscation.ext.SpecialPackages;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
@@ -61,12 +64,12 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
/**
|
||||
* Injector element
|
||||
*/
|
||||
static class AnnotatedElementInjector extends AnnotatedElement<ExecutableElement> {
|
||||
static class AnnotatedElementInjector extends AnnotatedElementExecutable {
|
||||
|
||||
private final InjectorRemap state;
|
||||
|
||||
public AnnotatedElementInjector(ExecutableElement element, AnnotationHandle annotation, InjectorRemap shouldRemap) {
|
||||
super(element, annotation);
|
||||
public AnnotatedElementInjector(ExecutableElement element, AnnotationHandle annotation, IMixinContext context, InjectorRemap shouldRemap) {
|
||||
super(element, annotation, context, "method");
|
||||
this.state = shouldRemap;
|
||||
}
|
||||
|
||||
@@ -100,7 +103,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
/**
|
||||
* Injection point element
|
||||
*/
|
||||
static class AnnotatedElementInjectionPoint extends AnnotatedElement<ExecutableElement> {
|
||||
static class AnnotatedElementInjectionPoint extends AnnotatedElementExecutable {
|
||||
|
||||
private final AnnotationHandle at;
|
||||
|
||||
@@ -108,8 +111,9 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
|
||||
private final InjectorRemap state;
|
||||
|
||||
public AnnotatedElementInjectionPoint(ExecutableElement element, AnnotationHandle inject, AnnotationHandle at, InjectorRemap state) {
|
||||
super(element, inject);
|
||||
public AnnotatedElementInjectionPoint(ExecutableElement element, AnnotationHandle inject, IMixinContext context, String selectorCoordinate,
|
||||
AnnotationHandle at, InjectorRemap state) {
|
||||
super(element, inject, context, selectorCoordinate);
|
||||
this.at = at;
|
||||
this.state = state;
|
||||
}
|
||||
@@ -121,6 +125,16 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
public AnnotationHandle getAt() {
|
||||
return this.at;
|
||||
}
|
||||
|
||||
public AnnotationMirror getAtErrorElement(CompilerEnvironment compilerEnvironment) {
|
||||
// JDT supports hanging the error on the @At annotation directly, doing this in javac doesn't work
|
||||
return (compilerEnvironment == CompilerEnvironment.JDT ? this.getAt() : this.getAnnotation()).asMirror();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAnnotationHandle getSelectorAnnotation() {
|
||||
return this.getAt();
|
||||
}
|
||||
|
||||
public String getAtArg(String key) {
|
||||
if (this.args == null) {
|
||||
@@ -147,6 +161,23 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
|
||||
}
|
||||
|
||||
static class AnnotatedElementSliceInjectionPoint extends AnnotatedElementInjectionPoint {
|
||||
|
||||
private final ISelectorContext parentContext;
|
||||
|
||||
public AnnotatedElementSliceInjectionPoint(ExecutableElement element, AnnotationHandle inject, IMixinContext context,
|
||||
String selectorCoordinate, AnnotationHandle at, InjectorRemap state, ISelectorContext parentContext) {
|
||||
super(element, inject, context, selectorCoordinate, at, state);
|
||||
this.parentContext = parentContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISelectorContext getParent() {
|
||||
return this.parentContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AnnotatedMixinElementHandlerInjector(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
super(ap, mixin);
|
||||
}
|
||||
@@ -157,33 +188,38 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
}
|
||||
|
||||
for (String reference : elem.getAnnotation().<String>getList("method")) {
|
||||
ITargetSelector targetSelector = TargetSelector.parse(reference);
|
||||
|
||||
try {
|
||||
targetSelector.validate();
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
elem.printMessage(this.ap, Kind.ERROR, ex.getMessage());
|
||||
}
|
||||
this.registerInjectorTarget(elem, reference, TargetSelector.parse(reference, elem), elem + ".method=\"" + reference + "\"");
|
||||
}
|
||||
|
||||
for (IAnnotationHandle desc : elem.getAnnotation().getAnnotationList("target")) {
|
||||
String subject = String.format("%s.target=@Desc(id = \"%s\")", elem, desc.<String>getValue("id", ""));
|
||||
this.registerInjectorTarget(elem, null, TargetSelector.parse(desc, elem), subject);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerInjectorTarget(AnnotatedElementInjector elem, String reference, ITargetSelector targetSelector, String subject) {
|
||||
try {
|
||||
targetSelector.validate();
|
||||
} catch (InvalidSelectorException ex) {
|
||||
elem.printMessage(this.ap, Kind.ERROR, ex.getMessage());
|
||||
}
|
||||
|
||||
if (!(targetSelector instanceof ITargetSelectorRemappable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ITargetSelectorRemappable targetMember = (ITargetSelectorRemappable)targetSelector;
|
||||
if (targetMember.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetMember.getDesc() != null) {
|
||||
this.validateReferencedTarget(elem.getElement(), elem.getAnnotation(), targetMember, elem.toString());
|
||||
}
|
||||
|
||||
if (!elem.shouldRemap()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(targetSelector instanceof ITargetSelectorByName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ITargetSelectorByName targetMember = (ITargetSelectorByName)targetSelector;
|
||||
if (targetMember.getName() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetMember.getDesc() != null) {
|
||||
this.validateReferencedTarget(elem, reference, targetMember, subject);
|
||||
}
|
||||
|
||||
if (targetSelector instanceof ITargetSelectorRemappable && elem.shouldRemap()) {
|
||||
for (TypeHandle target : this.mixin.getTargets()) {
|
||||
if (!this.registerInjector(elem, reference, targetMember, target)) {
|
||||
if (!this.registerInjector(elem, reference, (ITargetSelectorRemappable)targetMember, target)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -195,7 +231,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
if (desc == null) {
|
||||
Kind error = this.mixin.isMultiTarget() ? Kind.ERROR : Kind.WARNING;
|
||||
if (target.isSimulated()) {
|
||||
elem.printMessage(this.ap, Kind.NOTE, elem + " target '" + reference + "' in @Pseudo mixin will not be obfuscated");
|
||||
elem.printMessage(this.ap, Kind.OTHER, elem + " target '" + reference + "' in @Pseudo mixin will not be obfuscated");
|
||||
} else if (target.isImaginary()) {
|
||||
elem.printMessage(this.ap, error, elem + " target requires method signature because enclosing type information for "
|
||||
+ target + " is unavailable");
|
||||
@@ -231,8 +267,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
String conflictType = this.mixin.isMultiTarget() ? "Multi-target" : "Target";
|
||||
|
||||
if (elem.hasCoerceArgument() && targetMember.getOwner() == null && targetMember.getDesc() == null) {
|
||||
ITargetSelector oldMember = TargetSelector.parse(ex.getOld());
|
||||
ITargetSelector newMember = TargetSelector.parse(ex.getNew());
|
||||
ITargetSelector oldMember = TargetSelector.parse(ex.getOld(), elem);
|
||||
ITargetSelector newMember = TargetSelector.parse(ex.getNew(), elem);
|
||||
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)) {
|
||||
@@ -264,91 +300,95 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", elem.getElement());
|
||||
}
|
||||
|
||||
if (!elem.shouldRemap()) {
|
||||
return;
|
||||
ITargetSelector targetSelector = null;
|
||||
String targetReference = elem.getAt().<String>getValue("target");
|
||||
if (targetReference != null) {
|
||||
targetSelector = TargetSelector.parse(targetReference, elem);
|
||||
try {
|
||||
targetSelector.validate();
|
||||
} catch (InvalidSelectorException ex) {
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), elem.getAtErrorElement(this.ap.getCompilerEnvironment()));
|
||||
}
|
||||
}
|
||||
|
||||
String type = InjectionPointData.parseType(elem.getAt().<String>getValue("value"));
|
||||
String target = elem.getAt().<String>getValue("target");
|
||||
String type = InjectionPointData.parseType(elem.getAt().<String>getValue("value", ""));
|
||||
|
||||
if ("NEW".equals(type)) {
|
||||
this.remapNewTarget(String.format(format, type + ".<target>"), target, elem);
|
||||
this.remapNewTarget(String.format(format, type + ".args[class]"), elem.getAtArg("class"), elem);
|
||||
} else {
|
||||
this.remapReference(String.format(format, type + ".<target>"), target, elem);
|
||||
ITargetSelector classSelector = null;
|
||||
String classReference = elem.getAtArg("class");
|
||||
if ("NEW".equals(type) && classReference != null) {
|
||||
classSelector = TargetSelector.parse(classReference, elem);
|
||||
try {
|
||||
classSelector.validate();
|
||||
} catch (InvalidSelectorException ex) {
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), elem.getAtErrorElement(this.ap.getCompilerEnvironment()));
|
||||
}
|
||||
}
|
||||
|
||||
if (elem.shouldRemap()) {
|
||||
if ("NEW".equals(type)) {
|
||||
this.remapNewTarget(String.format(format, type + ".<target>"), targetReference, targetSelector, elem);
|
||||
this.remapNewTarget(String.format(format, type + ".args[class]"), classReference, classSelector, elem);
|
||||
} else {
|
||||
this.remapReference(String.format(format, type + ".<target>"), targetReference, targetSelector, elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void remapNewTarget(String subject, String reference, AnnotatedElementInjectionPoint elem) {
|
||||
if (reference == null) {
|
||||
protected final void remapNewTarget(String subject, String reference, ITargetSelector selector, AnnotatedElementInjectionPoint elem) {
|
||||
if (!(selector instanceof ITargetSelectorConstructor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ITargetSelector selector = TargetSelector.parse(reference);
|
||||
if (selector instanceof ITargetSelectorConstructor) {
|
||||
ITargetSelectorConstructor member = (ITargetSelectorConstructor)selector;
|
||||
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() && !SpecialPackages.isExcludedPackage(member.toCtorType())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find class mapping for " + subject + " '" + target + "'", elem.getElement(),
|
||||
elem.getAnnotation().asMirror(), SuppressedBy.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);
|
||||
|
||||
ITargetSelectorConstructor member = (ITargetSelectorConstructor)selector;
|
||||
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() && !SpecialPackages.isExcludedPackage(member.toCtorType())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find class mapping for " + subject + " '" + target + "'", elem.getElement(),
|
||||
elem.getAnnotation().asMirror(), SuppressedBy.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();
|
||||
}
|
||||
|
||||
protected final void remapReference(String subject, String reference, AnnotatedElementInjectionPoint elem) {
|
||||
if (reference == null) {
|
||||
protected final void remapReference(String subject, String reference, ITargetSelector selector, AnnotatedElementInjectionPoint elem) {
|
||||
if (!(selector instanceof ITargetSelectorRemappable)) {
|
||||
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();
|
||||
|
||||
ITargetSelectorRemappable targetMember = (ITargetSelectorRemappable)selector;
|
||||
AnnotationMirror errorElement = elem.getAtErrorElement(this.ap.getCompilerEnvironment());
|
||||
|
||||
if (!targetMember.isFullyQualified()) {
|
||||
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);
|
||||
this.ap.printMessage(Kind.ERROR, subject + " is not fully qualified, missing " + missing, elem.getElement(), errorElement);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
targetMember.validate();
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), errorsOn);
|
||||
}
|
||||
|
||||
try {
|
||||
if (targetMember.isField()) {
|
||||
ObfuscationData<MappingField> obfFieldData = this.obf.getDataProvider().getObfFieldRecursive(targetMember);
|
||||
if (obfFieldData.isEmpty()) {
|
||||
if (targetMember.getOwner() == null || !SpecialPackages.isExcludedPackage(targetMember.getOwner())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn, SuppressedBy.MAPPING);
|
||||
errorElement, SuppressedBy.MAPPING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -358,7 +398,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
if (obfMethodData.isEmpty()) {
|
||||
if (targetMember.getOwner() == null || !SpecialPackages.isExcludedPackage(targetMember.getOwner())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find method mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn, SuppressedBy.MAPPING);
|
||||
errorElement, SuppressedBy.MAPPING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -368,7 +408,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
// Since references are fully-qualified, it shouldn't be possible for there to be multiple mappings, however
|
||||
// we catch and log the error in case something weird happens in the mapping provider
|
||||
this.ap.printMessage(Kind.ERROR, "Unexpected reference conflict for " + subject + ": " + reference + " -> "
|
||||
+ ex.getNew() + " previously defined as " + ex.getOld(), elem.getElement(), errorsOn);
|
||||
+ ex.getNew() + " previously defined as " + ex.getOld(), elem.getElement(), errorElement);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -33,6 +33,7 @@ import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.Interface.Remap;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.asm.IAnnotationHandle;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
|
||||
import org.spongepowered.tools.obfuscation.mirror.MethodHandle;
|
||||
@@ -42,7 +43,7 @@ import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
|
||||
/**
|
||||
* A module for {@link AnnotatedMixin} whic handles soft-implements clauses
|
||||
*/
|
||||
public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinElementHandler {
|
||||
class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinElementHandler {
|
||||
|
||||
AnnotatedMixinElementHandlerSoftImplements(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
super(ap, mixin);
|
||||
@@ -63,15 +64,15 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
|
||||
return;
|
||||
}
|
||||
|
||||
List<AnnotationHandle> interfaces = implementsAnnotation.getAnnotationList("value");
|
||||
List<IAnnotationHandle> interfaces = implementsAnnotation.getAnnotationList("value");
|
||||
|
||||
// Derp?
|
||||
if (interfaces.size() < 1) {
|
||||
this.ap.printMessage(Kind.WARNING, "Empty @Implements annotation", this.mixin.getMixin(), implementsAnnotation.asMirror());
|
||||
this.ap.printMessage(Kind.WARNING, "Empty @Implements annotation", this.mixin.getMixinElement(), implementsAnnotation.asMirror());
|
||||
return;
|
||||
}
|
||||
|
||||
for (AnnotationHandle interfaceAnnotation : interfaces) {
|
||||
for (IAnnotationHandle interfaceAnnotation : interfaces) {
|
||||
Remap remap = interfaceAnnotation.<Remap>getValue("remap", Remap.ALL);
|
||||
if (remap == Remap.NONE) {
|
||||
continue;
|
||||
@@ -82,8 +83,8 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
|
||||
String prefix = interfaceAnnotation.<String>getValue("prefix");
|
||||
this.processSoftImplements(remap, iface, prefix);
|
||||
} catch (Exception ex) {
|
||||
this.ap.printMessage(Kind.ERROR, "Unexpected error: " + ex.getClass().getName() + ": " + ex.getMessage(), this.mixin.getMixin(),
|
||||
interfaceAnnotation.asMirror());
|
||||
this.ap.printMessage(Kind.ERROR, "Unexpected error: " + ex.getClass().getName() + ": " + ex.getMessage(),
|
||||
this.mixin.getMixinElement(), ((AnnotationHandle)interfaceAnnotation).asMirror());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,13 +139,19 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
*/
|
||||
private Properties properties;
|
||||
|
||||
/**
|
||||
* No informational messages, I'm hunting wabbits
|
||||
*/
|
||||
private boolean beVewyVewyQuiet;
|
||||
|
||||
/**
|
||||
* Private constructor, get instances using {@link #getMixinsForEnvironment}
|
||||
*/
|
||||
private AnnotatedMixins(ProcessingEnvironment processingEnv) {
|
||||
this.env = this.detectEnvironment(processingEnv);
|
||||
this.processingEnv = processingEnv;
|
||||
|
||||
this.beVewyVewyQuiet = this.env == CompilerEnvironment.JDT || "true".equalsIgnoreCase(this.getOption(SupportedOptions.QUIET));
|
||||
|
||||
MessageRouter.setMessager(processingEnv.getMessager());
|
||||
|
||||
String pluginVersion = this.checkPluginVersion(this.getOption(SupportedOptions.PLUGIN_VERSION));
|
||||
@@ -557,7 +563,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
public void printMessage(Kind kind, CharSequence msg) {
|
||||
if (kind == Kind.OTHER) return;
|
||||
|
||||
if (this.env == CompilerEnvironment.JAVAC || kind != Kind.NOTE) {
|
||||
if (!this.beVewyVewyQuiet || kind != Kind.NOTE) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg);
|
||||
}
|
||||
}
|
||||
@@ -626,7 +632,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
name = name.replace('/', '.');
|
||||
|
||||
Elements elements = this.processingEnv.getElementUtils();
|
||||
TypeElement element = elements.getTypeElement(name);
|
||||
TypeElement element = this.getTypeElement(name, elements);
|
||||
if (element != null) {
|
||||
try {
|
||||
return new TypeHandle(element);
|
||||
@@ -647,6 +653,66 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a TypeElement representing another type in the current processing
|
||||
* environment. This method attempts substitution of '$' symbols appearing
|
||||
* in the class name when requesting TypeElements from the processing env.
|
||||
*/
|
||||
public TypeElement getTypeElement(String name) {
|
||||
return this.getTypeElement(name.replace('/', '.'), this.processingEnv.getElementUtils());
|
||||
}
|
||||
|
||||
private TypeElement getTypeElement(String name, Elements elements) {
|
||||
// Try fetching directly first
|
||||
TypeElement element = elements.getTypeElement(name);
|
||||
if (element != null || name.indexOf('$') < 0) {
|
||||
return element;
|
||||
}
|
||||
|
||||
int lastDotPos = name.lastIndexOf('.');
|
||||
String pkg = lastDotPos > -1 ? name.substring(0, lastDotPos) : "";
|
||||
name = name.substring(pkg.length());
|
||||
|
||||
// Name has '$' in it, try naive replacement first, this will work for
|
||||
// most cases where there is a single '$' symbol
|
||||
element = elements.getTypeElement(pkg + name.replace('$', '.'));
|
||||
if (element != null) {
|
||||
return element;
|
||||
}
|
||||
|
||||
char[] source = name.toCharArray();
|
||||
char[] dest = new char[source.length];
|
||||
int occurs = 0;
|
||||
|
||||
for (int offset = 0; offset < source.length; offset++) {
|
||||
if (source[offset] == '$') {
|
||||
occurs++;
|
||||
}
|
||||
}
|
||||
|
||||
// Ok someone is trolling if there are more than 10 '$' symbols in a
|
||||
// name! 10 is an arbitary number, we could do more but the loop below
|
||||
// is expensive and something horrible is probably happening if there
|
||||
// are that many '$' signs. We can also skip here if occurs < 2 because
|
||||
// we already tested that case above when we replaced "all"
|
||||
if (occurs > 10 || occurs < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try all possible combinations of replacing '$' with '.' starting at
|
||||
// the end of the string. Not really ideal but if we haven't resolved
|
||||
// the class name by replacing all '$' with '.' then this is our only
|
||||
// remaining approach.
|
||||
for (int mask = 1; mask < 1 << occurs && element == null; mask++) {
|
||||
for (int offset = source.length - 1, index = 0; offset >= 0; offset--) {
|
||||
dest[offset] = (source[offset] == '$' && (mask & (1 << index++)) != 0) ? '.' : source[offset];
|
||||
}
|
||||
element = elements.getTypeElement(pkg + new String(dest));
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simulated TypeHandle for a non-existing type
|
||||
*/
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
/**
|
||||
* Base class for mixin annotation processor modules
|
||||
*/
|
||||
public abstract class MixinObfuscationProcessor extends AbstractProcessor {
|
||||
abstract class MixinObfuscationProcessor extends AbstractProcessor {
|
||||
|
||||
/**
|
||||
* Mixin info manager
|
||||
|
||||
@@ -37,7 +37,6 @@ 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;
|
||||
import org.spongepowered.asm.util.ObfuscationUtil;
|
||||
@@ -281,7 +280,7 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
}
|
||||
}
|
||||
|
||||
return transformed ? new MemberInfo(method.getName(), owner, desc, method.getMatchCount() > 1) : null;
|
||||
return transformed ? method.move(owner).transform(desc) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,7 @@ public final class SupportedOptions {
|
||||
public static final String DEPENDENCY_TARGETS_FILE = "dependencyTargetsFile";
|
||||
public static final String MAPPING_TYPES = "mappingTypes";
|
||||
public static final String PLUGIN_VERSION = "pluginVersion";
|
||||
public static final String QUIET = "quiet";
|
||||
|
||||
private SupportedOptions() {}
|
||||
|
||||
@@ -65,7 +66,8 @@ public final class SupportedOptions {
|
||||
SupportedOptions.DEFAULT_OBFUSCATION_ENV,
|
||||
SupportedOptions.DEPENDENCY_TARGETS_FILE,
|
||||
SupportedOptions.MAPPING_TYPES,
|
||||
SupportedOptions.PLUGIN_VERSION
|
||||
SupportedOptions.PLUGIN_VERSION,
|
||||
SupportedOptions.QUIET
|
||||
);
|
||||
options.addAll(
|
||||
ObfuscationServices.getInstance().getSupportedOptions()
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
/**
|
||||
* A centralised list of tokens supported by the AP for use in
|
||||
* {@link SuppressWarnings} annotations. Collected here mainly for
|
||||
@@ -33,45 +35,79 @@ public enum SuppressedBy {
|
||||
|
||||
/**
|
||||
* Suppress warnings for constraint violations
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'constraints'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
CONSTRAINTS("constraints"),
|
||||
|
||||
/**
|
||||
* Suppress warnings about overwrite visibility upgrading/downgrading target
|
||||
* visibility
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'visibility'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
VISIBILITY("visibility"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when an injector target cannot be found
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'target'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
TARGET("target"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when a class, method or field mapping cannot be located
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'mapping'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
MAPPING("mapping"),
|
||||
|
||||
/**
|
||||
* Suppress warnings for when an <tt>@Overwrite</tt> method is missing
|
||||
* javadoc, or author or reason tags
|
||||
* Suppress warnings for when an {@link Overwrite @Overwrite} method is
|
||||
* missing javadoc, or author or reason tags
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'overwrite'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
OVERWRITE("overwrite"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when a mixin target specified by name is located in the
|
||||
* default package
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'default-package'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
DEFAULT_PACKAGE("default-package"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when a mixin target is resolved by the AP as visible
|
||||
* but cannot be referenced with a class literal for some reason
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'public-target'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
PUBLIC_TARGET("public-target"),
|
||||
|
||||
/**
|
||||
* Suppress warning when a mixin target is resolved by the AP as imaginary
|
||||
* (unresolvable via Mirror at compile time), for example for anonymous
|
||||
* inner classes or other synthetic member classes
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'unresolvable-target'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
UNRESOLVABLE_TARGET("unresolvable-target"),
|
||||
|
||||
/**
|
||||
* The default java "raw types" suppressions
|
||||
* <div class="example">Usage:
|
||||
* <code><b>@SuppressWarnings(<i>'rawtypes'</i>)</b></code>
|
||||
* </div>
|
||||
*/
|
||||
RAW_TYPES("rawtypes");
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class MappingProviderTSrg extends MappingProvider {
|
||||
this.inputMappings.addAll(Files.readLines(input, Charset.defaultCharset()));
|
||||
|
||||
for (String line : this.inputMappings) {
|
||||
if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
|
||||
if (Strings.isNullOrEmpty(line) || line.startsWith("#") || line.startsWith("tsrg2") || line.startsWith("\t\t")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
@@ -35,6 +36,10 @@ import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import org.spongepowered.asm.util.asm.IAnnotationHandle;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -42,7 +47,7 @@ import com.google.common.collect.ImmutableList;
|
||||
* A wrapper for {@link AnnotationMirror} which provides a more convenient way
|
||||
* to access annotation values.
|
||||
*/
|
||||
public final class AnnotationHandle {
|
||||
public final class AnnotationHandle implements IAnnotationHandle {
|
||||
|
||||
public static final AnnotationHandle MISSING = new AnnotationHandle(null);
|
||||
|
||||
@@ -75,10 +80,22 @@ public final class AnnotationHandle {
|
||||
*
|
||||
* @return true if the annotation exists
|
||||
*/
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.annotation != null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.util.asm.IAnnotationHandle#getDesc()
|
||||
*/
|
||||
@Override
|
||||
public String getDesc() {
|
||||
if (this.annotation == null) {
|
||||
return "java/lang/Annotation";
|
||||
}
|
||||
return TypeUtils.getInternalName(this.annotation.getAnnotationType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.annotation == null) {
|
||||
@@ -96,6 +113,7 @@ public final class AnnotationHandle {
|
||||
* @return value or default if not set
|
||||
* @param <T> duck type
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T> T getValue(String key, T defaultValue) {
|
||||
if (this.annotation == null) {
|
||||
@@ -120,6 +138,7 @@ public final class AnnotationHandle {
|
||||
* @param <T> duck type
|
||||
* @return value or null if not present or not set
|
||||
*/
|
||||
@Override
|
||||
public <T> T getValue() {
|
||||
return this.getValue("value", null);
|
||||
}
|
||||
@@ -132,6 +151,7 @@ public final class AnnotationHandle {
|
||||
* @param <T> duck type
|
||||
* @return value or null if not present or not set
|
||||
*/
|
||||
@Override
|
||||
public <T> T getValue(String key) {
|
||||
return this.getValue(key, null);
|
||||
}
|
||||
@@ -154,7 +174,8 @@ public final class AnnotationHandle {
|
||||
* @param key key to search for in the value map
|
||||
* @return value or <tt>null</tt> if not set
|
||||
*/
|
||||
public AnnotationHandle getAnnotation(String key) {
|
||||
@Override
|
||||
public IAnnotationHandle getAnnotation(String key) {
|
||||
Object value = this.getValue(key);
|
||||
if (value instanceof AnnotationMirror) {
|
||||
return AnnotationHandle.of((AnnotationMirror)value);
|
||||
@@ -187,6 +208,7 @@ public final class AnnotationHandle {
|
||||
* @param <T> list element duck type
|
||||
* @return list of values
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> getList(String key) {
|
||||
List<AnnotationValue> list = this.<List<AnnotationValue>>getValue(key, Collections.<AnnotationValue>emptyList());
|
||||
return AnnotationHandle.<T>unwrapAnnotationValueList(list);
|
||||
@@ -198,15 +220,16 @@ public final class AnnotationHandle {
|
||||
* @param key key to fetch
|
||||
* @return list of annotations
|
||||
*/
|
||||
public List<AnnotationHandle> getAnnotationList(String key) {
|
||||
@Override
|
||||
public List<IAnnotationHandle> getAnnotationList(String key) {
|
||||
Object val = this.getValue(key, null);
|
||||
if (val == null) {
|
||||
return Collections.<AnnotationHandle>emptyList();
|
||||
return Collections.<IAnnotationHandle>emptyList();
|
||||
}
|
||||
|
||||
// Fix for JDT, single values are just returned as a bare AnnotationMirror
|
||||
if (val instanceof AnnotationMirror) {
|
||||
return ImmutableList.<AnnotationHandle>of(AnnotationHandle.of((AnnotationMirror)val));
|
||||
return ImmutableList.<IAnnotationHandle>of(AnnotationHandle.of((AnnotationMirror)val));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") List<AnnotationValue> list = (List<AnnotationValue>)val;
|
||||
@@ -214,7 +237,25 @@ public final class AnnotationHandle {
|
||||
for (AnnotationValue value : list) {
|
||||
annotations.add(new AnnotationHandle((AnnotationMirror)value.getValue()));
|
||||
}
|
||||
return Collections.<AnnotationHandle>unmodifiableList(annotations);
|
||||
return Collections.<IAnnotationHandle>unmodifiableList(annotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getTypeValue(String key) {
|
||||
TypeMirror typeMirror = this.<TypeMirror>getValue(key);
|
||||
return typeMirror == null ? Type.VOID_TYPE : Type.getType(TypeUtils.getInternalName(typeMirror));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Type> getTypeList(String key) {
|
||||
List<Type> list = this.<Type>getList(key);
|
||||
for (ListIterator<Type> iter = list.listIterator(); iter.hasNext();) {
|
||||
Object next = iter.next();
|
||||
if (next instanceof TypeMirror) {
|
||||
iter.set(Type.getType(TypeUtils.getInternalName((TypeMirror)next)));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected AnnotationValue getAnnotationValue(String key) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base package for the Mixin Annotation Processor.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
Reference in new issue
Block a user