Package io.micronaut.inject.ast
Interface ElementQuery<T extends Element>
- Type Parameters:
T
- The element kind
public interface ElementQuery<T extends Element>
An interface for querying the AST for elements.
- Since:
- 2.3.0
- Author:
- graemerocher
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
ElementQuery.Result<T extends Element>
Result interface when building a query. -
Field Summary
Modifier and TypeFieldDescriptionstatic final ElementQuery<MemberElement>
Constant to retrieve all methods and fields.static final ElementQuery<FieldElement>
Constant to retrieve all fields.static final ElementQuery<ClassElement>
Constant to retrieve inner classes.static final ElementQuery<MethodElement>
Constant to retrieve all methods.static final ElementQuery<ConstructorElement>
Constant to retrieve instance constructors, not including those of the parent class. -
Method Summary
Modifier and TypeMethodDescriptionannotated
(@NonNull Predicate<AnnotationMetadata> predicate) Allows filtering elements by annotation.Indicates to exclude any property elements (read write methods and a field).A final filter that allows access to the materialized Element.Indicates to include enum constants, only applicable for fields query.Indicates to include hidden methods/fields, only applicable for methods/fields query.Indicates to include overridden methods, only applicable for methods query.modifiers
(@NonNull Predicate<Set<ElementModifier>> predicate) Allows filtering by modifiers.default @NonNull ElementQuery<T>
Allows filtering elements by name.Allows filtering elements by name.static <T1 extends Element>
@NonNull ElementQuery<T1>Create a newElementQuery
for the given element type.Indicates that only abstract members should be returned.Indicates that only accessible members should be returned.onlyAccessible
(ClassElement fromType) Indicates that only accessible members from the given type should be returned.Indicates that only concrete members should be returned.Indicates that only declared members should be returned and not members from parent classes.Search for methods that are injection points.Indicates to return only instance (non-static methods).Indicates to return only static methods/fields.result()
Build the query result.typed
(@NonNull Predicate<ClassElement> predicate) Allows filtering elements by type.
-
Field Details
-
ALL_INNER_CLASSES
Constant to retrieve inner classes.- Since:
- 3.1.0
-
ALL_FIELDS
Constant to retrieve all fields. -
ALL_METHODS
Constant to retrieve all methods. -
ALL_FIELD_AND_METHODS
Constant to retrieve all methods and fields.- Since:
- 4.0.0
-
CONSTRUCTORS
Constant to retrieve instance constructors, not including those of the parent class.
-
-
Method Details
-
onlyDeclared
Indicates that only declared members should be returned and not members from parent classes.- Returns:
- This query
-
onlyInjected
ElementQuery<T> onlyInjected()Search for methods that are injection points.- Returns:
- This query
-
onlyConcrete
Indicates that only concrete members should be returned.- Returns:
- This query
-
onlyAbstract
Indicates that only abstract members should be returned.- Returns:
- This query
-
onlyAccessible
Indicates that only accessible members should be returned. Inaccessible members include:- package/private members that are in a different package
- private members
- synthetic members or those whose names start with the dollar symbol
- Returns:
- This query
-
onlyAccessible
Indicates that only accessible members from the given type should be returned. Inaccessible members include:- package/private members that are in a different package
- private members
- synthetic members or those whose names start with the dollar symbol
- Parameters:
fromType
- The origin type- Returns:
- This query
-
onlyInstance
ElementQuery<T> onlyInstance()Indicates to return only instance (non-static methods).- Returns:
- The query
-
onlyStatic
ElementQuery<T> onlyStatic()Indicates to return only static methods/fields.- Returns:
- The query
- Since:
- 4.0.0
-
excludePropertyElements
ElementQuery<T> excludePropertyElements()Indicates to exclude any property elements (read write methods and a field).- Returns:
- The query
- Since:
- 4.0.0
-
includeEnumConstants
ElementQuery<T> includeEnumConstants()Indicates to include enum constants, only applicable for fields query.- Returns:
- The query
- Since:
- 3.4.0
-
includeOverriddenMethods
ElementQuery<T> includeOverriddenMethods()Indicates to include overridden methods, only applicable for methods query.- Returns:
- The query
- Since:
- 3.4.0
-
includeHiddenElements
ElementQuery<T> includeHiddenElements()Indicates to include hidden methods/fields, only applicable for methods/fields query.- Returns:
- The query
- Since:
- 3.4.0
-
named
Allows filtering elements by name.- Parameters:
predicate
- The predicate to use. Should return true to include the element.- Returns:
- This query
-
named
Allows filtering elements by name.- Parameters:
name
- The name to filter by- Returns:
- This query
- Since:
- 3.5.2
-
typed
Allows filtering elements by type. ForMethodElement
instances this is based on the return type.- Parameters:
predicate
- The predicate to use. Should return true to include the element.- Returns:
- This query
-
annotated
@NonNull @NonNull ElementQuery<T> annotated(@NonNull @NonNull Predicate<AnnotationMetadata> predicate) Allows filtering elements by annotation.- Parameters:
predicate
- The predicate to use. Should return true to include the element.- Returns:
- This query
-
modifiers
@NonNull @NonNull ElementQuery<T> modifiers(@NonNull @NonNull Predicate<Set<ElementModifier>> predicate) Allows filtering by modifiers.- Parameters:
predicate
- The predicate to use. Should return true to include the element.- Returns:
- This query
-
filter
A final filter that allows access to the materialized Element. This method should be used as a last resort as it is less efficient than the other filtration methods.- Parameters:
predicate
- The predicate to use. Should return true to include the element.- Returns:
- This query
-
result
Build the query result.- Returns:
- The query result.
-
of
@NonNull static <T1 extends Element> @NonNull ElementQuery<T1> of(@NonNull @NonNull Class<T1> elementType) Create a newElementQuery
for the given element type.- Type Parameters:
T1
- The element generic type- Parameters:
elementType
- The element type- Returns:
- The query
-