Refactor some packages in the AP

This commit is contained in:
Mumfrey committed 2016-11-23 18:00:44 +00:00
1 parent c007eabc31
commit 4bfaf3ce8b
26 files changed
+119 -87

No files matched your search

@@ -49,6 +49,8 @@ import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator.Validation
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
import org.spongepowered.tools.obfuscation.interfaces.ITypeHandleProvider;
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.struct.Message;
/**
@@ -42,11 +42,15 @@ import org.spongepowered.asm.util.ConstraintParser;
import org.spongepowered.asm.util.ConstraintParser.Constraint;
import org.spongepowered.asm.util.throwables.ConstraintViolationException;
import org.spongepowered.asm.util.throwables.InvalidConstraintException;
import org.spongepowered.tools.MirrorUtils;
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.FieldHandle;
import org.spongepowered.tools.obfuscation.mirror.MethodHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Base class for module for {@link AnnotatedMixin} which handle different
@@ -70,7 +74,7 @@ abstract class AnnotatedMixinElementHandler {
public AnnotatedElement(E element, AnnotationHandle annotation) {
this.element = element;
this.annotation = annotation;
this.desc = MirrorUtils.getDescriptor(element);
this.desc = TypeUtils.getDescriptor(element);
}
public E getElement() {
@@ -428,7 +432,7 @@ abstract class AnnotatedMixinElementHandler {
* warnings where appropriate
*/
protected final void validateTargetMethod(ExecutableElement method, AnnotationHandle annotation, AliasedElementName name, String type) {
String signature = MirrorUtils.getJavaSignature(method);
String signature = TypeUtils.getJavaSignature(method);
for (TypeHandle target : this.mixin.getTargets()) {
if (target.isImaginary()) {
@@ -37,9 +37,13 @@ import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.MirrorUtils;
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.FieldHandle;
import org.spongepowered.tools.obfuscation.mirror.MethodHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import com.google.common.base.Strings;
@@ -78,11 +82,11 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
}
public String getTargetTypeName() {
return MirrorUtils.getTypeName(this.getTargetType());
return TypeUtils.getTypeName(this.getTargetType());
}
public String getAccessorDesc() {
return MirrorUtils.getInternalName(this.getTargetType());
return TypeUtils.getInternalName(this.getTargetType());
}
public MemberInfo getContext() {
@@ -118,7 +122,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
@Override
public String getAccessorDesc() {
return MirrorUtils.getDescriptor(this.getElement());
return TypeUtils.getDescriptor(this.getElement());
}
@Override
@@ -128,7 +132,7 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
@Override
public String getTargetTypeName() {
return MirrorUtils.getJavaSignature(this.getElement());
return TypeUtils.getJavaSignature(this.getElement());
}
}
@@ -36,6 +36,8 @@ import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.struct.Message;
/**
@@ -32,6 +32,8 @@ 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.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* A module for {@link AnnotatedMixin} which handles method overwrites
@@ -36,6 +36,8 @@ import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.obfuscation.Mappings.MappingConflictException;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* A module for {@link AnnotatedMixin} which handles shadowed fields and methods
@@ -33,8 +33,11 @@ import javax.tools.Diagnostic.Kind;
import org.spongepowered.asm.mixin.Interface.Remap;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.MirrorUtils;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.MethodHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* A module for {@link AnnotatedMixin} whic handles soft-implements clauses
@@ -110,8 +113,8 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
*/
private void processMethod(Remap remap, TypeHandle iface, String prefix, ExecutableElement method) {
String name = method.getSimpleName().toString();
String sig = MirrorUtils.getJavaSignature(method);
String desc = MirrorUtils.getDescriptor(method);
String sig = TypeUtils.getJavaSignature(method);
String desc = TypeUtils.getDescriptor(method);
if (remap != Remap.ONLY_PREFIXED) {
MethodHandle mixinMethod = this.mixin.getHandle().findMethod(name, sig);
@@ -62,6 +62,9 @@ import org.spongepowered.tools.obfuscation.interfaces.IJavadocProvider;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator.ValidationPass;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeReference;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
import org.spongepowered.tools.obfuscation.interfaces.ITypeHandleProvider;
import org.spongepowered.tools.obfuscation.struct.Message;
@@ -454,18 +457,18 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp
at = ((AnnotationValue)at).getValue();
}
if (at instanceof AnnotationMirror) {
remappedAts += mixinClass.registerInjectionPoint(method, inject, new AnnotationHandle((AnnotationMirror)at));
remappedAts += mixinClass.registerInjectionPoint(method, inject, AnnotationHandle.of((AnnotationMirror)at));
} else {
this.printMessage(Kind.WARNING, "No annotation mirror on " + at.getClass().getName());
}
}
} else if (ats instanceof AnnotationMirror) {
remappedAts += mixinClass.registerInjectionPoint(method, inject, new AnnotationHandle((AnnotationMirror)ats));
remappedAts += mixinClass.registerInjectionPoint(method, inject, AnnotationHandle.of((AnnotationMirror)ats));
} else if (ats instanceof AnnotationValue) {
// Fix for JDT
Object mirror = ((AnnotationValue)ats).getValue();
if (mirror instanceof AnnotationMirror) {
remappedAts += mixinClass.registerInjectionPoint(method, inject, new AnnotationHandle((AnnotationMirror)mirror));
remappedAts += mixinClass.registerInjectionPoint(method, inject, AnnotationHandle.of((AnnotationMirror)mirror));
}
}
}
@@ -41,7 +41,8 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.tools.MirrorUtils;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
/**
* Annotation processor which finds {@link Inject} and {@link At} annotations in
@@ -97,7 +98,7 @@ public class MixinObfuscationProcessorInjection extends MixinObfuscationProcesso
Element parent = elem.getEnclosingElement();
if (!(parent instanceof TypeElement)) {
throw new IllegalStateException("@" + injectorClass.getSimpleName() + " element has unexpected parent with type "
+ MirrorUtils.getElementType(parent));
+ TypeUtils.getElementType(parent));
}
AnnotationHandle inject = AnnotationHandle.of(elem, injectorClass);
@@ -40,7 +40,8 @@ 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.MirrorUtils;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
/**
* Annotation processor which finds {@link Shadow} and {@link Overwrite}
@@ -97,7 +98,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 " + MirrorUtils.getElementType(parent), elem);
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
@@ -121,7 +122,7 @@ 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 " + MirrorUtils.getElementType(parent), elem);
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
@@ -141,7 +142,7 @@ 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 " + MirrorUtils.getElementType(parent), elem);
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
@@ -161,7 +162,7 @@ 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 " + MirrorUtils.getElementType(parent), elem);
this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem);
continue;
}
@@ -36,6 +36,8 @@ import javax.tools.Diagnostic.Kind;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
import org.spongepowered.tools.obfuscation.interfaces.IOptionProvider;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Base class for mixin validators
@@ -34,6 +34,7 @@ import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationDataProvider;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Implementation of obfuscation provider which queries all obfuscation
@@ -45,6 +45,7 @@ import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer;
import org.spongepowered.tools.obfuscation.mapping.IMappingProvider;
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.IMixinAnnotationProcessor;
@@ -40,6 +40,9 @@ import java.util.Set;
import javax.lang.model.element.TypeElement;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeReference;
import com.google.common.io.Files;
/**
@@ -28,8 +28,8 @@ import java.util.Collection;
import javax.lang.model.element.TypeElement;
import org.spongepowered.tools.obfuscation.AnnotationHandle;
import org.spongepowered.tools.obfuscation.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* A mixin validator module, basically just a way of making the various sanity
@@ -29,7 +29,7 @@ import org.spongepowered.asm.obfuscation.mapping.IMapping;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.obfuscation.ObfuscationData;
import org.spongepowered.tools.obfuscation.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Provides obfuscation data to the annotation processor
@@ -24,7 +24,7 @@
*/
package org.spongepowered.tools.obfuscation.interfaces;
import org.spongepowered.tools.obfuscation.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Manager object which cann supply {@link TypeHandle} instances
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
package org.spongepowered.tools.obfuscation.mirror;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
@@ -52,7 +52,7 @@ public class AnnotationHandle {
*
* @param annotation annotation to wrap
*/
AnnotationHandle(AnnotationMirror annotation) {
private AnnotationHandle(AnnotationMirror annotation) {
this.annotation = annotation;
}
@@ -214,6 +214,10 @@ public class AnnotationHandle {
return null;
}
public static AnnotationHandle of(AnnotationMirror annotation) {
return new AnnotationHandle(annotation);
}
public static AnnotationHandle of(Element elem, Class<? extends Annotation> annotationClass) {
return new AnnotationHandle(AnnotationHandle.getAnnotation(elem, annotationClass));
@@ -22,17 +22,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
package org.spongepowered.tools.obfuscation.mirror;
import javax.lang.model.element.VariableElement;
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
import org.spongepowered.tools.MirrorUtils;
/**
* Retrieved from a {@link TypeHandle} when searching for fields
*/
class FieldHandle {
public class FieldHandle {
/**
* Actual element, can be null
@@ -77,7 +76,7 @@ class FieldHandle {
}
public MappingField asMapping() {
return new MappingField(null, this.element.getSimpleName().toString(), MirrorUtils.getInternalName(this.element));
return new MappingField(null, this.element.getSimpleName().toString(), TypeUtils.getInternalName(this.element));
}
}
@@ -22,17 +22,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
package org.spongepowered.tools.obfuscation.mirror;
import javax.lang.model.element.ExecutableElement;
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
import org.spongepowered.tools.MirrorUtils;
/**
* Retrieved from a {@link TypeHandle} when searching for methods
*/
class MethodHandle {
public class MethodHandle {
/**
* Actual element, can be null
@@ -62,7 +61,7 @@ class MethodHandle {
}
public MappingMethod asMapping() {
return new MappingMethod(null, this.element.getSimpleName().toString(), MirrorUtils.getDescriptor(this.element));
return new MappingMethod(null, this.element.getSimpleName().toString(), TypeUtils.getDescriptor(this.element));
}
}
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
package org.spongepowered.tools.obfuscation.mirror;
import java.lang.annotation.Annotation;
import java.util.Collections;
@@ -40,7 +40,6 @@ import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.tools.MirrorUtils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
@@ -92,8 +91,8 @@ public class TypeHandle {
* @param element ze element
*/
public TypeHandle(TypeElement element) {
this.pkg = MirrorUtils.getPackage(element);
this.name = MirrorUtils.getInternalName(element);
this.pkg = TypeUtils.getPackage(element);
this.name = TypeUtils.getInternalName(element);
this.element = element;
}
@@ -238,7 +237,7 @@ public class TypeHandle {
if (desc == null) {
for (ExecutableElement method : this.<ExecutableElement>getEnclosedElements(ElementKind.METHOD)) {
if (method.getSimpleName().toString().equals(memberInfo.name)) {
desc = MirrorUtils.getDescriptor(method);
desc = TypeUtils.getDescriptor(method);
break;
}
}
@@ -265,7 +264,7 @@ public class TypeHandle {
* @return handle to the discovered field if matched or null if no match
*/
public FieldHandle findField(VariableElement element, boolean caseSensitive) {
return this.findField(element.getSimpleName().toString(), MirrorUtils.getTypeName(element.asType()), caseSensitive);
return this.findField(element.getSimpleName().toString(), TypeUtils.getTypeName(element.asType()), caseSensitive);
}
/**
@@ -289,7 +288,7 @@ public class TypeHandle {
* @return handle to the discovered field if matched or null if no match
*/
public FieldHandle findField(String name, String type, boolean caseSensitive) {
String rawType = MirrorUtils.stripGenerics(type);
String rawType = TypeUtils.stripGenerics(type);
for (VariableElement field : this.<VariableElement>getEnclosedElements(ElementKind.FIELD)) {
if (this.compareElement(field, name, type, caseSensitive)) {
@@ -321,7 +320,7 @@ public class TypeHandle {
* @return handle to the discovered method if matched or null if no match
*/
public MethodHandle findMethod(ExecutableElement element, boolean caseSensitive) {
return this.findMethod(element.getSimpleName().toString(), MirrorUtils.getJavaSignature(element), caseSensitive);
return this.findMethod(element.getSimpleName().toString(), TypeUtils.getJavaSignature(element), caseSensitive);
}
/**
@@ -345,7 +344,7 @@ public class TypeHandle {
* @return handle to the discovered method if matched or null if no match
*/
public MethodHandle findMethod(String name, String signature, boolean caseSensitive) {
String rawSignature = MirrorUtils.stripGenerics(signature);
String rawSignature = TypeUtils.stripGenerics(signature);
for (ExecutableElement method : this.<ExecutableElement>getEnclosedElements(ElementKind.CONSTRUCTOR, ElementKind.METHOD)) {
if (this.compareElement(method, name, signature, caseSensitive) || this.compareElement(method, name, rawSignature, caseSensitive)) {
@@ -359,8 +358,8 @@ public class TypeHandle {
private boolean compareElement(Element elem, String name, String type, boolean caseSensitive) {
try {
String elementName = elem.getSimpleName().toString();
String elementType = MirrorUtils.getJavaSignature(elem);
String rawElementType = MirrorUtils.stripGenerics(elementType);
String elementType = TypeUtils.getJavaSignature(elem);
String rawElementType = TypeUtils.stripGenerics(elementType);
boolean compared = caseSensitive ? name.equals(elementName) : name.equalsIgnoreCase(elementName);
return compared && (type.length() == 0 || type.equals(elementType) || type.equals(rawElementType));
} catch (NullPointerException ex) {
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
package org.spongepowered.tools.obfuscation.mirror;
import java.io.Serializable;
@@ -61,7 +61,7 @@ public class TypeReference implements Serializable, Comparable<TypeReference> {
*
* @param name Name of the type
*/
TypeReference(String name) {
public TypeReference(String name) {
this.name = name;
}
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools;
package org.spongepowered.tools.obfuscation.mirror;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
@@ -37,9 +37,9 @@ import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
/**
* Convenience functions for mirror
* Convenience functions for mirror types
*/
public abstract class MirrorUtils {
public abstract class TypeUtils {
/**
* Number of times to recurse into TypeMirrors when trying to determine the
@@ -51,7 +51,7 @@ public abstract class MirrorUtils {
private static final String OBJECT_REF = "java/lang/Object";
// No instances for you
private MirrorUtils() {}
private TypeUtils() {}
public static PackageElement getPackage(TypeElement elem) {
Element parent = elem.getEnclosingElement();
@@ -86,13 +86,13 @@ public abstract class MirrorUtils {
if (extra) {
desc.append(',');
}
desc.append(MirrorUtils.getTypeName(arg.asType()));
desc.append(TypeUtils.getTypeName(arg.asType()));
extra = true;
}
desc.append(')').append(method.getReturnType().toString());
return desc.toString();
}
return MirrorUtils.getTypeName(element.asType());
return TypeUtils.getTypeName(element.asType());
}
public static String stripGenerics(String type) {
@@ -113,55 +113,55 @@ public abstract class MirrorUtils {
public static String getDescriptor(Element elem) {
if (elem instanceof ExecutableElement) {
return MirrorUtils.getDescriptor((ExecutableElement)elem);
return TypeUtils.getDescriptor((ExecutableElement)elem);
} else if (elem instanceof VariableElement) {
return MirrorUtils.getInternalName((VariableElement)elem);
return TypeUtils.getInternalName((VariableElement)elem);
}
return MirrorUtils.getInternalName(elem.asType());
return TypeUtils.getInternalName(elem.asType());
}
public static String getTypeName(TypeMirror type) {
switch (type.getKind()) {
case ARRAY: return MirrorUtils.getTypeName(((ArrayType)type).getComponentType()) + "[]";
case DECLARED: return MirrorUtils.getTypeName((DeclaredType)type);
case TYPEVAR: return MirrorUtils.getTypeName(MirrorUtils.getUpperBound(type));
case ERROR: return MirrorUtils.OBJECT_SIG;
case ARRAY: return TypeUtils.getTypeName(((ArrayType)type).getComponentType()) + "[]";
case DECLARED: return TypeUtils.getTypeName((DeclaredType)type);
case TYPEVAR: return TypeUtils.getTypeName(TypeUtils.getUpperBound(type));
case ERROR: return TypeUtils.OBJECT_SIG;
default: return type.toString();
}
}
public static String getTypeName(DeclaredType type) {
if (type == null) {
return MirrorUtils.OBJECT_SIG;
return TypeUtils.OBJECT_SIG;
}
return MirrorUtils.getTypeName((TypeElement)type.asElement());
return TypeUtils.getTypeName((TypeElement)type.asElement());
}
private static String getTypeName(TypeElement elem) {
return MirrorUtils.getInternalName(elem).replace('/', '.');
return TypeUtils.getInternalName(elem).replace('/', '.');
}
public static String getDescriptor(ExecutableElement method) {
StringBuilder signature = new StringBuilder();
for (VariableElement var : method.getParameters()) {
signature.append(MirrorUtils.getInternalName(var));
signature.append(TypeUtils.getInternalName(var));
}
String returnType = MirrorUtils.getInternalName(method.getReturnType());
String returnType = TypeUtils.getInternalName(method.getReturnType());
return String.format("(%s)%s", signature, returnType);
}
public static String getInternalName(VariableElement var) {
return MirrorUtils.getInternalName(var.asType());
return TypeUtils.getInternalName(var.asType());
}
public static String getInternalName(TypeMirror type) {
switch (type.getKind()) {
case ARRAY: return "[" + MirrorUtils.getInternalName(((ArrayType)type).getComponentType());
case DECLARED: return "L" + MirrorUtils.getInternalName((DeclaredType)type) + ";";
case TYPEVAR: return "L" + MirrorUtils.getInternalName(MirrorUtils.getUpperBound(type)) + ";";
case ARRAY: return "[" + TypeUtils.getInternalName(((ArrayType)type).getComponentType());
case DECLARED: return "L" + TypeUtils.getInternalName((DeclaredType)type) + ";";
case TYPEVAR: return "L" + TypeUtils.getInternalName(TypeUtils.getUpperBound(type)) + ";";
case BOOLEAN: return "Z";
case BYTE: return "B";
case CHAR: return "C";
@@ -172,7 +172,7 @@ public abstract class MirrorUtils {
case SHORT: return "S";
case VOID: return "V";
// TODO figure out a better way to not crash when we get here
case ERROR: return "L" + MirrorUtils.OBJECT_REF + ";";
case ERROR: return "L" + TypeUtils.OBJECT_REF + ";";
default:
}
@@ -181,7 +181,7 @@ public abstract class MirrorUtils {
private static DeclaredType getUpperBound(TypeMirror type) {
try {
return MirrorUtils.getUpperBound0(type, MirrorUtils.MAX_GENERIC_RECURSION_DEPTH);
return TypeUtils.getUpperBound0(type, TypeUtils.MAX_GENERIC_RECURSION_DEPTH);
} catch (IllegalStateException ex) {
throw new IllegalArgumentException("Type symbol \"" + type + "\" is too complex", ex);
} catch (IllegalArgumentException ex) {
@@ -192,7 +192,7 @@ public abstract class MirrorUtils {
private static DeclaredType getUpperBound0(TypeMirror type, int depth) {
if (depth == 0) {
throw new IllegalStateException("Generic symbol \"" + type + "\" is too complex, exceeded "
+ MirrorUtils.MAX_GENERIC_RECURSION_DEPTH + " iterations attempting to determine upper bound");
+ TypeUtils.MAX_GENERIC_RECURSION_DEPTH + " iterations attempting to determine upper bound");
}
if (type instanceof DeclaredType) {
return (DeclaredType)type;
@@ -200,7 +200,7 @@ public abstract class MirrorUtils {
if (type instanceof TypeVariable) {
try {
TypeMirror upper = ((TypeVariable)type).getUpperBound();
return MirrorUtils.getUpperBound0(upper, --depth);
return TypeUtils.getUpperBound0(upper, --depth);
} catch (IllegalStateException ex) {
throw ex;
} catch (IllegalArgumentException ex) {
@@ -214,9 +214,9 @@ public abstract class MirrorUtils {
public static String getInternalName(DeclaredType type) {
if (type == null) {
return MirrorUtils.OBJECT_REF;
return TypeUtils.OBJECT_REF;
}
return MirrorUtils.getInternalName((TypeElement)type.asElement());
return TypeUtils.getInternalName((TypeElement)type.asElement());
}
public static String getInternalName(TypeElement elem) {
@@ -237,8 +237,8 @@ public abstract class MirrorUtils {
public static boolean isAssignable(ProcessingEnvironment processingEnv, TypeMirror targetType, TypeMirror superClass) {
boolean assignable = processingEnv.getTypeUtils().isAssignable(targetType, superClass);
if (!assignable && targetType instanceof DeclaredType && superClass instanceof DeclaredType) {
TypeMirror rawTargetType = MirrorUtils.toRawType(processingEnv, (DeclaredType)targetType);
TypeMirror rawSuperType = MirrorUtils.toRawType(processingEnv, (DeclaredType)superClass);
TypeMirror rawTargetType = TypeUtils.toRawType(processingEnv, (DeclaredType)targetType);
TypeMirror rawSuperType = TypeUtils.toRawType(processingEnv, (DeclaredType)superClass);
return processingEnv.getTypeUtils().isAssignable(rawTargetType, rawSuperType);
}
@@ -30,7 +30,7 @@ import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
import org.spongepowered.tools.obfuscation.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
/**
* Wrapper for Annotation Processor messages, used to enable messages to be
@@ -30,10 +30,10 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import org.spongepowered.tools.obfuscation.AnnotationHandle;
import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.TypeHandle;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Validator which checks that the mixin parent is sane
@@ -35,12 +35,12 @@ import javax.lang.model.type.TypeMirror;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.tools.MirrorUtils;
import org.spongepowered.tools.obfuscation.AnnotationHandle;
import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.SupportedOptions;
import org.spongepowered.tools.obfuscation.TypeHandle;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeUtils;
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
/**
* Validator which checks that the mixin targets are sane
@@ -111,7 +111,7 @@ public class TargetValidator extends MixinValidator {
}
private boolean validateSuperClass(TypeMirror targetType, TypeMirror superClass) {
if (MirrorUtils.isAssignable(this.processingEnv, targetType, superClass)) {
if (TypeUtils.isAssignable(this.processingEnv, targetType, superClass)) {
return true;
}
@@ -123,7 +123,7 @@ public class TargetValidator extends MixinValidator {
return false;
}
if (MirrorUtils.isAssignable(this.processingEnv, targetType, superClass)) {
if (TypeUtils.isAssignable(this.processingEnv, targetType, superClass)) {
return true;
}
@@ -142,7 +142,7 @@ public class TargetValidator extends MixinValidator {
private boolean checkMixinsFor(TypeMirror targetType, TypeMirror superClass) {
for (TypeMirror mixinType : this.getMixinsTargeting(targetType)) {
if (MirrorUtils.isAssignable(this.processingEnv, mixinType, superClass)) {
if (TypeUtils.isAssignable(this.processingEnv, mixinType, superClass)) {
return true;
}
}