mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 20:22:31 +00:00
WIP but mostly working Desc selector functionality
This commit is contained in:
1 parent
2ef2417de6
commit
21881482ae
27 files changed
+998
-42
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;
|
||||
@@ -47,6 +48,8 @@ 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.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;
|
||||
@@ -70,7 +73,7 @@ import com.google.common.base.Strings;
|
||||
/**
|
||||
* Information about a mixin stored during processing
|
||||
*/
|
||||
class AnnotatedMixin implements IMixinContext {
|
||||
class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
|
||||
|
||||
/**
|
||||
* Mixin annotation
|
||||
@@ -386,13 +389,13 @@ class AnnotatedMixin implements IMixinContext {
|
||||
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", 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)) {
|
||||
@@ -400,14 +403,15 @@ class AnnotatedMixin implements IMixinContext {
|
||||
}
|
||||
SelectorAnnotationContext sliceContext = new SelectorAnnotationContext(injectorElement, slice, coord);
|
||||
|
||||
AnnotationHandle from = slice.getAnnotation("from");
|
||||
IAnnotationHandle from = slice.getAnnotation("from");
|
||||
if (from != null) {
|
||||
this.registerSliceInjectionPoint(method, inject, "from", from, remap, "@Slice[" + id + "](from=@At(%s))", sliceContext);
|
||||
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.registerSliceInjectionPoint(method, inject, "to", to, remap, "@Slice[" + id + "](to=@At(%s))", sliceContext);
|
||||
this.registerSliceInjectionPoint(method, inject, "to", (AnnotationHandle)to, remap, "@Slice[" + id + "](to=@At(%s))", sliceContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,7 +453,7 @@ class AnnotatedMixin implements IMixinContext {
|
||||
|
||||
@Override
|
||||
public String getTargetClassRef() {
|
||||
throw new UnsupportedOperationException("Target class not available at compile time");
|
||||
return this.primaryTarget.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -476,5 +480,10 @@ class AnnotatedMixin implements IMixinContext {
|
||||
public Target getTargetMethod(MethodNode into) {
|
||||
throw new UnsupportedOperationException("Target 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;
|
||||
@@ -42,6 +43,8 @@ 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;
|
||||
@@ -66,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;
|
||||
|
||||
@@ -104,6 +107,11 @@ 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 {
|
||||
@@ -130,7 +138,12 @@ abstract class AnnotatedMixinElementHandler {
|
||||
|
||||
@Override
|
||||
public Object getMethod() {
|
||||
return this.getElement();
|
||||
return new IAnnotatedElement() {
|
||||
@Override
|
||||
public IAnnotationHandle getAnnotation(Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationHandle.of(AnnotatedElementExecutable.this.getElement(), annotationClass);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,8 +152,8 @@ abstract class AnnotatedMixinElementHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectorCoordinate() {
|
||||
return this.selectorCoordinate;
|
||||
public String getSelectorCoordinate(boolean leaf) {
|
||||
return leaf ? this.selectorCoordinate : TypeUtils.getName(this.element);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-3
@@ -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;
|
||||
@@ -63,7 +64,7 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
|
||||
return;
|
||||
}
|
||||
|
||||
List<AnnotationHandle> interfaces = implementsAnnotation.getAnnotationList("value");
|
||||
List<IAnnotationHandle> interfaces = implementsAnnotation.getAnnotationList("value");
|
||||
|
||||
// Derp?
|
||||
if (interfaces.size() < 1) {
|
||||
@@ -71,7 +72,7 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
|
||||
return;
|
||||
}
|
||||
|
||||
for (AnnotationHandle interfaceAnnotation : interfaces) {
|
||||
for (IAnnotationHandle interfaceAnnotation : interfaces) {
|
||||
Remap remap = interfaceAnnotation.<Remap>getValue("remap", Remap.ALL);
|
||||
if (remap == Remap.NONE) {
|
||||
continue;
|
||||
@@ -83,7 +84,7 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
|
||||
this.processSoftImplements(remap, iface, prefix);
|
||||
} catch (Exception ex) {
|
||||
this.ap.printMessage(Kind.ERROR, "Unexpected error: " + ex.getClass().getName() + ": " + ex.getMessage(),
|
||||
this.mixin.getMixinElement(), interfaceAnnotation.asMirror());
|
||||
this.mixin.getMixinElement(), ((AnnotationHandle)interfaceAnnotation).asMirror());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,7 +36,9 @@ 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;
|
||||
@@ -109,6 +112,7 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
* @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) {
|
||||
@@ -133,6 +137,7 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
* @param <T> duck type
|
||||
* @return value or null if not present or not set
|
||||
*/
|
||||
@Override
|
||||
public <T> T getValue() {
|
||||
return this.getValue("value", null);
|
||||
}
|
||||
@@ -145,6 +150,7 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
* @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);
|
||||
}
|
||||
@@ -167,7 +173,8 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
* @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);
|
||||
@@ -200,6 +207,7 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
* @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);
|
||||
@@ -211,15 +219,16 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
* @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;
|
||||
@@ -227,7 +236,19 @@ public final class AnnotationHandle implements IAnnotationHandle {
|
||||
for (AnnotationValue value : list) {
|
||||
annotations.add(new AnnotationHandle((AnnotationMirror)value.getValue()));
|
||||
}
|
||||
return Collections.<AnnotationHandle>unmodifiableList(annotations);
|
||||
return Collections.<IAnnotationHandle>unmodifiableList(annotations);
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
Reference in new issue
Block a user