mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 00:39:34 +00:00
Refactor annotation handling in the AP
This commit is contained in:
1 parent
4934071ee7
commit
c007eabc31
18 files changed
+378
-258
No files matched your search
@@ -26,12 +26,9 @@ package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@@ -41,7 +38,6 @@ import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerAccessor.AnnotatedElementAccessor;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerAccessor.AnnotatedElementInvoker;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerInjector.AnnotatedElementInjectionPoint;
|
||||
@@ -63,7 +59,7 @@ class AnnotatedMixin {
|
||||
/**
|
||||
* Mixin annotation
|
||||
*/
|
||||
private final AnnotationMirror annotation;
|
||||
private final AnnotationHandle annotation;
|
||||
|
||||
/**
|
||||
* Messager
|
||||
@@ -141,13 +137,13 @@ class AnnotatedMixin {
|
||||
private final AnnotatedMixinElementHandlerSoftImplements softImplements;
|
||||
|
||||
public AnnotatedMixin(IMixinAnnotationProcessor ap, TypeElement type) {
|
||||
this.annotation = MirrorUtils.getAnnotation(type, Mixin.class);
|
||||
this.typeProvider = ap.getTypeProvider();
|
||||
this.obf = ap.getObfuscationManager();
|
||||
this.mappings = this.obf.createMappingConsumer();
|
||||
this.messager = ap;
|
||||
this.mixin = type;
|
||||
this.handle = new TypeHandle(type);
|
||||
this.annotation = this.handle.getAnnotation(Mixin.class);
|
||||
this.classRef = type.getQualifiedName().toString().replace('.', '/');
|
||||
this.primaryTarget = this.initTargets();
|
||||
this.remap = AnnotatedMixins.getRemapValue(this.annotation) && this.targets.size() > 0;
|
||||
@@ -174,9 +170,7 @@ class AnnotatedMixin {
|
||||
|
||||
// Public targets, referenced by class
|
||||
try {
|
||||
List<AnnotationValue> publicTargets = MirrorUtils.<List<AnnotationValue>>getAnnotationValue(this.annotation, "value",
|
||||
Collections.<AnnotationValue>emptyList());
|
||||
for (TypeMirror target : MirrorUtils.<TypeMirror>unfold(publicTargets)) {
|
||||
for (TypeMirror target : this.annotation.<TypeMirror>getList()) {
|
||||
TypeHandle type = new TypeHandle((DeclaredType)target);
|
||||
if (this.targets.contains(type)) {
|
||||
continue;
|
||||
@@ -192,9 +186,7 @@ class AnnotatedMixin {
|
||||
|
||||
// Private targets, referenced by name
|
||||
try {
|
||||
List<AnnotationValue> privateTargets = MirrorUtils.<List<AnnotationValue>>getAnnotationValue(this.annotation, "targets",
|
||||
Collections.<AnnotationValue>emptyList());
|
||||
for (String privateTarget : MirrorUtils.<String>unfold(privateTargets)) {
|
||||
for (String privateTarget : this.annotation.<String>getList("targets")) {
|
||||
TypeHandle type = this.typeProvider.getTypeHandle(privateTarget);
|
||||
if (this.targets.contains(type)) {
|
||||
continue;
|
||||
@@ -226,7 +218,7 @@ class AnnotatedMixin {
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
private void printMessage(Kind kind, CharSequence msg, AnnotatedMixin mixin) {
|
||||
this.messager.printMessage(kind, msg, this.mixin, this.annotation);
|
||||
this.messager.printMessage(kind, msg, this.mixin, this.annotation.asMirror());
|
||||
}
|
||||
|
||||
private void addSoftTarget(TypeHandle type, String reference) {
|
||||
@@ -247,7 +239,7 @@ class AnnotatedMixin {
|
||||
return this.mixin.getSimpleName().toString();
|
||||
}
|
||||
|
||||
public AnnotationMirror getAnnotation() {
|
||||
public AnnotationHandle getAnnotation() {
|
||||
return this.annotation;
|
||||
}
|
||||
|
||||
@@ -312,35 +304,35 @@ class AnnotatedMixin {
|
||||
return this.mappings;
|
||||
}
|
||||
|
||||
public void registerOverwrite(ExecutableElement method, AnnotationMirror overwrite) {
|
||||
public void registerOverwrite(ExecutableElement method, AnnotationHandle overwrite) {
|
||||
this.overwrites.registerOverwrite(new AnnotatedElementOverwrite(method, overwrite));
|
||||
}
|
||||
|
||||
public void registerShadow(VariableElement field, AnnotationMirror shadow, boolean shouldRemap) {
|
||||
public void registerShadow(VariableElement field, AnnotationHandle shadow, boolean shouldRemap) {
|
||||
this.shadows.registerShadow(this.shadows.new AnnotatedElementShadowField(field, shadow, shouldRemap));
|
||||
}
|
||||
|
||||
public void registerShadow(ExecutableElement method, AnnotationMirror shadow, boolean shouldRemap) {
|
||||
public void registerShadow(ExecutableElement method, AnnotationHandle shadow, boolean shouldRemap) {
|
||||
this.shadows.registerShadow(this.shadows.new AnnotatedElementShadowMethod(method, shadow, shouldRemap));
|
||||
}
|
||||
|
||||
public Message registerInjector(ExecutableElement method, AnnotationMirror inject, boolean shouldRemap) {
|
||||
public Message registerInjector(ExecutableElement method, AnnotationHandle inject, boolean shouldRemap) {
|
||||
return this.injectors.registerInjector(new AnnotatedElementInjector(method, inject, shouldRemap));
|
||||
}
|
||||
|
||||
public int registerInjectionPoint(ExecutableElement element, AnnotationMirror inject, AnnotationMirror at) {
|
||||
public int registerInjectionPoint(ExecutableElement element, AnnotationHandle inject, AnnotationHandle at) {
|
||||
return this.injectors.registerInjectionPoint(new AnnotatedElementInjectionPoint(element, inject, at));
|
||||
}
|
||||
|
||||
public void registerAccessor(ExecutableElement element, AnnotationMirror accessor) {
|
||||
public void registerAccessor(ExecutableElement element, AnnotationHandle accessor) {
|
||||
this.accessors.registerAccessor(new AnnotatedElementAccessor(element, accessor));
|
||||
}
|
||||
|
||||
public void registerInvoker(ExecutableElement element, AnnotationMirror invoker) {
|
||||
public void registerInvoker(ExecutableElement element, AnnotationHandle invoker) {
|
||||
this.accessors.registerAccessor(new AnnotatedElementInvoker(element, invoker));
|
||||
}
|
||||
|
||||
public void registerSoftImplements(AnnotationMirror implementsAnnotation) {
|
||||
public void registerSoftImplements(AnnotationHandle implementsAnnotation) {
|
||||
this.softImplements.process(implementsAnnotation);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user