Enhanced AP messaging, detect IDEA, support configurable message levels

This commit is contained in:
Mumfrey committed 2021-10-16 13:24:30 +01:00
1 parent 8dbd876225
commit 812bfcc811
25 files changed
+972 -204

No files matched your search

@@ -35,11 +35,10 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
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.Pseudo;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.injection.selectors.ISelectorContext;
import org.spongepowered.asm.mixin.injection.struct.SelectorAnnotationContext;
@@ -51,9 +50,10 @@ 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.AnnotatedMixinElementHandlerInjector.AnnotatedElementSliceInjectionPoint;
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerOverwrite.AnnotatedElementOverwrite;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerSuppressible;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
@@ -182,7 +182,7 @@ class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
this.virtual = this.handle.getAnnotation(Pseudo.class).exists();
this.annotation = this.handle.getAnnotation(Mixin.class);
this.classRef = TypeUtils.getInternalName(type);
this.primaryTarget = this.initTargets();
this.primaryTarget = this.initTargets(ap);
this.remap = this.annotation.getBoolean("remap", true) && this.targets.size() > 0;
this.overwrites = new AnnotatedMixinElementHandlerOverwrite(ap, this);
@@ -207,7 +207,7 @@ class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
return this;
}
private TypeHandle initTargets() {
private TypeHandle initTargets(IMixinAnnotationProcessor ap) {
TypeHandle primaryTarget = null;
// Public targets, referenced by class
@@ -223,7 +223,7 @@ class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
}
}
} catch (Exception ex) {
this.printMessage(Kind.WARNING, "Error processing public targets: " + ex.getClass().getName() + ": " + ex.getMessage(), this);
this.printMessage(MessageType.WARNING, "Error processing public targets: " + ex.getClass().getName() + ": " + ex.getMessage());
}
// Private targets, referenced by name
@@ -236,15 +236,16 @@ class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
if (this.virtual) {
type = this.typeProvider.getSimulatedHandle(softTarget, this.mixin.asType());
} else if (type == null) {
this.printMessage(Kind.ERROR, "Mixin target " + softTarget + " could not be found", this);
this.printMessage(MessageType.MIXIN_SOFT_TARGET_NOT_FOUND, "Mixin target " + softTarget + " could not be found");
return null;
} else if (type.isImaginary()) {
this.printMessage(Kind.WARNING, "Mixin target " + softTarget + " could not be fully resolved.", this,
this.printMessage(MessageType.MIXIN_SOFT_TARGET_NOT_RESOLVED, "Mixin target " + softTarget + " could not be fully resolved.",
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);
this.printMessage(MessageType.MIXIN_SOFT_TARGET_IS_PUBLIC, "Mixin target " + softTarget
+ " is public and must be specified in value", suppressedBy);
return null;
}
this.addSoftTarget(type, softTarget);
@@ -253,11 +254,11 @@ class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
}
}
} catch (Exception ex) {
this.printMessage(Kind.WARNING, "Error processing private targets: " + ex.getClass().getName() + ": " + ex.getMessage(), this);
this.printMessage(MessageType.WARNING, "Error processing private targets: " + ex.getClass().getName() + ": " + ex.getMessage());
}
if (primaryTarget == null) {
this.printMessage(Kind.ERROR, "Mixin has no targets", this);
this.printMessage(MessageType.MIXIN_NO_TARGETS, "Mixin has no targets");
}
return primaryTarget;
@@ -266,15 +267,15 @@ class AnnotatedMixin implements IMixinContext, IAnnotatedElement {
/**
* 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.asMirror());
private void printMessage(MessageType type, CharSequence msg) {
this.messager.printMessage(type, msg, this.mixin, this.annotation.asMirror());
}
/**
* Print a suppressible message to the AP messager
*/
private void printMessage(Kind kind, CharSequence msg, AnnotatedMixin mixin, SuppressedBy suppressedBy) {
this.messager.printMessage(kind, msg, this.mixin, this.annotation.asMirror(), suppressedBy);
private void printMessage(MessageType type, CharSequence msg, SuppressedBy suppressedBy) {
this.messager.printMessage(type, msg, this.mixin, this.annotation.asMirror(), suppressedBy);
}
private void addSoftTarget(TypeHandle type, String reference) {
@@ -27,12 +27,9 @@ package org.spongepowered.tools.obfuscation;
import java.lang.annotation.Annotation;
import java.util.List;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
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;
@@ -47,6 +44,8 @@ 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.IMessagerEx;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerSuppressible;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
@@ -99,12 +98,12 @@ abstract class AnnotatedMixinElementHandler {
return this.desc;
}
public final void printMessage(Messager messager, Diagnostic.Kind kind, CharSequence msg) {
messager.printMessage(kind, msg, this.element, this.annotation.asMirror());
public final void printMessage(IMessagerEx messager, MessageType type, CharSequence msg) {
messager.printMessage(type, msg, this.element, this.annotation.asMirror());
}
public final void printMessage(IMessagerSuppressible messager, Diagnostic.Kind kind, CharSequence msg, SuppressedBy suppressedBy) {
messager.printMessage(kind, msg, this.element, this.annotation.asMirror(), suppressedBy);
public final void printMessage(IMessagerSuppressible messager, MessageType type, CharSequence msg, SuppressedBy suppressedBy) {
messager.printMessage(type, msg, this.element, this.annotation.asMirror(), suppressedBy);
}
@Override
@@ -445,10 +444,10 @@ abstract class AnnotatedMixinElementHandler {
try {
constraint.check(this.ap.getTokenProvider());
} catch (ConstraintViolationException ex) {
this.ap.printMessage(Kind.ERROR, ex.getMessage(), method, annotation.asMirror());
this.ap.printMessage(MessageType.CONSTRAINT_VIOLATION, ex.getMessage(), method, annotation.asMirror());
}
} catch (InvalidConstraintException ex) {
this.ap.printMessage(Kind.WARNING, ex.getMessage(), method, annotation.asMirror(), SuppressedBy.CONSTRAINTS);
this.ap.printMessage(MessageType.INVALID_CONSTRAINT, ex.getMessage(), method, annotation.asMirror(), SuppressedBy.CONSTRAINTS);
}
}
@@ -495,7 +494,8 @@ 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, SuppressedBy.TARGET);
this.printMessage(MessageType.TARGET_ELEMENT_NOT_FOUND, "Cannot find target for " + type + " method in " + target,
method, annotation, SuppressedBy.TARGET);
}
}
}
@@ -510,10 +510,10 @@ 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(MessageType.METHOD_VISIBILITY, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation,
SuppressedBy.VISIBILITY);
} else if (visTarget == Visibility.PRIVATE && visMethod.ordinal() > visTarget.ordinal()) {
this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation,
this.printMessage(MessageType.METHOD_VISIBILITY, visMethod + " " + type + " method will upgrade " + visibility, method, annotation,
SuppressedBy.VISIBILITY);
}
}
@@ -545,8 +545,8 @@ abstract class AnnotatedMixinElementHandler {
}
if (targetField == null) {
this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, annotation.asMirror(),
SuppressedBy.TARGET);
this.ap.printMessage(MessageType.TARGET_ELEMENT_NOT_FOUND, "Cannot find target for " + type + " field in " + target,
field, annotation.asMirror(), SuppressedBy.TARGET);
}
}
}
@@ -570,17 +570,18 @@ abstract class AnnotatedMixinElementHandler {
MethodHandle targetMethod = target.findMethod(nameRef.getName(), signature);
if (targetMethod == null) {
this.ap.printMessage(Kind.WARNING, "Cannot find target method \"" + nameRef.getName() + nameRef.getDesc() + "\" for " + subject
+ " in " + target, elem.getElement(), elem.getAnnotation().asMirror(), SuppressedBy.TARGET);
this.ap.printMessage(MessageType.TARGET_ELEMENT_NOT_FOUND, "Cannot find target method \"" + nameRef.getName()
+ nameRef.getDesc() + "\" for " + subject + " in " + target, elem.getElement(), elem.getAnnotation().asMirror(),
SuppressedBy.TARGET);
}
}
}
private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation, SuppressedBy suppressedBy) {
private void printMessage(MessageType type, String msg, Element e, AnnotationHandle annotation, SuppressedBy suppressedBy) {
if (annotation == null) {
this.ap.printMessage(kind, msg, e, suppressedBy);
this.ap.printMessage(type, msg, e, suppressedBy);
} else {
this.ap.printMessage(kind, msg, e, annotation.asMirror(), suppressedBy);
this.ap.printMessage(type, msg, e, annotation.asMirror(), suppressedBy);
}
}
@@ -28,7 +28,6 @@ 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.mixin.gen.AccessorInfo;
import org.spongepowered.asm.mixin.gen.AccessorInfo.AccessorName;
@@ -40,6 +39,7 @@ 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.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.FieldHandle;
@@ -207,13 +207,13 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
*/
public void registerAccessor(AnnotatedElementAccessor elem) {
if (elem.getAccessorType() == null) {
elem.printMessage(this.ap, Kind.WARNING, "Unsupported accessor type");
elem.printMessage(this.ap, MessageType.ACCESSOR_TYPE_UNSUPPORTED, "Unsupported accessor type");
return;
}
String targetName = this.getAccessorTargetName(elem);
if (targetName == null) {
elem.printMessage(this.ap, Kind.WARNING, "Cannot inflect accessor target name");
elem.printMessage(this.ap, MessageType.ACCESSOR_NAME_UNRESOLVED, "Cannot inflect accessor target name");
return;
}
elem.setTargetName(targetName);
@@ -222,7 +222,7 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
try {
elem.attach(target);
} catch (Exception ex) {
elem.printMessage(this.ap, Kind.ERROR, ex.getMessage());
elem.printMessage(this.ap, MessageType.ACCESSOR_ATTACH_ERROR, ex.getMessage());
continue;
}
if (elem.getAccessorType() == AccessorType.OBJECT_FACTORY) {
@@ -239,7 +239,8 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
FieldHandle targetField = target.findField(elem.getTargetName(), elem.getTargetTypeName(), false);
if (targetField == null) {
if (!target.isImaginary()) {
elem.printMessage(this.ap, Kind.ERROR, "Could not locate @Accessor target " + elem + " in target " + target);
elem.printMessage(this.ap, MessageType.ACCESSOR_TARGET_NOT_FOUND,
"Could not locate @Accessor target " + elem + " in target " + target);
return;
}
@@ -253,7 +254,8 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
ObfuscationData<MappingField> obfData = this.obf.getDataProvider().getObfField(targetField.asMapping(false).move(target.getName()));
if (obfData.isEmpty()) {
String info = this.mixin.isMultiTarget() ? " in target " + target : "";
elem.printMessage(this.ap, Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Accessor target " + elem);
elem.printMessage(this.ap, MessageType.NO_OBFDATA_FOR_ACCESSOR,
"Unable to locate obfuscation mapping" + info + " for @Accessor target " + elem);
return;
}
@@ -262,8 +264,8 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
try {
this.obf.getReferenceManager().addFieldMapping(this.mixin.getClassRef(), elem.getTargetName(), elem.getContext(), obfData);
} catch (ReferenceConflictException ex) {
elem.printMessage(this.ap, Kind.ERROR, "Mapping conflict for @Accessor target " + elem + ": " + ex.getNew() + " for target "
+ target + " conflicts with existing mapping " + ex.getOld());
elem.printMessage(this.ap, MessageType.ACCESSOR_MAPPING_CONFLICT, "Mapping conflict for @Accessor target " + elem + ": "
+ ex.getNew() + " for target " + target + " conflicts with existing mapping " + ex.getOld());
}
}
@@ -271,7 +273,8 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
MethodHandle targetMethod = target.findMethod(elem.getTargetName(), elem.getTargetTypeName(), false);
if (targetMethod == null) {
if (!target.isImaginary()) {
elem.printMessage(this.ap, Kind.ERROR, "Could not locate @Invoker target " + elem + " in target " + target);
elem.printMessage(this.ap, MessageType.ACCESSOR_TARGET_NOT_FOUND,
"Could not locate @Invoker target " + elem + " in target " + target);
return;
}
@@ -285,7 +288,8 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
ObfuscationData<MappingMethod> obfData = this.obf.getDataProvider().getObfMethod(targetMethod.asMapping(false).move(target.getName()));
if (obfData.isEmpty()) {
String info = this.mixin.isMultiTarget() ? " in target " + target : "";
elem.printMessage(this.ap, Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Accessor target " + elem);
elem.printMessage(this.ap, MessageType.NO_OBFDATA_FOR_ACCESSOR,
"Unable to locate obfuscation mapping" + info + " for @Accessor target " + elem);
return;
}
@@ -294,8 +298,8 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
try {
this.obf.getReferenceManager().addMethodMapping(this.mixin.getClassRef(), elem.getTargetName(), elem.getContext(), obfData);
} catch (ReferenceConflictException ex) {
elem.printMessage(this.ap, Kind.ERROR, "Mapping conflict for @Invoker target " + elem + ": " + ex.getNew() + " for target "
+ target + " conflicts with existing mapping " + ex.getOld());
elem.printMessage(this.ap, MessageType.ACCESSOR_MAPPING_CONFLICT, "Mapping conflict for @Invoker target " + elem + ": "
+ ex.getNew() + " for target " + target + " conflicts with existing mapping " + ex.getOld());
}
}
@@ -303,19 +307,19 @@ class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementHandler
EquivalencyResult equivalency = TypeUtils.isEquivalentType(this.ap.getProcessingEnvironment(), elem.getReturnType(), target.getType());
if (equivalency.type != Equivalency.EQUIVALENT) {
if (equivalency.type == Equivalency.EQUIVALENT_BUT_RAW && equivalency.rawType == 1) {
elem.printMessage(this.ap, Kind.WARNING, "Raw return type for Factory @Invoker", SuppressedBy.RAW_TYPES);
elem.printMessage(this.ap, MessageType.INVOKER_RAW_RETURN_TYPE, "Raw return type for Factory @Invoker", SuppressedBy.RAW_TYPES);
} else if (equivalency.type == Equivalency.BOUNDS_MISMATCH) {
elem.printMessage(this.ap, Kind.ERROR, "Invalid Factory @Invoker return type, generic type arguments of " + target.getType()
+ " are incompatible with " + elem.getReturnType() + ". " + equivalency);
elem.printMessage(this.ap, MessageType.FACTORY_INVOKER_GENERIC_ARGS, "Invalid Factory @Invoker return type, generic type args of "
+ target.getType() + " are incompatible with " + elem.getReturnType() + ". " + equivalency);
return;
} else {
elem.printMessage(this.ap, Kind.ERROR, "Invalid Factory @Invoker return type, expected " + target.getType() + " but found "
+ elem.getReturnType());
elem.printMessage(this.ap, MessageType.FACTORY_INVOKER_RETURN_TYPE, "Invalid Factory @Invoker return type, expected "
+ target.getType() + " but found " + elem.getReturnType());
return;
}
}
if (!elem.isStatic()) {
elem.printMessage(this.ap, Kind.ERROR, "Factory @Invoker must be static");
elem.printMessage(this.ap, MessageType.FACTORY_INVOKER_NONSTATIC, "Factory @Invoker must be static");
return;
}
@@ -31,8 +31,6 @@ import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.selectors.ISelectorContext;
@@ -49,6 +47,7 @@ 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.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor.CompilerEnvironment;
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
@@ -89,8 +88,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
return false;
}
public void addMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationHandle annotation) {
this.state.addMessage(kind, msg, element, annotation);
public void addMessage(MessageType type, CharSequence msg, Element element, AnnotationHandle annotation) {
this.state.addMessage(type, msg, element, annotation);
}
@Override
@@ -127,8 +126,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
}
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();
// JDT and IDEA support hanging the error on the @At annotation directly, doing this in javac doesn't work
return (compilerEnvironment.isDevelopmentEnvironment() ? this.getAt() : this.getAnnotation()).asMirror();
}
@Override
@@ -184,7 +183,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
public void registerInjector(AnnotatedElementInjector elem) {
if (this.mixin.isInterface()) {
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", elem.getElement());
this.ap.printMessage(MessageType.INJECTOR_IN_INTERFACE, "Injector in interface is unsupported", elem.getElement());
}
for (String reference : elem.getAnnotation().<String>getList("method")) {
@@ -201,7 +200,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
try {
targetSelector.validate();
} catch (InvalidSelectorException ex) {
elem.printMessage(this.ap, Kind.ERROR, ex.getMessage());
elem.printMessage(this.ap, MessageType.TARGET_SELECTOR_VALIDATION, ex.getMessage());
}
if (!(targetSelector instanceof ITargetSelectorByName)) {
@@ -229,14 +228,16 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
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;
MessageType messageType = this.mixin.isMultiTarget() ? MessageType.MISSING_INJECTOR_DESC_MULTITARGET
: MessageType.MISSING_INJECTOR_DESC_SINGLETARGET;
if (target.isSimulated()) {
elem.printMessage(this.ap, Kind.OTHER, elem + " target '" + reference + "' in @Pseudo mixin will not be obfuscated");
elem.printMessage(this.ap, MessageType.MISSING_INJECTOR_DESC_SIMULATED, 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 "
elem.printMessage(this.ap, messageType, elem + " target requires method signature because enclosing type information for "
+ target + " is unavailable");
} else if (!targetMember.isInitialiser()) {
elem.printMessage(this.ap, error, "Unable to determine signature for " + elem + " target method");
elem.printMessage(this.ap, messageType, "Unable to determine descriptor for " + elem + " target method");
}
return true;
}
@@ -250,8 +251,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
} else if (targetMember.isClassInitialiser()) {
return true;
} else {
Kind error = targetMember.isConstructor() ? Kind.WARNING : Kind.ERROR;
elem.addMessage(error, "No obfuscation mapping for " + targetName, elem.getElement(), elem.getAnnotation());
elem.addMessage(targetMember.isConstructor() ? MessageType.NO_OBFDATA_FOR_CTOR : MessageType.NO_OBFDATA_FOR_TARGET,
"Unable to locate obfuscation mapping for " + targetName, elem.getElement(), elem.getAnnotation());
return false;
}
}
@@ -278,14 +279,14 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
refMap.setAllowConflicts(false);
// This is bad because in notch mappings, using the bare target name might cause everything to explode
elem.printMessage(this.ap, Kind.WARNING, "Coerced " + conflictType + " reference has conflicting descriptors for " + targetName
+ ": Storing bare references " + obfData.values() + " in refMap");
elem.printMessage(this.ap, MessageType.BARE_REFERENCE, "Coerced " + conflictType + " reference has conflicting descriptors for "
+ targetName + ": Storing bare references " + obfData.values() + " in refMap");
return true;
}
}
elem.printMessage(this.ap, Kind.ERROR, conflictType + " reference conflict for " + targetName + ": " + reference + " -> "
+ ex.getNew() + " previously defined as " + ex.getOld());
elem.printMessage(this.ap, MessageType.INJECTOR_MAPPING_CONFLICT, conflictType + " reference conflict for " + targetName + ": "
+ reference + " -> " + ex.getNew() + " previously defined as " + ex.getOld());
}
return true;
@@ -297,7 +298,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
*/
public void registerInjectionPoint(AnnotatedElementInjectionPoint elem, String format) {
if (this.mixin.isInterface()) {
this.ap.printMessage(Kind.ERROR, "Injector in interface is unsupported", elem.getElement());
this.ap.printMessage(MessageType.INJECTOR_IN_INTERFACE, "Injector in interface is unsupported", elem.getElement());
}
ITargetSelector targetSelector = null;
@@ -307,7 +308,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
try {
targetSelector.validate();
} catch (InvalidSelectorException ex) {
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), elem.getAtErrorElement(this.ap.getCompilerEnvironment()));
this.ap.printMessage(MessageType.TARGET_SELECTOR_VALIDATION, ex.getMessage(), elem.getElement(),
elem.getAtErrorElement(this.ap.getCompilerEnvironment()));
}
}
@@ -320,7 +322,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
try {
classSelector.validate();
} catch (InvalidSelectorException ex) {
this.ap.printMessage(Kind.ERROR, ex.getMessage(), elem.getElement(), elem.getAtErrorElement(this.ap.getCompilerEnvironment()));
this.ap.printMessage(MessageType.TARGET_SELECTOR_VALIDATION, ex.getMessage(), elem.getElement(),
elem.getAtErrorElement(this.ap.getCompilerEnvironment()));
}
}
@@ -347,8 +350,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
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);
this.ap.printMessage(MessageType.NO_OBFDATA_FOR_CLASS, "Unable to locate class mapping for " + subject + " '" + target + "'",
elem.getElement(), elem.getAnnotation().asMirror(), SuppressedBy.MAPPING);
return;
}
@@ -377,8 +380,9 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
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(), errorElement);
String missing = targetMember.getOwner() == null ? (targetMember.getDesc() == null ? "owner and descriptor" : "owner") : "descriptor";
this.ap.printMessage(MessageType.INJECTOR_TARGET_NOT_FULLY_QUALIFIED, subject + " is not fully qualified, missing " + missing,
elem.getElement(), errorElement);
return;
}
@@ -387,8 +391,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
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(),
errorElement, SuppressedBy.MAPPING);
this.ap.printMessage(MessageType.NO_OBFDATA_FOR_FIELD, "Unable to locate field mapping for " + subject + " '" + reference
+ "'", elem.getElement(), errorElement, SuppressedBy.MAPPING);
}
return;
}
@@ -397,8 +401,8 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
ObfuscationData<MappingMethod> obfMethodData = this.obf.getDataProvider().getObfMethodRecursive(targetMember);
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(),
errorElement, SuppressedBy.MAPPING);
this.ap.printMessage(MessageType.NO_OBFDATA_FOR_METHOD, "Unable to locate method mapping for " + subject + " '" + reference
+ "'", elem.getElement(), errorElement, SuppressedBy.MAPPING);
}
return;
}
@@ -407,7 +411,7 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
} catch (ReferenceConflictException ex) {
// 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 + " -> "
this.ap.printMessage(MessageType.INJECTOR_MAPPING_CONFLICT, "Unexpected reference conflict for " + subject + ": " + reference + " -> "
+ ex.getNew() + " previously defined as " + ex.getOld(), elem.getElement(), errorElement);
return;
}
@@ -28,10 +28,10 @@ import java.lang.reflect.Method;
import java.util.Locale;
import javax.lang.model.element.ExecutableElement;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.obfuscation.Mappings.MappingConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
@@ -81,21 +81,18 @@ class AnnotatedMixinElementHandlerOverwrite extends AnnotatedMixinElementHandler
}
if (!"true".equalsIgnoreCase(this.ap.getOption(SupportedOptions.DISABLE_OVERWRITE_CHECKER))) {
Kind overwriteErrorKind = "error".equalsIgnoreCase(this.ap.getOption(SupportedOptions.OVERWRITE_ERROR_LEVEL))
? Kind.ERROR : Kind.WARNING;
String javadoc = this.ap.getJavadocProvider().getJavadoc(elem.getElement());
if (javadoc == null) {
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", elem.getElement(), SuppressedBy.OVERWRITE);
this.ap.printMessage(MessageType.OVERWRITE_DOCS, "@Overwrite is missing javadoc comment", elem.getElement(), SuppressedBy.OVERWRITE);
return;
}
if (!javadoc.toLowerCase(Locale.ROOT).contains("@author")) {
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", elem.getElement(), SuppressedBy.OVERWRITE);
this.ap.printMessage(MessageType.OVERWRITE_DOCS, "@Overwrite is missing an @author tag", elem.getElement(), SuppressedBy.OVERWRITE);
}
if (!javadoc.toLowerCase(Locale.ROOT).contains("@reason")) {
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", elem.getElement(), SuppressedBy.OVERWRITE);
this.ap.printMessage(MessageType.OVERWRITE_DOCS, "@Overwrite is missing an @reason tag", elem.getElement(), SuppressedBy.OVERWRITE);
}
}
}
@@ -105,27 +102,27 @@ class AnnotatedMixinElementHandlerOverwrite extends AnnotatedMixinElementHandler
ObfuscationData<MappingMethod> obfData = this.obf.getDataProvider().getObfMethod(targetMethod);
if (obfData.isEmpty()) {
Kind error = Kind.ERROR;
MessageType messageType = MessageType.NO_OBFDATA_FOR_OVERWRITE;
try {
// Try to access isStatic from com.sun.tools.javac.code.Symbol
Method md = elem.getElement().getClass().getMethod("isStatic");
if (((Boolean)md.invoke(elem.getElement())).booleanValue()) {
error = Kind.WARNING;
messageType = MessageType.NO_OBFDATA_FOR_STATIC_OVERWRITE;
}
} catch (Exception ex) {
// well, we tried
}
this.ap.printMessage(error, "No obfuscation mapping for @Overwrite method", elem.getElement());
this.ap.printMessage(messageType, "Unable to locate obfuscation mapping for @Overwrite method", elem.getElement());
return false;
}
try {
this.addMethodMappings(elem.getSimpleName(), elem.getDesc(), obfData);
} catch (MappingConflictException ex) {
elem.printMessage(this.ap, Kind.ERROR, "Mapping conflict for @Overwrite method: " + ex.getNew().getSimpleName() + " for target " + target
+ " conflicts with existing mapping " + ex.getOld().getSimpleName());
elem.printMessage(this.ap, MessageType.OVERWRITE_MAPPING_CONFLICT, "Mapping conflict for @Overwrite method: "
+ ex.getNew().getSimpleName() + " for target " + target + " conflicts with existing mapping " + ex.getOld().getSimpleName());
return false;
}
return true;
@@ -29,13 +29,13 @@ import java.util.Locale;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.obfuscation.mapping.IMapping;
import org.spongepowered.asm.obfuscation.mapping.IMapping.Type;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.obfuscation.Mappings.MappingConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
@@ -168,11 +168,8 @@ class AnnotatedMixinElementHandlerShadow extends AnnotatedMixinElementHandler {
if (obfData.isEmpty()) {
String info = this.mixin.isMultiTarget() ? " in target " + target : "";
if (target.isSimulated()) {
elem.printMessage(this.ap, Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Shadow " + elem);
} else {
elem.printMessage(this.ap, Kind.WARNING, "Unable to locate obfuscation mapping" + info + " for @Shadow " + elem);
}
MessageType messageType = target.isSimulated() ? MessageType.NO_OBFDATA_FOR_SIMULATED_SHADOW : MessageType.NO_OBFDATA_FOR_SHADOW;
elem.printMessage(this.ap, messageType, "Unable to locate obfuscation mapping" + info + " for @Shadow " + elem);
return;
}
@@ -180,8 +177,8 @@ class AnnotatedMixinElementHandlerShadow extends AnnotatedMixinElementHandler {
try {
elem.addMapping(type, obfData.get(type));
} catch (MappingConflictException ex) {
elem.printMessage(this.ap, Kind.ERROR, "Mapping conflict for @Shadow " + elem + ": " + ex.getNew().getSimpleName() + " for target "
+ target + " conflicts with existing mapping " + ex.getOld().getSimpleName());
elem.printMessage(this.ap, MessageType.SHADOW_MAPPING_CONFLICT, "Mapping conflict for @Shadow " + elem + ": "
+ ex.getNew().getSimpleName() + " for target " + target + " conflicts with existing mapping " + ex.getOld().getSimpleName());
}
}
}
@@ -29,11 +29,11 @@ import java.util.List;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.DeclaredType;
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.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.MethodHandle;
@@ -68,7 +68,8 @@ class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinElementHa
// Derp?
if (interfaces.size() < 1) {
this.ap.printMessage(Kind.WARNING, "Empty @Implements annotation", this.mixin.getMixinElement(), implementsAnnotation.asMirror());
this.ap.printMessage(MessageType.SOFT_IMPLEMENTS_EMPTY, "Empty @Implements annotation", this.mixin.getMixinElement(),
implementsAnnotation.asMirror());
return;
}
@@ -83,7 +84,7 @@ class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinElementHa
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.ap.printMessage(MessageType.ERROR, "Unexpected error: " + ex.getClass().getName() + ": " + ex.getMessage(),
this.mixin.getMixinElement(), ((AnnotationHandle)interfaceAnnotation).asMirror());
}
}
@@ -154,7 +155,8 @@ class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinElementHa
ObfuscationData<MappingMethod> obfData = this.obf.getDataProvider().getObfMethod(mapping);
if (obfData.isEmpty()) {
if (remap.forceRemap()) {
this.ap.printMessage(Kind.ERROR, "No obfuscation mapping for soft-implementing method", method.getElement());
this.ap.printMessage(MessageType.NO_OBFDATA_FOR_SOFT_IMPLEMENTS, "No obfuscation mapping for soft-implementing method",
method.getElement());
}
return;
}
@@ -138,30 +138,25 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
* configured via the build script (eg. when using AP with MCP)
*/
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.env = CompilerEnvironment.detect(processingEnv);
this.processingEnv = processingEnv;
this.beVewyVewyQuiet = this.env == CompilerEnvironment.JDT || "true".equalsIgnoreCase(this.getOption(SupportedOptions.QUIET));
MessageType.applyOptions(this.env, this);
MessageRouter.setMessager(processingEnv.getMessager());
String pluginVersion = this.checkPluginVersion(this.getOption(SupportedOptions.PLUGIN_VERSION));
String pluginVersionString = pluginVersion != null ? String.format(" (MixinGradle Version=%s)", pluginVersion) : "";
this.printMessage(Kind.NOTE, "SpongePowered MIXIN Annotation Processor Version=" + MixinBootstrap.VERSION + pluginVersionString);
this.printMessage(MessageType.INFO, "SpongePowered MIXIN Annotation Processor Version=" + MixinBootstrap.VERSION + pluginVersionString);
this.targets = this.initTargetMap();
this.obf = new ObfuscationManager(this);
this.obf.init();
this.validators = ImmutableList.<IMixinValidator>of(
new ParentValidator(this),
new TargetValidator(this)
@@ -246,7 +241,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public CompilerEnvironment getCompilerEnvironment() {
return this.env;
}
@Override
public Integer getToken(String token) {
if (this.tokenCache.containsKey(token)) {
@@ -323,14 +318,6 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
return this.properties;
}
private CompilerEnvironment detectEnvironment(ProcessingEnvironment processingEnv) {
if (processingEnv.getClass().getName().contains("jdt")) {
return CompilerEnvironment.JDT;
}
return CompilerEnvironment.JAVAC;
}
/**
* Write out generated mappings
*/
@@ -407,7 +394,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerAccessor(TypeElement mixinType, ExecutableElement method) {
AnnotatedMixin mixinClass = this.getMixin(mixinType);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found @Accessor annotation on a non-mixin method", method);
this.printMessage(MessageType.ACCESSOR_ON_NON_MIXIN_METHOD, "Found @Accessor annotation on a non-mixin method", method);
return;
}
@@ -424,7 +411,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerInvoker(TypeElement mixinType, ExecutableElement method) {
AnnotatedMixin mixinClass = this.getMixin(mixinType);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found @Accessor annotation on a non-mixin method", method);
this.printMessage(MessageType.ACCESSOR_ON_NON_MIXIN_METHOD, "Found @Invoker annotation on a non-mixin method", method);
return;
}
@@ -441,7 +428,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerOverwrite(TypeElement mixinType, ExecutableElement method) {
AnnotatedMixin mixinClass = this.getMixin(mixinType);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found @Overwrite annotation on a non-mixin method", method);
this.printMessage(MessageType.OVERWRITE_ON_NON_MIXIN_METHOD, "Found @Overwrite annotation on a non-mixin method", method);
return;
}
@@ -459,7 +446,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerShadow(TypeElement mixinType, VariableElement field, AnnotationHandle shadow) {
AnnotatedMixin mixinClass = this.getMixin(mixinType);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found @Shadow annotation on a non-mixin field", field);
this.printMessage(MessageType.SHADOW_ON_NON_MIXIN_ELEMENT, "Found @Shadow annotation on a non-mixin field", field);
return;
}
@@ -476,7 +463,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerShadow(TypeElement mixinType, ExecutableElement method, AnnotationHandle shadow) {
AnnotatedMixin mixinClass = this.getMixin(mixinType);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found @Shadow annotation on a non-mixin method", method);
this.printMessage(MessageType.SHADOW_ON_NON_MIXIN_ELEMENT, "Found @Shadow annotation on a non-mixin method", method);
return;
}
@@ -494,7 +481,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerInjector(TypeElement mixinType, ExecutableElement method, AnnotationHandle inject) {
AnnotatedMixin mixinClass = this.getMixin(mixinType);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found " + inject + " annotation on a non-mixin method", method);
this.printMessage(MessageType.INJECTOR_ON_NON_MIXIN_METHOD, "Found " + inject + " annotation on a non-mixin method", method);
return;
}
@@ -514,7 +501,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
public void registerSoftImplements(TypeElement mixin, AnnotationHandle implementsAnnotation) {
AnnotatedMixin mixinClass = this.getMixin(mixin);
if (mixinClass == null) {
this.printMessage(Kind.ERROR, "Found @Implements annotation on a non-mixin class");
this.printMessage(MessageType.SOFT_IMPLEMENTS_ON_NON_MIXIN, "Found @Implements annotation on a non-mixin class");
return;
}
@@ -556,13 +543,31 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
return AnnotatedMixins.shouldSuppress(element.getEnclosingElement(), suppressedBy);
}
/**
* Print a message to the AP messager
*/
@Override
public void printMessage(MessageType type, CharSequence msg) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg));
}
}
/**
* Print a message to the AP messager
*/
@Override
public void printMessage(Kind kind, CharSequence msg) {
if (!this.beVewyVewyQuiet || kind != Kind.NOTE) {
this.processingEnv.getMessager().printMessage(kind, msg);
this.processingEnv.getMessager().printMessage(kind, msg);
}
/**
* Print a message to the AP messager
*/
@Override
public void printMessage(MessageType type, CharSequence msg, Element element) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg), element);
}
}
@@ -574,6 +579,16 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
this.processingEnv.getMessager().printMessage(kind, msg, element);
}
/**
* Print a message to the AP messager
*/
@Override
public void printMessage(MessageType type, CharSequence msg, Element element, SuppressedBy suppressedBy) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg), element, suppressedBy);
}
}
/**
* Print a message to the AP messager
*/
@@ -584,6 +599,16 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
}
}
/**
* Print a message to the AP messager
*/
@Override
public void printMessage(MessageType type, CharSequence msg, Element element, AnnotationMirror annotation) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg), element, annotation);
}
}
/**
* Print a message to the AP messager
*/
@@ -592,6 +617,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(MessageType type, CharSequence msg, Element element, AnnotationMirror annotation, SuppressedBy suppressedBy) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg), element, annotation, suppressedBy);
}
}
/**
* Print a message to the AP messager
*/
@@ -602,6 +637,16 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
}
}
/**
* Print a message to the AP messager
*/
@Override
public void printMessage(MessageType type, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg), element, annotation, value);
}
}
/**
* Print a message to the AP messager
*/
@@ -610,6 +655,17 @@ 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(MessageType type, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value,
SuppressedBy suppressedBy) {
if (type.isEnabled()) {
this.printMessage(type.getKind(), type.decorate(msg), element, annotation, value, suppressedBy);
}
}
/**
* Print a message to the AP messager
*/
@@ -33,9 +33,9 @@ import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
/**
* Base class for mixin annotation processor modules
@@ -69,7 +69,8 @@ abstract class MixinObfuscationProcessor extends AbstractProcessor {
if (elem.getKind() == ElementKind.CLASS || elem.getKind() == ElementKind.INTERFACE) {
this.mixins.registerMixin((TypeElement)elem);
} else {
this.mixins.printMessage(Kind.ERROR, "Found an @Mixin annotation on an element which is not a class or interface", elem);
this.mixins.printMessage(MessageType.MIXIN_ON_INVALID_TYPE,
"Found an @Mixin annotation on an element which is not a class or interface", elem);
}
}
}
@@ -33,11 +33,11 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
@@ -106,7 +106,7 @@ public class MixinObfuscationProcessorInjection extends MixinObfuscationProcesso
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerInjector((TypeElement)parent, (ExecutableElement)elem, inject);
} else {
this.mixins.printMessage(Kind.WARNING,
this.mixins.printMessage(MessageType.INJECTOR_ON_NON_METHOD_ELEMENT,
"Found an @" + injectorClass.getSimpleName() + " annotation on an element which is not a method: " + elem.toString());
}
}
@@ -33,13 +33,13 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
@@ -99,7 +99,7 @@ public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor
for (Element elem : roundEnv.getElementsAnnotatedWith(Shadow.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
@@ -110,7 +110,7 @@ public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor
} else if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerShadow((TypeElement)parent, (ExecutableElement)elem, shadow);
} else {
this.mixins.printMessage(Kind.ERROR, "Element is not a method or field", elem);
this.mixins.printMessage(MessageType.SHADOW_ON_INVALID_ELEMENT, "Element is not a method or field", elem);
}
}
}
@@ -123,14 +123,14 @@ public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor
for (Element elem : roundEnv.getElementsAnnotatedWith(Overwrite.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerOverwrite((TypeElement)parent, (ExecutableElement)elem);
} else {
this.mixins.printMessage(Kind.ERROR, "Element is not a method", elem);
this.mixins.printMessage(MessageType.OVERWRITE_ON_NON_METHOD_ELEMENT, "Element is not a method", elem);
}
}
}
@@ -143,14 +143,14 @@ public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor
for (Element elem : roundEnv.getElementsAnnotatedWith(Accessor.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerAccessor((TypeElement)parent, (ExecutableElement)elem);
} else {
this.mixins.printMessage(Kind.ERROR, "Element is not a method", elem);
this.mixins.printMessage(MessageType.ACCESSOR_ON_NON_METHOD_ELEMENT, "Element is not a method", elem);
}
}
}
@@ -163,14 +163,14 @@ public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor
for (Element elem : roundEnv.getElementsAnnotatedWith(Invoker.class)) {
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
this.mixins.printMessage(MessageType.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
if (elem.getKind() == ElementKind.METHOD) {
this.mixins.registerInvoker((TypeElement)parent, (ExecutableElement)elem);
} else {
this.mixins.printMessage(Kind.ERROR, "Element is not a method", elem);
this.mixins.printMessage(MessageType.ACCESSOR_ON_NON_METHOD_ELEMENT, "Element is not a method", elem);
}
}
}
@@ -185,7 +185,8 @@ public class MixinObfuscationProcessorTargets extends MixinObfuscationProcessor
AnnotationHandle implementsAnnotation = AnnotationHandle.of(elem, Implements.class);
this.mixins.registerSoftImplements((TypeElement)elem, implementsAnnotation);
} else {
this.mixins.printMessage(Kind.ERROR, "Found an @Implements annotation on an element which is not a class or interface", elem);
this.mixins.printMessage(MessageType.SOFT_IMPLEMENTS_ON_INVALID_TYPE,
"Found an @Implements annotation on an element which is not a class or interface", elem);
}
}
}
@@ -26,13 +26,11 @@ package org.spongepowered.tools.obfuscation;
import java.util.Collection;
import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerSuppressible;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
import org.spongepowered.tools.obfuscation.interfaces.IOptionProvider;
@@ -53,7 +51,7 @@ public abstract class MixinValidator implements IMixinValidator {
/**
* Messager to use to output errors and warnings
*/
protected final Messager messager;
protected final IMessagerSuppressible messager;
/**
* Option provider
@@ -95,37 +93,6 @@ public abstract class MixinValidator implements IMixinValidator {
}
protected abstract boolean validate(TypeElement mixin, AnnotationHandle annotation, Collection<TypeHandle> targets);
/**
* Output a compiler note
*
* @param note Message
* @param element Element to attach the note to
*/
protected final void note(String note, Element element) {
this.messager.printMessage(Kind.NOTE, note, element);
}
/**
* Output a compiler note
*
* @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, String suppressedBy) {
this.messager.printMessage(Kind.WARNING, warning, element);
}
/**
* Output a compiler note
*
* @param error Message
* @param element Element to attach the error to
*/
protected final void error(String error, Element element) {
this.messager.printMessage(Kind.ERROR, error, element);
}
protected final Collection<TypeMirror> getMixinsTargeting(TypeMirror targetType) {
return AnnotatedMixins.getMixinsForEnvironment(this.processingEnv).getMixinsTargeting(targetType);
@@ -47,6 +47,7 @@ import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationEnvironment;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
/**
@@ -153,7 +154,7 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
File inputFile = new File(inputFileName);
try {
if (inputFile.isFile()) {
this.ap.printMessage(Kind.NOTE, "Loading " + this.type + " mappings from " + inputFile.getAbsolutePath());
this.ap.printMessage(MessageType.INFO, "Loading " + this.type + " mappings from " + inputFile.getAbsolutePath());
this.mappingProvider.read(inputFile);
successCount++;
}
@@ -27,10 +27,14 @@ package org.spongepowered.tools.obfuscation;
import java.util.ArrayList;
import java.util.List;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor.CompilerEnvironment;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
import org.spongepowered.tools.obfuscation.service.ObfuscationServices;
@@ -78,12 +82,36 @@ public class ObfuscationManager implements IObfuscationManager {
return;
}
this.initDone = true;
ObfuscationServices.getInstance().initProviders(this.ap);
for (ObfuscationType obfType : ObfuscationType.types()) {
if (obfType.isSupported()) {
this.environments.add(obfType.createEnvironment());
}
}
CompilerEnvironment compilerEnv = this.ap.getCompilerEnvironment();
if (this.environments.size() == 0 && compilerEnv.isDevelopmentEnvironment()) {
MessageType.setPrefix("(Mixin AP) ");
this.ap.printMessage(MessageType.NOTE, "No obfuscation data are available and an IDE (" + compilerEnv.getFriendlyName()
+ ") was detected, quenching error levels ");
MessageType.NO_OBFDATA_FOR_CLASS.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_ACCESSOR.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_CTOR.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_TARGET.quench(Kind.NOTE); // ERROR -> NOTE
MessageType.NO_OBFDATA_FOR_OVERWRITE.quench(Kind.NOTE); // ERROR -> NOTE
MessageType.NO_OBFDATA_FOR_STATIC_OVERWRITE.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_FIELD.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_METHOD.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_SHADOW.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_SIMULATED_SHADOW.quench(Kind.NOTE); // WARNING -> NOTE
MessageType.NO_OBFDATA_FOR_SOFT_IMPLEMENTS.quench(Kind.NOTE); // ERROR -> NOTE
MessageType.PARENT_VALIDATOR.quench(Kind.WARNING); // ERROR -> WARNING
MessageType.TARGET_VALIDATOR.quench(Kind.WARNING); // ERROR -> WARNING
}
}
@Override
@@ -31,7 +31,6 @@ import java.util.List;
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;
@@ -40,6 +39,7 @@ import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
/**
* Implementation of the reference manager
@@ -150,12 +150,12 @@ public class ReferenceManager implements IReferenceManager {
if (fileName.matches("^.*[\\\\/:].*$")) {
File outFile = new File(fileName);
outFile.getParentFile().mkdirs();
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + outFile.getAbsolutePath());
this.ap.printMessage(MessageType.INFO, "Writing " + description + " to " + outFile.getAbsolutePath());
return new PrintWriter(outFile);
}
FileObject outResource = this.ap.getProcessingEnvironment().getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
this.ap.printMessage(Kind.NOTE, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
this.ap.printMessage(MessageType.INFO, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
return new PrintWriter(outResource.openWriter());
}
@@ -26,6 +26,7 @@ package org.spongepowered.tools.obfuscation;
import java.util.Set;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx;
import org.spongepowered.tools.obfuscation.service.ObfuscationServices;
import com.google.common.collect.ImmutableSet;
@@ -48,6 +49,7 @@ public final class SupportedOptions {
public static final String MAPPING_TYPES = "mappingTypes";
public static final String PLUGIN_VERSION = "pluginVersion";
public static final String QUIET = "quiet";
public static final String SHOW_MESSAGE_TYPES = "showMessageTypes";
private SupportedOptions() {}
@@ -67,11 +69,15 @@ public final class SupportedOptions {
SupportedOptions.DEPENDENCY_TARGETS_FILE,
SupportedOptions.MAPPING_TYPES,
SupportedOptions.PLUGIN_VERSION,
SupportedOptions.QUIET
SupportedOptions.QUIET,
SupportedOptions.SHOW_MESSAGE_TYPES
);
options.addAll(
ObfuscationServices.getInstance().getSupportedOptions()
);
options.addAll(
IMessagerEx.MessageType.getSupportedOptions()
);
return options.build();
}
}
@@ -0,0 +1,496 @@
/*
* 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 java.util.HashSet;
import java.util.Locale;
import java.util.Set;
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.Kind;
import org.spongepowered.tools.obfuscation.SupportedOptions;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor.CompilerEnvironment;
/**
* An extended {@link Messager} which supports messages with configurable
* message levels based on the supplied {@link MessageType}.
*/
public interface IMessagerEx extends Messager {
/**
* Message types, centralised so that individual error/warning levels can be
* controlled at runtime.
*/
public static enum MessageType {
/**
* Level for NOTE messages which are informational and can be suppressed
* by quiet
*/
INFO(Kind.NOTE),
/** All other NOTE level messages */
NOTE(Kind.NOTE),
/** Uncategorised (usually unexpected or critical) ERROR messages */
ERROR(Kind.ERROR),
/** Uncategorised (usually unexpected or important) WARNING messages */
WARNING(Kind.WARNING),
/** &#64;Mixin annotation on a non class or interface, eg. package */
MIXIN_ON_INVALID_TYPE(Kind.ERROR),
/** Soft target for mixin not found */
MIXIN_SOFT_TARGET_NOT_FOUND(Kind.ERROR),
/** Soft target for mixin not found, but imaginary type was returned */
MIXIN_SOFT_TARGET_NOT_RESOLVED(Kind.WARNING),
/** Soft target for mixin is public */
MIXIN_SOFT_TARGET_IS_PUBLIC(Kind.WARNING),
/** &#64;Mixin annotation doesn't specify any targets */
MIXIN_NO_TARGETS(Kind.ERROR),
/** Errors raised by the parent validator */
PARENT_VALIDATOR(Kind.ERROR),
/** Errors raised by the target validator */
TARGET_VALIDATOR(Kind.ERROR),
/** Unexpected error attaching accessor/invoker */
ACCESSOR_ATTACH_ERROR(Kind.ERROR),
/** Accessor target could not be found */
ACCESSOR_TARGET_NOT_FOUND(Kind.ERROR),
/** The AP was unable to determine the accessor type for some reason */
ACCESSOR_TYPE_UNSUPPORTED(Kind.WARNING),
/**
* The AP was unable to determine the accessor name either from the
* annotation or using the inflector on the annoated method name
*/
ACCESSOR_NAME_UNRESOLVED(Kind.WARNING),
/** Invoker uses a raw return type when the return type is generic */
INVOKER_RAW_RETURN_TYPE(Kind.WARNING),
/** Generic args of factory invoker incompatible with return type */
FACTORY_INVOKER_GENERIC_ARGS(Kind.ERROR),
/** Return type of factory invoker does not match target type */
FACTORY_INVOKER_RETURN_TYPE(Kind.ERROR),
/** Factory invoker is not declared as static */
FACTORY_INVOKER_NONSTATIC(Kind.ERROR),
/** Constraint violation with supplied tokens */
CONSTRAINT_VIOLATION(Kind.ERROR),
/** Constraint expression is not valid */
INVALID_CONSTRAINT(Kind.WARNING),
/** Mapping conflict encountered on accessor method */
ACCESSOR_MAPPING_CONFLICT(Kind.ERROR),
/** Mapping conflict encountered on injector method */
INJECTOR_MAPPING_CONFLICT(Kind.ERROR),
/** Mapping conflict encountered on overwrite method */
OVERWRITE_MAPPING_CONFLICT(Kind.ERROR),
/** Mapping conflict encountered on shadow method */
SHADOW_MAPPING_CONFLICT(Kind.ERROR),
/** Injector-annotated method encounterd in an interface */
INJECTOR_IN_INTERFACE(Kind.ERROR),
/** Injector annotation encountered on element which is not a method */
INJECTOR_ON_NON_METHOD_ELEMENT(Kind.WARNING),
/** Overwrite annotation encountered on element which is not a method */
OVERWRITE_ON_NON_METHOD_ELEMENT(Kind.ERROR),
/** Accessor annotation encountered on element which is not a method */
ACCESSOR_ON_NON_METHOD_ELEMENT(Kind.ERROR),
/** Shadow annotation encountered on non- field or method element */
SHADOW_ON_INVALID_ELEMENT(Kind.ERROR),
/** Injector annotation encountered on method which isn't in a mixin */
INJECTOR_ON_NON_MIXIN_METHOD(Kind.ERROR),
/** Overwrite annotation encountered on method which isn't in a mixin */
OVERWRITE_ON_NON_MIXIN_METHOD(Kind.ERROR),
/** Accessor annotation encountered on method which isn't in a mixin */
ACCESSOR_ON_NON_MIXIN_METHOD(Kind.ERROR),
/** Shadow annotation encountered on element which isn't in a mixin */
SHADOW_ON_NON_MIXIN_ELEMENT(Kind.ERROR),
/** &#64;Implements annotation on a non- class or interface element */
SOFT_IMPLEMENTS_ON_INVALID_TYPE(Kind.ERROR),
/** &#64;Implements annotation on a non-mixin class or interface */
SOFT_IMPLEMENTS_ON_NON_MIXIN(Kind.ERROR),
/** &#64;Implements annotation has no values */
SOFT_IMPLEMENTS_EMPTY(Kind.WARNING),
/** A target selector failed validation */
TARGET_SELECTOR_VALIDATION(Kind.ERROR),
/** An injection point target is missing owner, descriptor, or both */
INJECTOR_TARGET_NOT_FULLY_QUALIFIED(Kind.ERROR),
/**
* A descriptor is missing on an injector target in a multi-target mixin
*/
MISSING_INJECTOR_DESC_MULTITARGET(Kind.ERROR),
/**
* A descriptor is missing on an injector target in a single-target
* mixin but enclosing type information is unavailable (imaginary) or
* could not be determined from the target class.
*/
MISSING_INJECTOR_DESC_SINGLETARGET(Kind.WARNING),
/**
* A descriptor is missing on an injector target in an &#64;Pseudo mixin
*/
MISSING_INJECTOR_DESC_SIMULATED(Kind.OTHER),
/**
* The target element of an injection could not be located in the target
*/
TARGET_ELEMENT_NOT_FOUND(Kind.WARNING),
/** Mismatched visibility of overwrite with resolved target, warn */
METHOD_VISIBILITY(Kind.WARNING),
/** Obf provider did not return a result for the accessor target */
NO_OBFDATA_FOR_ACCESSOR(Kind.WARNING),
/** Obf provider did not return a result for the specified class */
NO_OBFDATA_FOR_CLASS(Kind.WARNING),
/**
* Obf provider did not return a result for the injector target and the
* target is a normal method
*/
NO_OBFDATA_FOR_TARGET(Kind.ERROR),
/**
* Obf provider did not return a result for the injector target but the
* target is a constructor, warn
*/
NO_OBFDATA_FOR_CTOR(Kind.WARNING),
/**
* Obf provider did not return a result for the specified overwrite and
* the overwrite target is an instance method
*/
NO_OBFDATA_FOR_OVERWRITE(Kind.ERROR),
/**
* Obf provider did not return a result for the specified overwrite but
* the overwrite target is static, warn
*/
NO_OBFDATA_FOR_STATIC_OVERWRITE(Kind.WARNING),
/** Obf provider did not return a result for the specified field */
NO_OBFDATA_FOR_FIELD(Kind.WARNING),
/** Obf provider did not return a result for the specified method */
NO_OBFDATA_FOR_METHOD(Kind.WARNING),
/** Obf provider did not return a result for the shadow target */
NO_OBFDATA_FOR_SHADOW(Kind.WARNING),
/**
* Obf provider did not return a result for the shadow target but the
* enclosing type is simulated, warn
*/
NO_OBFDATA_FOR_SIMULATED_SHADOW(Kind.WARNING),
/**
* Obf provider did not return a result for the specified
* soft-implemented method
*/
NO_OBFDATA_FOR_SOFT_IMPLEMENTS(Kind.ERROR),
/**
* A method in a multi-target mixin has conflicting descriptors so the
* AP is storing the bare reference (name only) in the refmap, which has
* resolvability issues.
*/
BARE_REFERENCE(Kind.WARNING),
/**
* All warnings related to overwrite javadoc contents, can be upgrade to
* error by {@link SupportedOptions#OVERWRITE_ERROR_LEVEL}
*/
OVERWRITE_DOCS(Kind.WARNING);
/**
* Prefix applied to supported commandline options for message levels,
* eg. <tt>INVALID_CONSTRAINT</tt> becomes
* <tt>MSG_INVALID_CONSTRAINT</tt>
*/
private static final String OPTION_PREFIX = "MSG_";
/**
* Development option, enable decoration of messages to make it easier
* to determine message origins.
*/
private static boolean decorate = false;
/**
* Global option, prefix for all annotation processor messages to make
* them easier to differentiate from other messages
*/
private static String prefix = "";
/**
* The original message kind
*/
private final Kind originalKind;
/**
* The current message kind
*/
private Kind kind;
/**
* Whether this message is globally enabled or disabled
*/
private boolean enabled = true;
/**
* Whether this message kind has been specified manually by the user
*/
private boolean setByUser = false;
private MessageType(Kind kind) {
this.originalKind = this.kind = kind;
}
/**
* Get the current message kind
*/
public Kind getKind() {
return this.kind;
}
/**
* Set the current kind
*
* @param kind kind to set
*/
public void setKind(Kind kind) {
this.kind = kind;
this.setByUser = true;
}
/**
* Set the current kind to a lower kind, but only if the level has not
* been set manually by the user. Used when an IDE is detected to
* selectively lower the severity of some messages but we don't want to
* override anything manually specified by the user.
*
* @param kind kind to set
*/
public void quench(Kind kind) {
if (!this.setByUser && kind.ordinal() > this.kind.ordinal()) {
this.kind = kind;
}
}
/**
* Get whether this message type is enabled
*/
public boolean isEnabled() {
return this.enabled;
}
/**
* Set whether this message type is enabled
*
* @param enabled true to enable the message
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
this.setByUser = true;
}
/**
* Reset the message kind to the original value and re-enable the
* message if it was disabled
*/
public void reset() {
this.kind = this.originalKind;
this.enabled = true;
this.setByUser = false;
}
/**
* Called when the message is passed to a real Messager, allows the
* message to be decorated in development and other special situations
* such as inside an IDE
*
* @param msg Message to decorate
* @return Decorated message
*/
public CharSequence decorate(CharSequence msg) {
return MessageType.decorate ? String.format("%s[%s] %s", MessageType.prefix, this.name(), msg) : MessageType.prefix + msg;
}
/**
* Set whether development decoration of messages is enabled
*
* @param enabled true to enable dev decorations
*/
public static void setDecoration(boolean enabled) {
MessageType.decorate = enabled;
}
/**
* Set the prefix for all messages, used to distinguish mixin AP
* messages from other compiler messages in IDE for example
*
* @param prefix Prefix to apply to all messages (include trailing
* space)
*/
public static void setPrefix(String prefix) {
MessageType.prefix = prefix;
}
/**
* Get all the available options for configuring message levels
*/
public static Set<String> getSupportedOptions() {
Set<String> supportedOptions = new HashSet<String>();
for (MessageType type : MessageType.values()) {
supportedOptions.add(MessageType.OPTION_PREFIX + type.name());
}
return supportedOptions;
}
/**
* Apply options supplied to the AP which configure individual message
* levels
*
* @param env Compiler environment
* @param options Options to apply
*/
public static void applyOptions(CompilerEnvironment env, IOptionProvider options) {
// Enable decorations if the option is specified
MessageType.setDecoration("true".equalsIgnoreCase(options.getOption(SupportedOptions.SHOW_MESSAGE_TYPES)));
// Apply the "quiet" option if specified, or if in dev env
MessageType.INFO.setEnabled(!(env.isDevelopmentEnvironment() || "true".equalsIgnoreCase(options.getOption(SupportedOptions.QUIET))));
// Legacy option
if ("error".equalsIgnoreCase(options.getOption(SupportedOptions.OVERWRITE_ERROR_LEVEL))) {
MessageType.OVERWRITE_DOCS.setKind(Kind.ERROR);
}
// Apply all other custom message levels
for (MessageType type : MessageType.values()) {
String option = options.getOption(MessageType.OPTION_PREFIX + type.name());
if (option == null) {
continue;
}
switch (option.toLowerCase(Locale.ROOT)) {
case "note":
type.setKind(Kind.NOTE);
break;
case "warning":
type.setKind(Kind.WARNING);
break;
case "error":
type.setKind(Kind.ERROR);
break;
case "disabled":
type.setEnabled(false);
break;
default:
// Unrecognised level
}
}
}
}
/**
* Prints a message of the specified kind.
*
* @param type the message type
* @param msg the message, or an empty string if none
*/
void printMessage(MessageType type, CharSequence msg);
/**
* Prints a message of the specified kind at the location of the
* element.
*
* @param type the message type
* @param msg the message, or an empty string if none
* @param e the element to use as a position hint
*/
void printMessage(MessageType type, CharSequence msg, Element e);
/**
* Prints a message of the specified kind at the location of the
* annotation mirror of the annotated element.
*
* @param type the message type
* @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
*/
void printMessage(MessageType type, CharSequence msg, Element e, AnnotationMirror a);
/**
* Prints a message of the specified kind at the location of the
* annotation value inside the annotation mirror of the annotated
* element.
*
* @param type the message type
* @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
*/
void printMessage(MessageType type, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v);
}
@@ -36,7 +36,7 @@ import org.spongepowered.tools.obfuscation.SuppressedBy;
* An extended {@link Messager} which supports messages that can be suppressed
* using the standard Java {@link SuppressWarnings} annotation.
*/
public interface IMessagerSuppressible extends Messager {
public interface IMessagerSuppressible extends IMessagerEx {
/**
* Prints a message of the specified kind at the location of the
@@ -50,6 +50,18 @@ public interface IMessagerSuppressible extends Messager {
*/
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, SuppressedBy suppressedBy);
/**
* Prints a message of the specified kind at the location of the
* element.
*
* @param type the message type
* @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(MessageType type, CharSequence msg, Element e, SuppressedBy suppressedBy);
/**
* Prints a message of the specified kind at the location of the
* annotation mirror of the annotated element.
@@ -63,6 +75,19 @@ public interface IMessagerSuppressible extends Messager {
*/
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, SuppressedBy suppressedBy);
/**
* Prints a message of the specified kind at the location of the
* annotation mirror of the annotated element.
*
* @param type the message type
* @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(MessageType type, CharSequence msg, Element e, AnnotationMirror a, SuppressedBy suppressedBy);
/**
* Prints a message of the specified kind at the location of the
* annotation value inside the annotation mirror of the annotated
@@ -76,7 +101,21 @@ public interface IMessagerSuppressible extends Messager {
* @param suppressedBy the {@link SuppressWarnings} value which will silence
* this message
*/
void printMessage(Diagnostic.Kind kind,CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, SuppressedBy suppressedBy);
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, SuppressedBy suppressedBy);
/**
* Prints a message of the specified kind at the location of the
* annotation value inside the annotation mirror of the annotated
* element.
*
* @param type the message type
* @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(MessageType type, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, SuppressedBy suppressedBy);
}
@@ -42,15 +42,112 @@ public interface IMixinAnnotationProcessor extends IMessagerSuppressible, IOptio
/**
* Default environment
*/
JAVAC,
JAVAC(false, "Java Compiler"),
/**
* Eclipse
*/
JDT
JDT(true, "Eclipse (JDT)") {
@Override
protected boolean isDetected(ProcessingEnvironment processingEnv) {
return processingEnv.getClass().getName().contains("jdt");
}
},
/**
* IntelliJ IDEA
*/
IDEA(true, "IntelliJ IDEA") {
@Override
protected boolean isDetected(ProcessingEnvironment processingEnv) {
for (String ideaSystemProperty : new String[] {
"idea.plugins.path",
"idea.config.path",
"idea.home.path",
"idea.paths.selector"
}) {
if (System.getProperty(ideaSystemProperty) != null) {
return true;
}
}
return false;
}
};
/**
* True if this compiler environment is an IDE
*/
private final boolean isDevelopmentEnvironment;
/**
* Display name
*/
private final String friendlyName;
private CompilerEnvironment(boolean isDevelopmentEnvironment, String friendlyName) {
this.isDevelopmentEnvironment = isDevelopmentEnvironment;
this.friendlyName = friendlyName;
}
/**
* True if this compiler environment is not an IDE
*/
public boolean isCompiler() {
return !this.isDevelopmentEnvironment;
}
/**
* True if this compiler environment is an IDE
*/
public boolean isDevelopmentEnvironment() {
return this.isDevelopmentEnvironment;
}
/**
* Get the human-readable name of this environment
*/
public String getFriendlyName() {
return this.friendlyName;
}
/**
* Stub for each compiler environment to implement heuristics to detect
* the presence of the environment
*
* @param processingEnv Current processing environment to detect
* compiler environment from
* @return true if this environment is detected
*/
protected boolean isDetected(ProcessingEnvironment processingEnv) {
return false;
}
/**
* Detect compiler environments which require special handling (for the
* time being, the only special environments we care about are IDEs)
* using heuristic checks such as looking for specific class names or
* system properties.
*
* @param processingEnv Current processing environment to detect
* compiler environment from
* @return detected compiler environment, defaults to {@link #JAVAC} if
* no special environment is detected
*/
public static CompilerEnvironment detect(ProcessingEnvironment processingEnv) {
for (CompilerEnvironment environment : CompilerEnvironment.values()) {
if (environment.isDetected(processingEnv)) {
return environment;
}
}
return CompilerEnvironment.JAVAC;
}
}
/**
* Get the detected compiler environment
*/
@@ -32,8 +32,9 @@ import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import javax.tools.Diagnostic.Kind;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mapping.IMappingWriter;
/**
@@ -62,13 +63,21 @@ public abstract class MappingWriter implements IMappingWriter {
if (fileName.matches("^.*[\\\\/:].*$")) {
File outFile = new File(fileName);
outFile.getParentFile().mkdirs();
this.messager.printMessage(Kind.NOTE, "Writing " + description + " to " + outFile.getAbsolutePath());
this.printMessage(MessageType.INFO, "Writing " + description + " to " + outFile.getAbsolutePath());
return new PrintWriter(outFile);
}
FileObject outResource = this.filer.createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
this.messager.printMessage(Kind.NOTE, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
this.printMessage(MessageType.INFO, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
return new PrintWriter(outResource.openWriter());
}
protected void printMessage(MessageType type, CharSequence msg) {
if (this.messager instanceof IMessagerEx) {
((IMessagerEx)this.messager).printMessage(type, msg);
} else if (type.isEnabled()) {
this.messager.printMessage(type.getKind(), type.decorate(msg));
}
}
}
@@ -26,7 +26,11 @@ package org.spongepowered.tools.obfuscation.service;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
@@ -35,6 +39,10 @@ import javax.tools.Diagnostic.Kind;
import org.spongepowered.tools.obfuscation.ObfuscationType;
import org.spongepowered.tools.obfuscation.SupportedOptions;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import com.google.common.base.Joiner;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
/**
@@ -57,6 +65,11 @@ public final class ObfuscationServices {
*/
private final Set<IObfuscationService> services = new HashSet<IObfuscationService>();
/**
* True if provider init was already completed
*/
private boolean providerInitDone = false;
/**
* Singleton pattern
*/
@@ -80,8 +93,15 @@ public final class ObfuscationServices {
* @param ap annotation processor
*/
public void initProviders(IMixinAnnotationProcessor ap) {
if (this.providerInitDone) {
return;
}
this.providerInitDone = true;
boolean defaultIsPresent = false;
Map<String, Set<String>> supportedTypes = new LinkedHashMap<String, Set<String>>();
try {
for (IObfuscationService service : this.serviceLoader) {
if (!this.services.contains(service)) {
@@ -94,7 +114,11 @@ public final class ObfuscationServices {
for (ObfuscationTypeDescriptor obfType : obfTypes) {
try {
ObfuscationType type = ObfuscationType.create(obfType, ap);
ap.printMessage(Kind.NOTE, serviceName + " supports type: \"" + type + "\"");
Set<String> types = supportedTypes.get(serviceName);
if (types == null) {
supportedTypes.put(serviceName, types = new LinkedHashSet<String>());
}
types.add(type.getKey());
defaultIsPresent |= type.isDefault();
} catch (Exception ex) {
ex.printStackTrace();
@@ -108,6 +132,14 @@ public final class ObfuscationServices {
serviceError.printStackTrace();
}
if (supportedTypes.size() > 0) {
StringBuilder sb = new StringBuilder("Supported obfuscation types:");
for (Entry<String, Set<String>> supportedType : supportedTypes.entrySet()) {
sb.append(' ').append(supportedType.getKey()).append(" supports [").append(Joiner.on(',').join(supportedType.getValue())).append(']');
}
ap.printMessage(MessageType.INFO, sb.toString());
}
if (!defaultIsPresent) {
String defaultEnv = ap.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV);
if (defaultEnv == null) {
@@ -26,9 +26,9 @@ package org.spongepowered.tools.obfuscation.struct;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
/**
@@ -82,13 +82,13 @@ public class InjectorRemap {
* Add an error message on ths injector, the message will be suppressed if
* a child {@link At} is remapped
*
* @param kind message kind
* @param type problem type
* @param msg message
* @param element annotated element
* @param annotation annotation
*/
public void addMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationHandle annotation) {
this.message = new Message(kind, msg, element, annotation);
public void addMessage(MessageType type, CharSequence msg, Element element, AnnotationHandle annotation) {
this.message = new Message(type, msg, element, annotation);
}
/**
@@ -30,6 +30,7 @@ import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
/**
@@ -44,26 +45,50 @@ public class Message {
private final AnnotationMirror annotation;
private final AnnotationValue value;
public Message(MessageType type, CharSequence msg) {
this(type.getKind(), type.decorate(msg), null, (AnnotationMirror)null, null);
}
public Message(Diagnostic.Kind kind, CharSequence msg) {
this(kind, msg, null, (AnnotationMirror)null, null);
}
public Message(MessageType type, CharSequence msg, Element element) {
this(type.getKind(), type.decorate(msg), element, (AnnotationMirror)null, null);
}
public Message(Diagnostic.Kind kind, CharSequence msg, Element element) {
this(kind, msg, element, (AnnotationMirror)null, null);
}
public Message(MessageType type, CharSequence msg, Element element, AnnotationHandle annotation) {
this(type.getKind(), type.decorate(msg), element, annotation.asMirror(), null);
}
public Message(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationHandle annotation) {
this(kind, msg, element, annotation.asMirror(), null);
}
public Message(MessageType type, CharSequence msg, Element element, AnnotationMirror annotation) {
this(type.getKind(), type.decorate(msg), element, annotation, null);
}
public Message(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation) {
this(kind, msg, element, annotation, null);
}
public Message(MessageType type, CharSequence msg, Element element, AnnotationHandle annotation, AnnotationValue value) {
this(type.getKind(), type.decorate(msg), element, annotation.asMirror(), value);
}
public Message(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationHandle annotation, AnnotationValue value) {
this(kind, msg, element, annotation.asMirror(), value);
}
public Message(MessageType type, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) {
this(type.getKind(), type.decorate(msg), element, annotation, value);
}
public Message(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value) {
this.kind = kind;
this.msg = msg;
@@ -31,6 +31,7 @@ import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
@@ -58,7 +59,7 @@ public class ParentValidator extends MixinValidator {
@Override
public boolean validate(TypeElement mixin, AnnotationHandle annotation, Collection<TypeHandle> targets) {
if (mixin.getEnclosingElement().getKind() != ElementKind.PACKAGE && !mixin.getModifiers().contains(Modifier.STATIC)) {
this.error("Inner class mixin must be declared static", mixin);
this.messager.printMessage(MessageType.PARENT_VALIDATOR, "Inner class mixin must be declared static", mixin);
}
return true;
@@ -38,6 +38,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.SupportedOptions;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMessagerEx.MessageType;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
@@ -94,7 +95,8 @@ public class TargetValidator extends MixinValidator {
for (TypeHandle target : targets) {
TypeElement targetType = target.getElement();
if (targetType != null && !(targetType.getKind() == ElementKind.INTERFACE)) {
this.error("Targetted type '" + target + " of " + mixin + " is not an interface", mixin);
this.messager.printMessage(MessageType.TARGET_VALIDATOR, "Targetted type '" + target + " of " + mixin + " is not an interface",
mixin);
}
}
}
@@ -105,7 +107,8 @@ public class TargetValidator extends MixinValidator {
for (TypeHandle target : targets) {
TypeMirror targetType = target.getType();
if (targetType != null && !this.validateSuperClass(targetType, superClass)) {
this.error("Superclass " + superClass + " of " + mixin + " was not found in the hierarchy of target class " + targetType, mixin);
this.messager.printMessage(MessageType.TARGET_VALIDATOR, "Superclass " + superClass + " of " + mixin
+ " was not found in the hierarchy of target class " + targetType, mixin);
}
}
}