public class InternalUtils extends Object
Modifier and Type | Method and Description |
---|---|
static AnnotationMirror |
annotationFromAnnotationTree(AnnotationTree tree) |
static List<? extends AnnotationMirror> |
annotationsFromArrayCreation(NewArrayTree node,
int level) |
static List<? extends AnnotationMirror> |
annotationsFromTree(AnnotatedTypeTree node) |
static List<? extends AnnotationMirror> |
annotationsFromTree(TypeParameterTree node) |
static List<AnnotationMirror> |
annotationsFromTypeAnnotationTrees(List<? extends AnnotationTree> annos) |
static int |
compareDiagnosticPosition(Tree tree1,
Tree tree2)
Compares tree1 to tree2 by the position at which a diagnostic (e.g., an error message) for
the tree should be printed.
|
static ExecutableElement |
constructor(NewClassTree tree)
Determines the symbol for a constructor given an invocation via
new . |
static com.sun.tools.javac.code.Symbol |
findFunction(Tree tree,
ProcessingEnvironment env)
The type of the lambda or method reference tree is a functional interface type.
|
static WildcardType |
getCapturedWildcard(TypeVariable typeVar)
If typeVar is a captured wildcard, returns that wildcard; otherwise returns null.
|
static ClassLoader |
getClassLoaderForClass(Class<? extends Object> clazz)
Obtain the class loader for
clazz . |
static com.sun.tools.javac.util.Context |
getJavacContext(ProcessingEnvironment env)
Helper function to extract the javac Context from the javac processing environment.
|
static TypeElement |
getTypeElement(TypeMirror type)
Returns the type element for
type if type is a class, interface, annotation
type, or enum. |
static TypeMirror |
greatestLowerBound(ProcessingEnvironment processingEnv,
TypeMirror tm1,
TypeMirror tm2)
Returns the greatest lower bound of two
TypeMirror s, ignoring any annotations on the
types. |
static boolean |
isAnonymousConstructor(MethodTree method)
Determines whether or not the node referred to by the given
TreePath is an anonymous
constructor (the constructor for an anonymous class. |
static boolean |
isCaptured(TypeVariable typeVar)
Returns whether a TypeVariable represents a captured type.
|
static boolean |
isClassType(TypeMirror type)
Returns whether a TypeMirror represents a class type.
|
static boolean |
isFunctionalInterface(TypeMirror type,
ProcessingEnvironment env)
Returns whether or not
type is a functional interface type (as defined in JLS 9.8). |
static TypeMirror |
leastUpperBound(ProcessingEnvironment processingEnv,
TypeMirror tm1,
TypeMirror tm2)
Returns the least upper bound of two
TypeMirror s, ignoring any annotations on the
types. |
static TypeMirror |
substituteMethodReturnType(ProcessingEnvironment env,
Element methodElement,
TypeMirror substitutedReceiverType)
Returns the return type of a method, given the receiver of the method call.
|
static @Nullable Element |
symbol(Tree tree)
Gets the
Element ("symbol") for the given Tree API node. |
static TypeMirror |
typeOf(Tree tree) |
public static @Nullable Element symbol(Tree tree)
Element
("symbol") for the given Tree API node.tree
- the Tree
node to get the symbol forSymbol
for the given tree, or null if one could not be foundIllegalArgumentException
- if tree
is null or is not a valid javac-internal
tree (JCTree)public static boolean isAnonymousConstructor(MethodTree method)
TreePath
is an anonymous
constructor (the constructor for an anonymous class.method
- the TreePath
for a node that may be an anonymous constructorpublic static ExecutableElement constructor(NewClassTree tree)
new
.
If the tree is a declaration of an anonymous class, then method returns constructor that gets invoked in the extended class, rather than the anonymous constructor implicitly added by the constructor (JLS 15.9.5.1)
tree
- the constructor invocationExecutableElement
corresponding to the constructor call in tree
public static final List<AnnotationMirror> annotationsFromTypeAnnotationTrees(List<? extends AnnotationTree> annos)
public static AnnotationMirror annotationFromAnnotationTree(AnnotationTree tree)
public static final List<? extends AnnotationMirror> annotationsFromTree(AnnotatedTypeTree node)
public static final List<? extends AnnotationMirror> annotationsFromTree(TypeParameterTree node)
public static final List<? extends AnnotationMirror> annotationsFromArrayCreation(NewArrayTree node, int level)
public static TypeMirror typeOf(Tree tree)
public static boolean isCaptured(TypeVariable typeVar)
public static WildcardType getCapturedWildcard(TypeVariable typeVar)
public static boolean isClassType(TypeMirror type)
public static TypeMirror leastUpperBound(ProcessingEnvironment processingEnv, TypeMirror tm1, TypeMirror tm2)
TypeMirror
s, ignoring any annotations on the
types.
Wrapper around Types.lub to add special handling for null types, primitives, and wildcards.
processingEnv
- the ProcessingEnvironment
to usetm1
- a TypeMirror
tm2
- a TypeMirror
tm1
and tm2
.public static TypeMirror greatestLowerBound(ProcessingEnvironment processingEnv, TypeMirror tm1, TypeMirror tm2)
TypeMirror
s, ignoring any annotations on the
types.
Wrapper around Types.glb to add special handling for null types, primitives, and wildcards.
processingEnv
- the ProcessingEnvironment
to usetm1
- a TypeMirror
tm2
- a TypeMirror
tm1
and tm2
.public static TypeMirror substituteMethodReturnType(ProcessingEnvironment env, Element methodElement, TypeMirror substitutedReceiverType)
public static com.sun.tools.javac.util.Context getJavacContext(ProcessingEnvironment env)
env
- the processing environmentpublic static TypeElement getTypeElement(TypeMirror type)
type
if type
is a class, interface, annotation
type, or enum. Otherwise, returns null.type
- whose element is returnedtype
if type
is a class, interface, annotation
type, or enum; otherwise, returns nullpublic static ClassLoader getClassLoaderForClass(Class<? extends Object> clazz)
clazz
. If that is not available, return the system class
loader.clazz
- the class whose class loader to findclazz
, or the system class loader, or null if both
are unavailablepublic static int compareDiagnosticPosition(Tree tree1, Tree tree2)
public static boolean isFunctionalInterface(TypeMirror type, ProcessingEnvironment env)
type
is a functional interface type (as defined in JLS 9.8).type
- possible functional interface typeenv
- ProcessingEnvironmenttype
is a functional interface type (as defined in JLS 9.8)public static com.sun.tools.javac.code.Symbol findFunction(Tree tree, ProcessingEnvironment env)
tree
- lambda or member reference treeenv
- ProcessingEnvironment