public class ASTUtils
extends java.lang.Object
Constructor and Description |
---|
ASTUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
descriptorFromExecutableElement(javax.lang.model.element.ExecutableElement m,
javax.annotation.processing.ProcessingEnvironment env)
Builds a method descriptor from the given
ExecutableElement . |
static java.lang.String |
descriptorFromType(javax.lang.model.type.TypeMirror t,
javax.annotation.processing.ProcessingEnvironment env)
Builds a type descriptor from the given
TypeMirror . |
static <T extends javax.lang.model.element.Element> |
findAnnotatedElement(javax.lang.model.element.Element parent,
java.lang.Class<? extends java.lang.annotation.Annotation> ann)
Finds, among the methods of a class cl, the one annotated with ann, and tries to build
an
Element from it. |
static javax.lang.model.element.Element |
findMember(ClassContainer parent,
java.lang.String name,
java.lang.String descr,
boolean strict,
boolean field,
javax.annotation.processing.ProcessingEnvironment env)
Finds a member given the name, the container class and (if it's a method) the descriptor.
|
static javax.lang.model.element.ExecutableElement |
findOverloadedMethod(javax.lang.model.element.TypeElement context,
javax.lang.model.element.ExecutableElement method,
javax.annotation.processing.ProcessingEnvironment env)
Tries to find the method being overloaded by the given
ExecutableElement . |
static javax.lang.model.element.ExecutableElement |
findSyntheticBridge(javax.lang.model.element.ExecutableElement method,
javax.annotation.processing.ProcessingEnvironment env)
Tries to find the "synthetic bridge" generated by the compiler for a certain overridden
methods.
|
static ftbsc.lll.mapper.data.ClassData |
getClassData(java.lang.String name,
ftbsc.lll.mapper.utils.Mapper mapper)
Gets the
ClassData corresponding to the given internal name,
or creates a false one with the same, non-obfuscated name twice. |
static ftbsc.lll.mapper.data.FieldData |
getFieldData(java.lang.String parent,
java.lang.String name,
ftbsc.lll.mapper.utils.Mapper mapper)
Gets the
FieldData corresponding to the field matching the given
name and parent, or creates a dummy one with fake data if no valid
mapping is found. |
static ftbsc.lll.mapper.data.MethodData |
getMethodData(java.lang.String parent,
java.lang.String name,
java.lang.String descriptor,
ftbsc.lll.mapper.utils.Mapper mapper)
Gets the
MethodData corresponding to the method matching the given
name, parent and descriptor, or creates a dummy one with fake data if no
valid mapping is found. |
static ProxyType |
getProxyType(javax.lang.model.element.VariableElement v)
Utility method for finding out what type of proxy a field is.
|
static <T extends java.lang.annotation.Annotation> |
getTypeFromAnnotation(T ann,
java.util.function.Function<T,java.lang.Class<?>> classFunction,
javax.annotation.processing.ProcessingEnvironment env)
Safely extracts a
Class from an annotation and gets a TypeMirror representing it. |
static java.lang.String |
internalNameFromType(javax.lang.model.type.TypeMirror type,
javax.annotation.processing.ProcessingEnvironment env)
Gets the internal name from a
TypeMirror . |
static int |
mapModifier(javax.lang.model.element.Modifier m)
Maps a
Modifier to its reflective
Modifier equivalent. |
static int |
mapModifiers(java.util.Collection<javax.lang.model.element.Modifier> modifiers)
Takes in a
Collection of AST Modifier s and
returns them mapped to their reflective integer equivalent. |
static boolean |
shouldValidate(java.lang.String name)
Checks whether a certain class name is valid, and whether the processor is able to validate
its existence.
|
public static <T extends javax.lang.model.element.Element> java.util.List<T> findAnnotatedElement(javax.lang.model.element.Element parent, java.lang.Class<? extends java.lang.annotation.Annotation> ann)
Element
from it.T
- the type of Element
to useparent
- the parent Element
to the desired elementann
- the Class
corresponding to the desired annotationList
of Element
s annotated with the given annotationpublic static int mapModifier(javax.lang.model.element.Modifier m)
Modifier
to its reflective
Modifier
equivalent.m
- the Modifier
to mapModifier
public static int mapModifiers(java.util.Collection<javax.lang.model.element.Modifier> modifiers)
Collection
of AST Modifier
s and
returns them mapped to their reflective integer equivalent.modifiers
- the Modifier
spublic static <T extends java.lang.annotation.Annotation> javax.lang.model.type.TypeMirror getTypeFromAnnotation(T ann, java.util.function.Function<T,java.lang.Class<?>> classFunction, javax.annotation.processing.ProcessingEnvironment env)
Class
from an annotation and gets a TypeMirror
representing it.T
- the type of the annotation carrying the informationann
- the annotation containing the classclassFunction
- the annotation function returning the classenv
- the ProcessingEnvironment
to perform the operation inTypeMirror
representing the requested Class
public static java.lang.String internalNameFromType(javax.lang.model.type.TypeMirror type, javax.annotation.processing.ProcessingEnvironment env)
TypeMirror
.type
- the TypeMirror
in questionenv
- the ProcessingEnvironment
to perform the operation inpublic static java.lang.String descriptorFromType(javax.lang.model.type.TypeMirror t, javax.annotation.processing.ProcessingEnvironment env)
TypeMirror
.t
- the TypeMirror
representing the desired typeenv
- the ProcessingEnvironment
to perform the operation inString
containing the relevant descriptorpublic static java.lang.String descriptorFromExecutableElement(javax.lang.model.element.ExecutableElement m, javax.annotation.processing.ProcessingEnvironment env)
ExecutableElement
.m
- the ExecutableElement
for the methodenv
- the ProcessingEnvironment
to perform the operation inString
containing the relevant descriptorpublic static ftbsc.lll.mapper.data.ClassData getClassData(java.lang.String name, ftbsc.lll.mapper.utils.Mapper mapper)
ClassData
corresponding to the given internal name,
or creates a false one with the same, non-obfuscated name twice.name
- the internal name of the class to convertmapper
- the Mapper
to use, may be nullpublic static ftbsc.lll.mapper.data.MethodData getMethodData(java.lang.String parent, java.lang.String name, java.lang.String descriptor, ftbsc.lll.mapper.utils.Mapper mapper)
MethodData
corresponding to the method matching the given
name, parent and descriptor, or creates a dummy one with fake data if no
valid mapping is found.parent
- the internal name of the parent classname
- the name of the memberdescriptor
- the descriptor of the methodmapper
- the Mapper
to use, may be nullpublic static ftbsc.lll.mapper.data.FieldData getFieldData(java.lang.String parent, java.lang.String name, ftbsc.lll.mapper.utils.Mapper mapper)
FieldData
corresponding to the field matching the given
name and parent, or creates a dummy one with fake data if no valid
mapping is found.parent
- the internal name of the parent classname
- the name of the membermapper
- the Mapper
to use, may be nullpublic static javax.lang.model.element.Element findMember(ClassContainer parent, java.lang.String name, java.lang.String descr, boolean strict, boolean field, javax.annotation.processing.ProcessingEnvironment env)
parent
- the ClassContainer
representing the parentname
- the name to search fordescr
- the descriptor to search for, or null if it's not a methodstrict
- whether to perform lookup in strict mode (see Target.strict()
for more information)field
- whether the member being searched is a fieldenv
- the ProcessingEnvironment
to perform the operation inAmbiguousDefinitionException
- if it finds more than one candidateTargetNotFoundException
- if it finds no valid candidatepublic static javax.lang.model.element.ExecutableElement findOverloadedMethod(javax.lang.model.element.TypeElement context, javax.lang.model.element.ExecutableElement method, javax.annotation.processing.ProcessingEnvironment env)
ExecutableElement
.
In case of multiple layers of overloading, it finds the original one. In case of
no overloading, it returns the given method.context
- the TypeElement
representing the parent classmethod
- an ExecutableElement
representing the overloading methodenv
- the ProcessingEnvironment
to perform the operation inpublic static javax.lang.model.element.ExecutableElement findSyntheticBridge(javax.lang.model.element.ExecutableElement method, javax.annotation.processing.ProcessingEnvironment env) throws TargetNotFoundException
method
- an ExecutableElement
the (potentially) bridged methodenv
- the ProcessingEnvironment
to perform the operation inTargetNotFoundException
- if the method in question was not overriding anything, or
if the method it was overriding does not require a bridgepublic static ProxyType getProxyType(javax.lang.model.element.VariableElement v)
v
- the annotated VariableElement
ProxyType
for the elementNotAProxyException
- if it's neitherpublic static boolean shouldValidate(java.lang.String name) throws InvalidClassNameException
name
- the name to validateInvalidClassNameException
- if an invalid name was provided