mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-23 00:49:44 +00:00
Increase checkstyle checks. Javadoc all the things.
This commit is contained in:
1 parent
9fd488cd62
commit
791aba7087
89 files changed
+1518
-305
No files matched your search
+5
@@ -174,6 +174,11 @@ public class AnnotatedMixinElementHandlerAccessor extends AnnotatedMixinElementH
|
||||
throw new UnsupportedOperationException("Target not available at compile time");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new accessor
|
||||
*
|
||||
* @param elem accessor element
|
||||
*/
|
||||
public void registerAccessor(AnnotatedElementAccessor elem) {
|
||||
if (elem.getAccessorType() == null) {
|
||||
elem.printMessage(this.ap, Kind.WARNING, "Unsupported accessor type");
|
||||
|
||||
+2
-1
@@ -55,7 +55,8 @@ public class AnnotatedMixinElementHandlerSoftImplements extends AnnotatedMixinEl
|
||||
* in the mixin are then tested for remapability based on the strategy
|
||||
* defined in the soft-implements decoration
|
||||
*
|
||||
* @param implementsAnnotation
|
||||
* @param implementsAnnotation the @Implements annotation on the
|
||||
* element
|
||||
*/
|
||||
public void process(AnnotationHandle implementsAnnotation) {
|
||||
if (!this.mixin.remap()) {
|
||||
|
||||
@@ -78,7 +78,7 @@ import com.google.common.collect.ImmutableList;
|
||||
* Mixin info manager, stores all of the mixin info during processing and also
|
||||
* manages access to the mappings
|
||||
*/
|
||||
class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITypeHandleProvider, IJavadocProvider {
|
||||
final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITypeHandleProvider, IJavadocProvider {
|
||||
|
||||
private static final String MAPID_SYSTEM_PROPERTY = "mixin.target.mapid";
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ public abstract class MixinObfuscationProcessor extends AbstractProcessor {
|
||||
|
||||
/**
|
||||
* Searches and catalogues all annotated mixin classes
|
||||
*
|
||||
* @param roundEnv round environment
|
||||
*/
|
||||
protected void processMixins(RoundEnvironment roundEnv) {
|
||||
this.mixins.onPassStarted();
|
||||
|
||||
@@ -47,8 +47,15 @@ import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
*/
|
||||
public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
|
||||
/**
|
||||
* Data points stored in this struct, entries are stored by type
|
||||
*/
|
||||
private final Map<ObfuscationType, T> data = new HashMap<ObfuscationType, T>();
|
||||
|
||||
/**
|
||||
* Default obfuscation value to return when an obfuscation entry is
|
||||
* requested but not present in the map
|
||||
*/
|
||||
private final T defaultValue;
|
||||
|
||||
public ObfuscationData() {
|
||||
@@ -59,24 +66,46 @@ public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry to the map
|
||||
*
|
||||
* @param type obfuscation type
|
||||
* @param value new entry
|
||||
*/
|
||||
public void add(ObfuscationType type, T value) {
|
||||
this.data.put(type, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this store contains no entries
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return this.data.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the obfuscation entry for the specified obfuscation type, returns the
|
||||
* default (if present) if no entry is found for the specified type
|
||||
*
|
||||
* @param type obfuscation type
|
||||
* @return obfuscation entry or default value if absent
|
||||
*/
|
||||
public T get(ObfuscationType type) {
|
||||
T value = this.data.get(type);
|
||||
return value != null ? value : this.defaultValue;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<ObfuscationType> iterator() {
|
||||
return this.data.keySet().iterator();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ObfuscationData[%sDEFAULT=%s]", this.listValues(), this.defaultValue);
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class ObfuscationEnvironment implements IObfuscationEnvironment
|
||||
|
||||
if (this.inFileNames == null) {
|
||||
this.ap.printMessage(Kind.ERROR, "The " + this.type.getConfig().getInputFileOption()
|
||||
+ " argument was not supplied, obfuscation processing will not occur");
|
||||
+ " argument was not supplied, obfuscation processing will not occur");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,14 +42,29 @@ import com.google.common.collect.ImmutableList.Builder;
|
||||
*/
|
||||
public final class ObfuscationType {
|
||||
|
||||
/**
|
||||
* Available obfuscation types indexed by key
|
||||
*/
|
||||
private static final Map<String, ObfuscationType> types = new LinkedHashMap<String, ObfuscationType>();
|
||||
|
||||
/**
|
||||
* Key for this type
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* Descriptor contains the majority of the metadata for the obfuscation type
|
||||
*/
|
||||
private final ObfuscationTypeDescriptor descriptor;
|
||||
|
||||
/**
|
||||
* Annotation Processor
|
||||
*/
|
||||
private final IMixinAnnotationProcessor ap;
|
||||
|
||||
/**
|
||||
* Option provider
|
||||
*/
|
||||
private final IOptionProvider options;
|
||||
|
||||
private ObfuscationType(ObfuscationTypeDescriptor descriptor, IMixinAnnotationProcessor ap) {
|
||||
@@ -59,6 +74,9 @@ public final class ObfuscationType {
|
||||
this.options = ap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create obfuscation environment instance for this obfuscation type
|
||||
*/
|
||||
public final ObfuscationEnvironment createEnvironment() {
|
||||
try {
|
||||
Class<? extends ObfuscationEnvironment> cls = this.descriptor.getEnvironmentType();
|
||||
@@ -88,16 +106,25 @@ public final class ObfuscationType {
|
||||
return this.ap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this is ithe default obfuscation environment
|
||||
*/
|
||||
public boolean isDefault() {
|
||||
String defaultEnv = this.options.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV);
|
||||
return (defaultEnv == null && this.key.equals(ObfuscationServiceMCP.SEARGE))
|
||||
|| (defaultEnv != null && this.key.equals(defaultEnv.toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this obfuscation type has data available
|
||||
*/
|
||||
public boolean isSupported() {
|
||||
return this.getInputFileNames().size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the input file names specified for this obfuscation type
|
||||
*/
|
||||
public List<String> getInputFileNames() {
|
||||
Builder<String> builder = ImmutableList.<String>builder();
|
||||
|
||||
@@ -116,24 +143,44 @@ public final class ObfuscationType {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output filenames specified for this obfuscation type
|
||||
*/
|
||||
public String getOutputFileName() {
|
||||
return this.options.getOption(this.descriptor.getOutputFileOption());
|
||||
}
|
||||
|
||||
/**
|
||||
* All available obfuscation types
|
||||
*/
|
||||
public static Iterable<ObfuscationType> types() {
|
||||
return ObfuscationType.types.values();
|
||||
}
|
||||
|
||||
public static ObfuscationType create(ObfuscationTypeDescriptor config, IMixinAnnotationProcessor ap) {
|
||||
String key = config.getKey();
|
||||
/**
|
||||
* Create a new obfuscation type from the supplied descriptor
|
||||
*
|
||||
* @param descriptor obfuscation type metadata
|
||||
* @param ap annotation processor
|
||||
* @return new obfuscation type
|
||||
*/
|
||||
public static ObfuscationType create(ObfuscationTypeDescriptor descriptor, IMixinAnnotationProcessor ap) {
|
||||
String key = descriptor.getKey();
|
||||
if (ObfuscationType.types.containsKey(key)) {
|
||||
throw new IllegalArgumentException("Obfuscation type with key " + key + " was already registered");
|
||||
}
|
||||
ObfuscationType type = new ObfuscationType(config, ap);
|
||||
ObfuscationType type = new ObfuscationType(descriptor, ap);
|
||||
ObfuscationType.types.put(key, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an obfuscation type by key
|
||||
*
|
||||
* @param key obfuscation type key to retrieve
|
||||
* @return obfuscation type or <tt>null</tt> if no matching type is
|
||||
* available
|
||||
*/
|
||||
public static ObfuscationType get(String key) {
|
||||
ObfuscationType type = ObfuscationType.types.get(key);
|
||||
if (type == null) {
|
||||
|
||||
@@ -48,6 +48,9 @@ public final class SupportedOptions {
|
||||
|
||||
private SupportedOptions() {}
|
||||
|
||||
/**
|
||||
* Return all supported options
|
||||
*/
|
||||
public static Set<String> getAllOptions() {
|
||||
Builder<String> options = ImmutableSet.<String>builder();
|
||||
options.add(
|
||||
|
||||
@@ -49,7 +49,7 @@ import com.google.common.io.Files;
|
||||
* Serialisable map of classes to their associated mixins, used so that we can
|
||||
* pass target information for supermixins from one compiler session to another
|
||||
*/
|
||||
public class TargetMap extends HashMap<TypeReference, Set<TypeReference>> {
|
||||
public final class TargetMap extends HashMap<TypeReference, Set<TypeReference>> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TargetMap extends HashMap<TypeReference, Set<TypeReference>> {
|
||||
/**
|
||||
* Create a TargetMap with the specified session ID
|
||||
*
|
||||
* @param sessionId
|
||||
* @param sessionId session id
|
||||
*/
|
||||
private TargetMap(String sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
|
||||
+22
@@ -43,8 +43,10 @@ public interface IObfuscationDataProvider {
|
||||
* owner class.
|
||||
*
|
||||
* @param targetMember Member to search for
|
||||
* @param <T> the type of the obfuscation mapping (MappingMethod for methods
|
||||
* @return ObfuscationData with remapped owner class corresponding to the
|
||||
* original owner class
|
||||
* or String for fields)
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntryRecursive(MemberInfo targetMember);
|
||||
|
||||
@@ -52,7 +54,9 @@ public interface IObfuscationDataProvider {
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
*
|
||||
* @param targetMember member to search for
|
||||
* @param <T> the type of the obfuscation mapping (MappingMethod for methods
|
||||
* @return obfuscation data (by type) for the supplied member
|
||||
* or String for fields)
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(MemberInfo targetMember);
|
||||
|
||||
@@ -60,7 +64,9 @@ public interface IObfuscationDataProvider {
|
||||
* Resolves a field or method reference to an ObfuscationData set
|
||||
*
|
||||
* @param mapping member to search for
|
||||
* @param <T> the type of the obfuscation mapping (MappingMethod for methods
|
||||
* @return obfuscation data (by type) for the supplied member
|
||||
* or String for fields)
|
||||
*/
|
||||
public abstract <T> ObfuscationData<T> getObfEntry(IMapping<T> mapping);
|
||||
|
||||
@@ -78,23 +84,31 @@ public interface IObfuscationDataProvider {
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*
|
||||
* @param method method to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethod(MemberInfo method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method if an explicit mapping exists.
|
||||
* Where no direct mapping exists, remap the descriptor of the method only.
|
||||
*
|
||||
* @param method method to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getRemappedMethod(MemberInfo method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method
|
||||
*
|
||||
* @param method method to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getObfMethod(MappingMethod method);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a method if an explicit mapping exists.
|
||||
* Where no direct mapping exists, remap the descriptor of the method only.
|
||||
*
|
||||
* @param method method to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingMethod> getRemappedMethod(MappingMethod method);
|
||||
|
||||
@@ -112,21 +126,29 @@ public interface IObfuscationDataProvider {
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*
|
||||
* @param field field to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfField(MemberInfo field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*
|
||||
* @param field field to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<MappingField> getObfField(MappingField field);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*
|
||||
* @param type class type to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfClass(TypeHandle type);
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*
|
||||
* @param className class name to fetch obfuscation mapping for
|
||||
*/
|
||||
public abstract ObfuscationData<String> getObfClass(String className);
|
||||
|
||||
|
||||
@@ -54,8 +54,9 @@ public interface IMappingProvider {
|
||||
* Called multiple times by the environment. This method will be called for
|
||||
* each input file specified by the user.
|
||||
*
|
||||
* @param input
|
||||
* @throws IOException
|
||||
* @param input input file to read
|
||||
* @throws IOException if an error occurs reading the input file or the file
|
||||
* does not exist or cannot be opened
|
||||
*/
|
||||
public abstract void read(File input) throws IOException;
|
||||
|
||||
|
||||
@@ -35,12 +35,13 @@ import org.spongepowered.tools.obfuscation.mapping.IMappingConsumer.MappingSet;
|
||||
public interface IMappingWriter {
|
||||
|
||||
/**
|
||||
* Receives
|
||||
* Instruct this writer to write the supplied collection of field and method
|
||||
* mappings to the output resource
|
||||
*
|
||||
* @param output
|
||||
* @param type
|
||||
* @param fields
|
||||
* @param methods
|
||||
* @param output path to output resource
|
||||
* @param type obfuscation type to write
|
||||
* @param fields field mappings
|
||||
* @param methods method mappings
|
||||
*/
|
||||
public abstract void write(String output, ObfuscationType type, MappingSet<MappingField> fields, MappingSet<MappingMethod> methods);
|
||||
|
||||
|
||||
@@ -52,6 +52,11 @@ public abstract class MappingWriter implements IMappingWriter {
|
||||
|
||||
/**
|
||||
* Open a writer for an output file
|
||||
*
|
||||
* @param fileName output file name (resource path)
|
||||
* @param description description of file being requested, for logging
|
||||
* @return new PrintWriter for opened resource
|
||||
* @throws IOException if the resource cannot be opened
|
||||
*/
|
||||
protected PrintWriter openFileWriter(String fileName, String description) throws IOException {
|
||||
if (fileName.matches("^.*[\\\\/:].*$")) {
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableList;
|
||||
* A wrapper for {@link AnnotationMirror} which provides a more convenient way
|
||||
* to access annotation values.
|
||||
*/
|
||||
public class AnnotationHandle {
|
||||
public final class AnnotationHandle {
|
||||
|
||||
/**
|
||||
* Annotation being wrapped
|
||||
@@ -92,6 +92,7 @@ public class AnnotationHandle {
|
||||
* @param key key
|
||||
* @param defaultValue value to return if the key is not set or not present
|
||||
* @return value or default if not set
|
||||
* @param <T> duck type
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T> T getValue(String key, T defaultValue) {
|
||||
@@ -114,6 +115,7 @@ public class AnnotationHandle {
|
||||
/**
|
||||
* Get the annotation value or return null if not present or not set
|
||||
*
|
||||
* @param <T> duck type
|
||||
* @return value or null if not present or not set
|
||||
*/
|
||||
public <T> T getValue() {
|
||||
@@ -125,6 +127,7 @@ public class AnnotationHandle {
|
||||
* present or not set
|
||||
*
|
||||
* @param key key to fetch
|
||||
* @param <T> duck type
|
||||
* @return value or null if not present or not set
|
||||
*/
|
||||
public <T> T getValue(String key) {
|
||||
@@ -146,8 +149,8 @@ public class AnnotationHandle {
|
||||
/**
|
||||
* Get an annotation value as an annotation handle
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
* @param key key to search for in the value map
|
||||
* @return value or <tt>null</tt> if not set
|
||||
*/
|
||||
public AnnotationHandle getAnnotation(String key) {
|
||||
Object value = this.getValue(key);
|
||||
@@ -166,6 +169,7 @@ public class AnnotationHandle {
|
||||
* Retrieve the annotation value as a list with values of the specified
|
||||
* type. Returns an empty list if the value is not present or not set.
|
||||
*
|
||||
* @param <T> list element duck type
|
||||
* @return list of values
|
||||
*/
|
||||
public <T> List<T> getList() {
|
||||
@@ -178,6 +182,7 @@ public class AnnotationHandle {
|
||||
* present or not set.
|
||||
*
|
||||
* @param key key to fetch
|
||||
* @param <T> list element duck type
|
||||
* @return list of values
|
||||
*/
|
||||
public <T> List<T> getList(String key) {
|
||||
@@ -259,10 +264,25 @@ public class AnnotationHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new annotation handle for the supplied annotation mirror
|
||||
*
|
||||
* @param annotation annotation mirror to wrap (can be null)
|
||||
* @return new annotation handle
|
||||
*/
|
||||
public static AnnotationHandle of(AnnotationMirror annotation) {
|
||||
return new AnnotationHandle(annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new annotation handle for the specified annotation on the
|
||||
* supplied element, consumers should call {@link #exists} in order to check
|
||||
* whether the requested annotation is present.
|
||||
*
|
||||
* @param elem element
|
||||
* @param annotationClass annotation class to search for
|
||||
* @return new annotation handle
|
||||
*/
|
||||
public static AnnotationHandle of(Element elem, Class<? extends Annotation> annotationClass) {
|
||||
return new AnnotationHandle(AnnotationHandle.getAnnotation(elem, annotationClass));
|
||||
}
|
||||
|
||||
@@ -57,5 +57,12 @@ public abstract class MemberHandle<T extends IMapping<T>> {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this handle as a mapping
|
||||
*
|
||||
* @param includeOwner include the owner in the generated mapping, false to
|
||||
* only include name and desc
|
||||
* @return this handle as a mapping of appropriate type
|
||||
*/
|
||||
public abstract T asMapping(boolean includeOwner);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class TypeHandle {
|
||||
/**
|
||||
* Ctor for real elements, instanced via a type mirror
|
||||
*
|
||||
* @param type
|
||||
* @param type type
|
||||
*/
|
||||
public TypeHandle(DeclaredType type) {
|
||||
this((TypeElement)type.asElement());
|
||||
@@ -142,6 +142,13 @@ public class TypeHandle {
|
||||
return this.element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an annotation handle for the specified annotation on this type
|
||||
*
|
||||
* @param annotationClass type of annotation to search for
|
||||
* @return new annotation handle, call <tt>exists</tt> on the returned
|
||||
* handle to determine whether the annotation is present
|
||||
*/
|
||||
public AnnotationHandle getAnnotation(Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationHandle.of(this.getTargetElement(), annotationClass);
|
||||
}
|
||||
@@ -157,6 +164,7 @@ public class TypeHandle {
|
||||
* Returns enclosed elements (methods, fields, etc.) of a particular type
|
||||
*
|
||||
* @param kind types of element to return
|
||||
* @param <T> list element type
|
||||
*/
|
||||
public <T extends Element> List<T> getEnclosedElements(ElementKind... kind) {
|
||||
return TypeHandle.getEnclosedElements(this.getTargetElement(), kind);
|
||||
@@ -188,6 +196,9 @@ public class TypeHandle {
|
||||
return new TypeHandle((DeclaredType)superClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interfaces directly implemented by this type
|
||||
*/
|
||||
public List<TypeHandle> getInterfaces() {
|
||||
if (this.getTargetElement() == null) {
|
||||
return Collections.<TypeHandle>emptyList();
|
||||
@@ -222,6 +233,9 @@ public class TypeHandle {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TypeReference for this type, used for serialisation
|
||||
*/
|
||||
public final TypeReference getReference() {
|
||||
if (this.reference == null) {
|
||||
this.reference = new TypeReference(this);
|
||||
@@ -236,12 +250,18 @@ public class TypeHandle {
|
||||
*
|
||||
* @param name Method name
|
||||
* @param desc Method descriptor
|
||||
* @return
|
||||
* @return this handle as a mapping method
|
||||
*/
|
||||
public MappingMethod getMappingMethod(String name, String desc) {
|
||||
return new MappingMethod(this.getName(), name, desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a descriptor for the supplied MemberInfo
|
||||
*
|
||||
* @param memberInfo MemberInfo to use as search term
|
||||
* @return descriptor or null if no matching member could be located
|
||||
*/
|
||||
public String findDescriptor(MemberInfo memberInfo) {
|
||||
String desc = memberInfo.desc;
|
||||
if (desc == null) {
|
||||
@@ -271,6 +291,7 @@ public class TypeHandle {
|
||||
* of the supplied element
|
||||
*
|
||||
* @param element Element to match
|
||||
* @param caseSensitive True if case-sensitive comparison should be used
|
||||
* @return handle to the discovered field if matched or null if no match
|
||||
*/
|
||||
public final FieldHandle findField(VariableElement element, boolean caseSensitive) {
|
||||
@@ -295,6 +316,7 @@ public class TypeHandle {
|
||||
*
|
||||
* @param name Field name to search for
|
||||
* @param type Field descriptor (java-style)
|
||||
* @param caseSensitive True if case-sensitive comparison should be used
|
||||
* @return handle to the discovered field if matched or null if no match
|
||||
*/
|
||||
public FieldHandle findField(String name, String type, boolean caseSensitive) {
|
||||
@@ -327,6 +349,7 @@ public class TypeHandle {
|
||||
* type of the supplied element
|
||||
*
|
||||
* @param element Element to match
|
||||
* @param caseSensitive True if case-sensitive comparison should be used
|
||||
* @return handle to the discovered method if matched or null if no match
|
||||
*/
|
||||
public final MethodHandle findMethod(ExecutableElement element, boolean caseSensitive) {
|
||||
@@ -351,6 +374,7 @@ public class TypeHandle {
|
||||
*
|
||||
* @param name Method name to search for
|
||||
* @param signature Method signature
|
||||
* @param matchCase True if case-sensitive comparison should be used
|
||||
* @return handle to the discovered method if matched or null if no match
|
||||
*/
|
||||
public MethodHandle findMethod(String name, String signature, boolean matchCase) {
|
||||
|
||||
@@ -53,6 +53,13 @@ public abstract class TypeUtils {
|
||||
// No instances for you
|
||||
private TypeUtils() {}
|
||||
|
||||
/**
|
||||
* If the supplied type is a {@link DeclaredType}, return the package in
|
||||
* which it is declared
|
||||
*
|
||||
* @param type type to find package for
|
||||
* @return package for supplied type or null
|
||||
*/
|
||||
public static PackageElement getPackage(TypeMirror type) {
|
||||
if (!(type instanceof DeclaredType)) {
|
||||
return null;
|
||||
@@ -60,6 +67,11 @@ public abstract class TypeUtils {
|
||||
return TypeUtils.getPackage((TypeElement)((DeclaredType)type).asElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the package in which the specified type element is declared
|
||||
* @param type type to find package for
|
||||
* @return package for supplied type or null
|
||||
*/
|
||||
public static PackageElement getPackage(TypeElement type) {
|
||||
Element parent = type.getEnclosingElement();
|
||||
while (parent != null && !(parent instanceof PackageElement)) {
|
||||
@@ -68,22 +80,80 @@ public abstract class TypeUtils {
|
||||
return (PackageElement)parent;
|
||||
}
|
||||
|
||||
public static String getElementType(Element parent) {
|
||||
if (parent instanceof TypeElement) {
|
||||
/**
|
||||
* Convenience method to convert element to string representation for error
|
||||
* messages
|
||||
*
|
||||
* @param element Element to inspect
|
||||
* @return string representation of element name
|
||||
*/
|
||||
public static String getElementType(Element element) {
|
||||
if (element instanceof TypeElement) {
|
||||
return "TypeElement";
|
||||
} else if (parent instanceof ExecutableElement) {
|
||||
} else if (element instanceof ExecutableElement) {
|
||||
return "ExecutableElement";
|
||||
} else if (parent instanceof VariableElement) {
|
||||
} else if (element instanceof VariableElement) {
|
||||
return "VariableElement";
|
||||
} else if (parent instanceof PackageElement) {
|
||||
} else if (element instanceof PackageElement) {
|
||||
return "PackageElement";
|
||||
} else if (parent instanceof TypeParameterElement) {
|
||||
} else if (element instanceof TypeParameterElement) {
|
||||
return "TypeParameterElement";
|
||||
}
|
||||
|
||||
return parent.getClass().getSimpleName();
|
||||
return element.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip generic arguments from the supplied type descriptor
|
||||
*
|
||||
* @param type type descriptor
|
||||
* @return type descriptor with generic args removed
|
||||
*/
|
||||
public static String stripGenerics(String type) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int pos = 0, depth = 0; pos < type.length(); pos++) {
|
||||
char c = type.charAt(pos);
|
||||
if (c == '<') {
|
||||
depth++;
|
||||
}
|
||||
if (depth == 0) {
|
||||
sb.append(c);
|
||||
} else if (c == '>') {
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the specified field
|
||||
*
|
||||
* @param field field element
|
||||
* @return field name
|
||||
*/
|
||||
public static String getName(VariableElement field) {
|
||||
return field != null ? field.getSimpleName().toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the specified method
|
||||
*
|
||||
* @param method method element
|
||||
* @return method name
|
||||
*/
|
||||
public static String getName(ExecutableElement method) {
|
||||
return method != null ? method.getSimpleName().toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a java-style signature for the specified element (return type follows
|
||||
* args) eg:
|
||||
*
|
||||
* <pre>(int,int)boolean</pre>
|
||||
*
|
||||
* @param element element to generate descriptor for
|
||||
* @return descriptor
|
||||
*/
|
||||
public static String getJavaSignature(Element element) {
|
||||
if (element instanceof ExecutableElement) {
|
||||
ExecutableElement method = (ExecutableElement)element;
|
||||
@@ -102,32 +172,12 @@ public abstract class TypeUtils {
|
||||
return TypeUtils.getTypeName(element.asType());
|
||||
}
|
||||
|
||||
public static String stripGenerics(String type) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int pos = 0, depth = 0; pos < type.length(); pos++) {
|
||||
char c = type.charAt(pos);
|
||||
if (c == '<') {
|
||||
depth++;
|
||||
}
|
||||
if (depth == 0) {
|
||||
sb.append(c);
|
||||
} else if (c == '>') {
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getDescriptor(Element elem) {
|
||||
if (elem instanceof ExecutableElement) {
|
||||
return TypeUtils.getDescriptor((ExecutableElement)elem);
|
||||
} else if (elem instanceof VariableElement) {
|
||||
return TypeUtils.getInternalName((VariableElement)elem);
|
||||
}
|
||||
|
||||
return TypeUtils.getInternalName(elem.asType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type name for the specified type
|
||||
*
|
||||
* @param type type mirror
|
||||
* @return type name
|
||||
*/
|
||||
public static String getTypeName(TypeMirror type) {
|
||||
switch (type.getKind()) {
|
||||
case ARRAY: return TypeUtils.getTypeName(((ArrayType)type).getComponentType()) + "[]";
|
||||
@@ -138,25 +188,41 @@ public abstract class TypeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type name for the specified type
|
||||
*
|
||||
* @param type type mirror
|
||||
* @return type name
|
||||
*/
|
||||
public static String getTypeName(DeclaredType type) {
|
||||
if (type == null) {
|
||||
return TypeUtils.OBJECT_SIG;
|
||||
}
|
||||
return TypeUtils.getTypeName((TypeElement)type.asElement());
|
||||
return TypeUtils.getInternalName((TypeElement)type.asElement()).replace('/', '.');
|
||||
}
|
||||
|
||||
private static String getTypeName(TypeElement elem) {
|
||||
return TypeUtils.getInternalName(elem).replace('/', '.');
|
||||
}
|
||||
|
||||
public static String getName(VariableElement field) {
|
||||
return field != null ? field.getSimpleName().toString() : null;
|
||||
}
|
||||
|
||||
public static String getName(ExecutableElement method) {
|
||||
return method != null ? method.getSimpleName().toString() : null;
|
||||
/**
|
||||
* Get a bytecode-style descriptor for the specified element
|
||||
*
|
||||
* @param element element to generate descriptor for
|
||||
* @return descriptor
|
||||
*/
|
||||
public static String getDescriptor(Element element) {
|
||||
if (element instanceof ExecutableElement) {
|
||||
return TypeUtils.getDescriptor((ExecutableElement)element);
|
||||
} else if (element instanceof VariableElement) {
|
||||
return TypeUtils.getInternalName((VariableElement)element);
|
||||
}
|
||||
|
||||
return TypeUtils.getInternalName(element.asType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bytecode-style descriptor for the specified method
|
||||
*
|
||||
* @param method method to generate descriptor for
|
||||
* @return descriptor
|
||||
*/
|
||||
public static String getDescriptor(ExecutableElement method) {
|
||||
if (method == null) {
|
||||
return null;
|
||||
@@ -172,13 +238,25 @@ public abstract class TypeUtils {
|
||||
return String.format("(%s)%s", signature, returnType);
|
||||
}
|
||||
|
||||
public static String getInternalName(VariableElement var) {
|
||||
if (var == null) {
|
||||
/**
|
||||
* Get a bytecode-style descriptor for the specified field
|
||||
*
|
||||
* @param field field to generate descriptor for
|
||||
* @return descriptor
|
||||
*/
|
||||
public static String getInternalName(VariableElement field) {
|
||||
if (field == null) {
|
||||
return null;
|
||||
}
|
||||
return TypeUtils.getInternalName(var.asType());
|
||||
return TypeUtils.getInternalName(field.asType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bytecode-style descriptor for the specified type
|
||||
*
|
||||
* @param type type to generate descriptor for
|
||||
* @return descriptor
|
||||
*/
|
||||
public static String getInternalName(TypeMirror type) {
|
||||
switch (type.getKind()) {
|
||||
case ARRAY: return "[" + TypeUtils.getInternalName(((ArrayType)type).getComponentType());
|
||||
@@ -200,6 +278,43 @@ public abstract class TypeUtils {
|
||||
|
||||
throw new IllegalArgumentException("Unable to parse type symbol " + type + " with " + type.getKind() + " to equivalent bytecode type");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bytecode-style name for the specified type
|
||||
*
|
||||
* @param type type to get name for
|
||||
* @return bytecode-style name
|
||||
*/
|
||||
public static String getInternalName(DeclaredType type) {
|
||||
if (type == null) {
|
||||
return TypeUtils.OBJECT_REF;
|
||||
}
|
||||
return TypeUtils.getInternalName((TypeElement)type.asElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bytecode-style name for the specified type element
|
||||
*
|
||||
* @param element type element to get name for
|
||||
* @return bytecode-style name
|
||||
*/
|
||||
public static String getInternalName(TypeElement element) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder reference = new StringBuilder();
|
||||
reference.append(element.getSimpleName());
|
||||
Element parent = element.getEnclosingElement();
|
||||
while (parent != null) {
|
||||
if (parent instanceof TypeElement) {
|
||||
reference.insert(0, "$").insert(0, parent.getSimpleName());
|
||||
} else if (parent instanceof PackageElement) {
|
||||
reference.insert(0, "/").insert(0, ((PackageElement)parent).getQualifiedName().toString().replace('.', '/'));
|
||||
}
|
||||
parent = parent.getEnclosingElement();
|
||||
}
|
||||
return reference.toString();
|
||||
}
|
||||
|
||||
private static DeclaredType getUpperBound(TypeMirror type) {
|
||||
try {
|
||||
@@ -234,31 +349,14 @@ public abstract class TypeUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getInternalName(DeclaredType type) {
|
||||
if (type == null) {
|
||||
return TypeUtils.OBJECT_REF;
|
||||
}
|
||||
return TypeUtils.getInternalName((TypeElement)type.asElement());
|
||||
}
|
||||
|
||||
public static String getInternalName(TypeElement elem) {
|
||||
if (elem == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder reference = new StringBuilder();
|
||||
reference.append(elem.getSimpleName());
|
||||
Element parent = elem.getEnclosingElement();
|
||||
while (parent != null) {
|
||||
if (parent instanceof TypeElement) {
|
||||
reference.insert(0, "$").insert(0, parent.getSimpleName());
|
||||
} else if (parent instanceof PackageElement) {
|
||||
reference.insert(0, "/").insert(0, ((PackageElement)parent).getQualifiedName().toString().replace('.', '/'));
|
||||
}
|
||||
parent = parent.getEnclosingElement();
|
||||
}
|
||||
return reference.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the target type is assignable to the specified superclass
|
||||
*
|
||||
* @param processingEnv processing environment
|
||||
* @param targetType target type to check
|
||||
* @param superClass superclass type to check
|
||||
* @return true if targetType is assignable to superClass
|
||||
*/
|
||||
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) {
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
/**
|
||||
* Obfuscation service manager
|
||||
*/
|
||||
public class ObfuscationServices {
|
||||
public final class ObfuscationServices {
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
@@ -74,6 +74,8 @@ public class ObfuscationServices {
|
||||
|
||||
/**
|
||||
* Initialise services
|
||||
*
|
||||
* @param ap annotation processor
|
||||
*/
|
||||
public void initProviders(IMixinAnnotationProcessor ap) {
|
||||
try {
|
||||
@@ -102,6 +104,9 @@ public class ObfuscationServices {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the options supported by all available providers
|
||||
*/
|
||||
public Set<String> getSupportedOptions() {
|
||||
Set<String> supportedOptions = new HashSet<String>();
|
||||
for (IObfuscationService provider : this.serviceLoader) {
|
||||
@@ -113,6 +118,12 @@ public class ObfuscationServices {
|
||||
return supportedOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the service instance for the specified class from the service loader
|
||||
*
|
||||
* @param serviceClass service class
|
||||
* @return service instance or null if no matching services were loaded
|
||||
*/
|
||||
public IObfuscationService getService(Class<? extends IObfuscationService> serviceClass) {
|
||||
for (IObfuscationService service : this.serviceLoader) {
|
||||
if (serviceClass.getName().equals(service.getClass().getName())) {
|
||||
|
||||
@@ -28,6 +28,7 @@ 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.mirror.AnnotationHandle;
|
||||
|
||||
/**
|
||||
@@ -61,23 +62,48 @@ public class InjectorRemap {
|
||||
this.remap = remap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether <tt>remap=true</tt> on the injector
|
||||
*/
|
||||
public boolean shouldRemap() {
|
||||
return this.remap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback from the parser to notify this injector that it has been
|
||||
* remapped
|
||||
*/
|
||||
public void notifyRemapped() {
|
||||
this.remappedCount++;
|
||||
this.clearMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error message on ths injector, the message will be suppressed if
|
||||
* a child {@link At} is remapped
|
||||
*
|
||||
* @param kind message kind
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current message (if any)
|
||||
*/
|
||||
public void clearMessage() {
|
||||
this.message = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after processing completes. Dispatches the queued message (if any)
|
||||
* if no child At annotations were remapped.
|
||||
*
|
||||
* @param messager messager to push message into
|
||||
*/
|
||||
public void dispatchPendingMessages(Messager messager) {
|
||||
if (this.remappedCount == 0 && this.message != null) {
|
||||
this.message.sendTo(messager);
|
||||
|
||||
@@ -72,6 +72,12 @@ public class Message {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the supplied message
|
||||
*
|
||||
* @param messager messager to send to
|
||||
* @return fluent interface
|
||||
*/
|
||||
public Message sendTo(Messager messager) {
|
||||
if (this.value != null) {
|
||||
messager.printMessage(this.kind, this.msg, this.element, this.annotation, this.value);
|
||||
@@ -85,40 +91,63 @@ public class Message {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the message kind
|
||||
*/
|
||||
public Diagnostic.Kind getKind() {
|
||||
return this.kind;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the message kind
|
||||
*
|
||||
* @param kind message kind
|
||||
* @return fluent interface
|
||||
*/
|
||||
public Message setKind(Diagnostic.Kind kind) {
|
||||
this.kind = kind;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the message text
|
||||
*
|
||||
* @return fluent interface
|
||||
*/
|
||||
public CharSequence getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the message text
|
||||
*
|
||||
* @param msg message text
|
||||
* @return fluent interface
|
||||
*/
|
||||
public Message setMsg(CharSequence msg) {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the target element
|
||||
*/
|
||||
public Element getElement() {
|
||||
return this.element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the target annotation
|
||||
*/
|
||||
public AnnotationMirror getAnnotation() {
|
||||
return this.annotation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the target annotation value
|
||||
*/
|
||||
public AnnotationValue getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user