Top Description Inners Constructors Methods
com.google.auto.common

public final Class MoreElements

extends Object
Class Inheritance
Annotations
@Beta
Static Imports
com.google.auto.common.MoreStreams.toImmutableSet, javax.lang.model.element.ElementKind.PACKAGE, .Modifier.STATIC

Static utility methods pertaining to Element instances.
Author
Gregory Kick

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
private static class
private static class
private static class
private static class
private static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ExecutableElement
asExecutable(Element element)

Returns the given Element instance as ExecutableElement.

public static PackageElement
asPackage(Element element)

Returns the given Element instance as PackageElement.

public static TypeElement
asType(Element element)

Returns the given Element instance as TypeElement.

public static TypeParameterElement
asTypeParameter(Element element)

Returns the given Element instance as TypeParameterElement.

public static VariableElement
asVariable(Element element)

Returns the given Element instance as VariableElement.

public static ImmutableSet<ExecutableElement>
getAllMethods(TypeElement
the type whose own and inherited methods are to be returned
type
,
Types
a Types object, typically returned by processingEnv.getTypeUtils()
typeUtils
,
Elements
an Elements object, typically returned by processingEnv.getElementUtils()
elementUtils
)

Returns the set of all methods from type, including methods that it inherits from its ancestors.

private static ImmutableSet<ExecutableElement>
private static void
public static Optional<AnnotationMirror>
getAnnotationMirror(Element element, Class<? extends Annotation> annotationClass)

Returns an AnnotationMirror for the annotation of type annotationClass on element, or Optional#absent() if no such annotation exists.

public static Optional<AnnotationMirror>
getAnnotationMirror(Element element, TypeElement annotation)

Returns an AnnotationMirror for the annotation of type annotation on element, or Optional#absent() if no such annotation exists.

public static Optional<AnnotationMirror>
getAnnotationMirror(Element element, String annotationName)

Returns an AnnotationMirror for the annotation whose type's canonical name is on element, or Optional#absent() if no such annotation exists.

public static ImmutableSet<ExecutableElement>
getLocalAndInheritedMethods(TypeElement
the type whose own and inherited methods are to be returned
type
,
Elements
an Elements object, typically returned by processingEnv.getElementUtils()
elementUtils
)

Deprecated The method getLocalAndInheritedMethods(TypeElement, Types, Elements) has better consistency between Java compilers.
Returns the set of all non-private, non-static methods from type, including methods that it inherits from its ancestors.
public static ImmutableSet<ExecutableElement>
getLocalAndInheritedMethods(TypeElement
the type whose own and inherited methods are to be returned
type
,
Types
a Types object, typically returned by processingEnv.getTypeUtils()
typeUtils
,
Elements
an Elements object, typically returned by processingEnv.getElementUtils()
elementUtils
)

Returns the set of all non-private, non-static methods from type, including methods that it inherits from its ancestors.

private static ImmutableSet<ExecutableElement>
public static PackageElement
getPackage(Element element)

An alternate implementation of Elements#getPackageOf that does not require an Elements instance.

public static <T extends Element> Predicate<T>
hasModifiers(Modifier... modifiers)

Returns a Predicate that can be used to filter elements by Modifier.

public static <T extends Element> Predicate<T>
hasModifiers(final Set<Modifier> modifiers)

Returns a Predicate that can be used to filter elements by Modifier.

public static boolean
isAnnotationPresent(Element element, Class<? extends Annotation> annotationClass)

Returns true iff the given element has an AnnotationMirror whose annotation type has the same canonical name as that of annotationClass.

public static boolean
isAnnotationPresent(Element element, TypeElement annotation)

Returns true iff the given element has an AnnotationMirror whose annotation type has the same fully qualified name as that of annotation.

public static boolean
isAnnotationPresent(Element element, String annotationName)

Returns true iff the given element has an AnnotationMirror whose annotation type has annotationName as its canonical name.

public static boolean
isType(Element element)

Returns true if the given Element instance is a TypeElement.

pack-priv static boolean
public static boolean

Returns:

true if and only if the first method overrides the second
overrides
(ExecutableElement
the first method, possible overrider
overrider
,
ExecutableElement
the second method, possibly being overridden
overridden
,
TypeElement
the type of which the first method is a member
type
,
Types typeUtils)

Tests whether one method, as a member of a given type, overrides another method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait