Interface ElementUtils
-
-
Method Summary
Static Methods Modifier and Type Method Description static <E extends javax.lang.model.element.Element>
java.util.List<E>filterElements(java.util.List<E> elements, java.util.function.Predicate<? super E>... elementPredicates)
Filters the provided list ofElement
objects based on the given array ofPredicate
conditions.static boolean
hasModifiers(javax.lang.model.element.Element member, javax.lang.model.element.Modifier... modifiers)
Checks whether the specifiedElement
has all of the specifiedModifier
s.static boolean
isClass(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of class: eitherCLASS
orENUM
orRECORD
.static boolean
isDeclaredType(javax.lang.model.element.ElementKind kind)
{@return {@code true} if this is a kind of declared type, a {@linkplain ElementKind#isClass() class} or an {@linkplain ElementKind#isInterface() interface}, and {@code false} otherwise}static boolean
isExecutable(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of executable: eitherMETHOD
orCONSTRUCTOR
orSTATIC_INIT
orINSTANCE_INIT
.static boolean
isField(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of field: eitherFIELD
orENUM_CONSTANT
.static boolean
isInitializer(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of initializer: eitherSTATIC_INIT
orINSTANCE_INIT
.static boolean
isInterface(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of interface: eitherINTERFACE
orANNOTATION_TYPE
.static boolean
isMember(javax.lang.model.element.ElementKind kind)
{@return {@code true} if this is a kind of {@linkplain ElementKind#isField() field} or {@linkplain ElementKind#isExecutable() executable}, and {@code false} otherwise}static boolean
isPublicNonStatic(javax.lang.model.element.Element member)
Checks whether the specifiedElement
is public and non-static.static boolean
isVariable(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of variable: includingENUM_CONSTANT
,FIELD
,PARAMETER
,LOCAL_VARIABLE
,EXCEPTION_PARAMETER
,RESOURCE_VARIABLE
, andBINDING_VARIABLE
.static boolean
matchesElementKind(javax.lang.model.element.Element member, javax.lang.model.element.ElementKind kind)
Checks whether the specifiedElement
has the specifiedElementKind
.static boolean
matchesElementType(javax.lang.model.element.ElementKind elementKind, java.lang.annotation.ElementType elementType)
Checks whether the specifiedElementKind
matches the specifiedElementType
.static boolean
matchesElementType(javax.lang.model.element.ElementKind elementKind, java.lang.annotation.ElementType... elementTypes)
Checks whether the specifiedElementKind
matches any of the specifiedElementType
s.static boolean
matchesElementType(javax.lang.model.element.Element element, java.lang.annotation.ElementType... elementTypes)
Checks whether the specifiedElement
matches the specifiedElementType
.static boolean
matchParameterTypeNames(java.util.List<? extends javax.lang.model.element.VariableElement> parameters, java.lang.CharSequence... parameterTypeNames)
Checks whether the parameter types of the given list ofVariableElement
parameters match the specified type names.static boolean
matchParameterTypes(java.util.List<? extends javax.lang.model.element.VariableElement> parameters, java.lang.reflect.Type... parameterTypes)
Checks whether the parameter types of the given list ofVariableElement
parameters match the specifiedtypes
.static boolean
matchParameterTypes(javax.lang.model.element.ExecutableElement executableElement, java.lang.reflect.Type... parameterTypes)
Checks whether the parameter types of the givenExecutableElement
match the specifiedtypes
.static javax.lang.model.element.ElementKind
toElementKind(java.lang.annotation.ElementType elementType)
Converts the specifiedElementType
to an equivalentElementKind
.
-
-
-
Method Detail
-
isClass
static boolean isClass(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of class: eitherCLASS
orENUM
orRECORD
.- Returns:
true
if this is a kind of class- See Also:
ElementKind.isClass()
-
isInterface
static boolean isInterface(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of interface: eitherINTERFACE
orANNOTATION_TYPE
.- Parameters:
kind
-ElementKind
- Returns:
true
if this is a kind of interface
-
isDeclaredType
static boolean isDeclaredType(javax.lang.model.element.ElementKind kind)
{@return {@code true} if this is a kind of declared type, a {@linkplain ElementKind#isClass() class} or an {@linkplain ElementKind#isInterface() interface}, and {@code false} otherwise}- Parameters:
kind
-ElementKind
- See Also:
ElementKind#isDeclaredType()
-
isField
static boolean isField(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of field: eitherFIELD
orENUM_CONSTANT
.- Parameters:
kind
-ElementKind
- Returns:
true
if this is a kind of field- See Also:
ElementKind.isField()
-
isExecutable
static boolean isExecutable(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of executable: eitherMETHOD
orCONSTRUCTOR
orSTATIC_INIT
orINSTANCE_INIT
.- Parameters:
kind
-ElementKind
- Returns:
true
if this is a kind of executable- See Also:
ElementKind#isExecutable()
-
isMember
static boolean isMember(javax.lang.model.element.ElementKind kind)
{@return {@code true} if this is a kind of {@linkplain ElementKind#isField() field} or {@linkplain ElementKind#isExecutable() executable}, and {@code false} otherwise}- Parameters:
kind
-ElementKind
kind
-- Returns:
- See Also:
ElementKind#isDeclaredType()
-
isInitializer
static boolean isInitializer(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of initializer: eitherSTATIC_INIT
orINSTANCE_INIT
.- Parameters:
kind
-ElementKind
- Returns:
true
if this is a kind of initializer- See Also:
ElementKind#isInitializer()
-
isVariable
static boolean isVariable(javax.lang.model.element.ElementKind kind)
Returnstrue
if this is a kind of variable: includingENUM_CONSTANT
,FIELD
,PARAMETER
,LOCAL_VARIABLE
,EXCEPTION_PARAMETER
,RESOURCE_VARIABLE
, andBINDING_VARIABLE
.- Parameters:
kind
-ElementKind
- Returns:
true
if this is a kind of variable- See Also:
ElementKind#isVariable()
-
toElementKind
static javax.lang.model.element.ElementKind toElementKind(java.lang.annotation.ElementType elementType)
Converts the specifiedElementType
to an equivalentElementKind
.If the provided
elementType
isnull
, this method returnsElementKind.OTHER
.- Parameters:
elementType
- the ElementType to convert, may benull
- Returns:
- the corresponding ElementKind, never
null
-
matchesElementType
static boolean matchesElementType(javax.lang.model.element.ElementKind elementKind, java.lang.annotation.ElementType elementType)
Checks whether the specifiedElementKind
matches the specifiedElementType
.- Parameters:
elementKind
- the ElementKind to checkelementType
- the ElementType to check- Returns:
true
if the ElementKind matches the ElementType,false
otherwise
-
matchesElementType
static boolean matchesElementType(javax.lang.model.element.ElementKind elementKind, java.lang.annotation.ElementType... elementTypes)
Checks whether the specifiedElementKind
matches any of the specifiedElementType
s.- Parameters:
elementKind
- the ElementKind to checkelementTypes
- the ElementTypes to check- Returns:
true
if the ElementKind matches any of the ElementTypes,false
otherwise
-
matchesElementType
static boolean matchesElementType(javax.lang.model.element.Element element, java.lang.annotation.ElementType... elementTypes)
Checks whether the specifiedElement
matches the specifiedElementType
.- Parameters:
element
- theElement
to checkelementTypes
- the ElementTypes to check- Returns:
true
if the Element matches the ElementType,false
otherwise
-
matchesElementKind
static boolean matchesElementKind(javax.lang.model.element.Element member, javax.lang.model.element.ElementKind kind)
Checks whether the specifiedElement
has the specifiedElementKind
.- Parameters:
member
- theElement
to check, may benull
kind
- theElementKind
to match, may benull
- Returns:
true
if the element is not null and its kind matches the specified kind; otherwise,false
-
isPublicNonStatic
static boolean isPublicNonStatic(javax.lang.model.element.Element member)
Checks whether the specifiedElement
is public and non-static.- Parameters:
member
- theElement
to check, may benull
- Returns:
true
if the element is public and not static; otherwise,false
-
hasModifiers
static boolean hasModifiers(javax.lang.model.element.Element member, javax.lang.model.element.Modifier... modifiers)
Checks whether the specifiedElement
has all of the specifiedModifier
s.- Parameters:
member
- theElement
to check, may benull
modifiers
- the array ofModifier
s to match, may benull
- Returns:
true
if the element is not null and contains all specified modifiers; otherwise,false
-
filterElements
static <E extends javax.lang.model.element.Element> java.util.List<E> filterElements(java.util.List<E> elements, java.util.function.Predicate<? super E>... elementPredicates)
Filters the provided list ofElement
objects based on the given array ofPredicate
conditions.If the input list of elements is empty or the array of predicates is null, an empty list is returned.
- Type Parameters:
E
- The type of the elements, which must be a subclass ofElement
- Parameters:
elements
- The list of elements to be filtered, may benull
elementPredicates
- An array of predicates used to filter the elements, may benull
- Returns:
- A filtered list of elements that match all the provided predicates. Returns an empty list if no elements match, or if the input list or predicate array is invalid.
-
matchParameterTypes
static boolean matchParameterTypes(javax.lang.model.element.ExecutableElement executableElement, java.lang.reflect.Type... parameterTypes)
Checks whether the parameter types of the givenExecutableElement
match the specifiedtypes
.If either the executable element or the parameter types array is
null
, this method returnsfalse
. Otherwise, it compares the fully qualified type names of the parameters.- Parameters:
executableElement
- the executable element whose parameters are to be checked, may benull
parameterTypes
- the expected parameter types, may benull
- Returns:
true
if the parameter types match;false
otherwise
-
matchParameterTypes
static boolean matchParameterTypes(java.util.List<? extends javax.lang.model.element.VariableElement> parameters, java.lang.reflect.Type... parameterTypes)
Checks whether the parameter types of the given list ofVariableElement
parameters match the specifiedtypes
.If either the parameters list or the parameter types array is
null
, this method returnsfalse
. Otherwise, it compares the fully qualified type names of the parameters.- Parameters:
parameters
- the list of variable elements representing the parameters, may benull
parameterTypes
- the expected parameter types, may benull
- Returns:
true
if the parameter types match;false
otherwise
-
matchParameterTypeNames
static boolean matchParameterTypeNames(java.util.List<? extends javax.lang.model.element.VariableElement> parameters, java.lang.CharSequence... parameterTypeNames)
Checks whether the parameter types of the given list ofVariableElement
parameters match the specified type names.If either the parameters list or the parameter type names array is
null
, this method returnsfalse
. It also returnsfalse
if the sizes of the two arrays do not match. Otherwise, it compares each parameter's type with the corresponding type name usingTypeUtils.isSameType(Element, CharSequence)
.- Parameters:
parameters
- the list of variable elements representing the parameters, may benull
parameterTypeNames
- the expected fully qualified type names of the parameters, may benull
- Returns:
true
if all parameter types match their corresponding type names;false
otherwise
-
-