Interface FieldUtils

  • All Superinterfaces:
    Utils

    public interface FieldUtils
    extends Utils
    The utilities class for the field in the package "javax.lang.model."
    Since:
    1.0.0
    Author:
    Mercy
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static boolean equalsFieldName​(javax.lang.model.element.VariableElement field, java.lang.CharSequence fieldName)
      Checks if the simple name of the given field matches the specified field name.
      static java.util.List<javax.lang.model.element.VariableElement> filterDeclaredFields​(javax.lang.model.type.TypeMirror type, boolean includeHierarchicalTypes, java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
      Filters and retrieves the declared fields from the given type based on the provided criteria.
      static java.util.List<javax.lang.model.element.VariableElement> findAllDeclaredFields​(javax.lang.model.element.Element element, java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
      Retrieves all declared fields from the given element, including those from hierarchical types, after applying the provided filters.
      static java.util.List<javax.lang.model.element.VariableElement> findAllDeclaredFields​(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
      Retrieves all declared fields from the given type, including those from hierarchical types, after applying the provided filters.
      static java.util.List<javax.lang.model.element.VariableElement> findDeclaredFields​(javax.lang.model.element.Element element, java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
      Retrieves the declared fields from the given element after applying the provided filters.
      static java.util.List<javax.lang.model.element.VariableElement> findDeclaredFields​(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
      Retrieves the declared fields from the given type after applying the provided filters.
      static javax.lang.model.element.VariableElement findField​(javax.lang.model.element.Element element, java.lang.String fieldName)
      Retrieves a field with the specified name from the given element.
      static javax.lang.model.element.VariableElement findField​(javax.lang.model.type.TypeMirror type, java.lang.String fieldName)
      Retrieves the first matching field with the specified name from the given type.
      static java.util.List<javax.lang.model.element.VariableElement> getAllDeclaredFields​(javax.lang.model.element.Element element)
      Retrieves all declared fields from the given element, including those from hierarchical types, without any filtering.
      static java.util.List<javax.lang.model.element.VariableElement> getAllDeclaredFields​(javax.lang.model.type.TypeMirror type)
      Retrieves all declared fields from the given type, including those from hierarchical types, without any filtering.
      static java.util.List<javax.lang.model.element.VariableElement> getAllNonStaticFields​(javax.lang.model.element.Element element)
      Retrieves all non-static fields from the given element, including those from hierarchical types.
      static java.util.List<javax.lang.model.element.VariableElement> getAllNonStaticFields​(javax.lang.model.type.TypeMirror type)
      Retrieves all non-static fields from the given type, including those from hierarchical types.
      static javax.lang.model.element.VariableElement getDeclaredField​(javax.lang.model.element.Element element, java.lang.String fieldName)
      Retrieves the declared field with the specified name from the given element.
      static javax.lang.model.element.VariableElement getDeclaredField​(javax.lang.model.type.TypeMirror type, java.lang.String fieldName)
      Retrieves the declared field with the specified name from the given type.
      static java.util.List<javax.lang.model.element.VariableElement> getDeclaredFields​(javax.lang.model.element.Element element)
      Retrieves all declared fields from the given element without any filtering.
      static java.util.List<javax.lang.model.element.VariableElement> getDeclaredFields​(javax.lang.model.type.TypeMirror type)
      Retrieves all declared fields from the given type without any filtering.
      static java.util.List<javax.lang.model.element.VariableElement> getNonStaticFields​(javax.lang.model.element.Element element)
      Retrieves all declared non-static fields from the given element.
      static java.util.List<javax.lang.model.element.VariableElement> getNonStaticFields​(javax.lang.model.type.TypeMirror type)
      Retrieves all declared non-static fields from the given type.
      static boolean isEnumMemberField​(javax.lang.model.element.VariableElement field)
      is Enum's member field or not
      static boolean isField​(javax.lang.model.element.VariableElement field)
      Checks if the given element is a field or an enum constant.
      static boolean isField​(javax.lang.model.element.VariableElement field, javax.lang.model.element.Modifier... modifiers)
      Checks if the given element is a field or an enum constant, and also has all the specified modifiers.
      static boolean isNonStaticField​(javax.lang.model.element.VariableElement field)
      Checks if the given field is a non-static field.
    • Method Detail

      • getDeclaredField

        static javax.lang.model.element.VariableElement getDeclaredField​(javax.lang.model.element.Element element,
                                                                         java.lang.String fieldName)
        Retrieves the declared field with the specified name from the given element.
        Parameters:
        element - the element to search for the field; if null, null is returned
        fieldName - the name of the field to find
        Returns:
        the VariableElement representing the declared field, or null if not found
      • getDeclaredField

        static javax.lang.model.element.VariableElement getDeclaredField​(javax.lang.model.type.TypeMirror type,
                                                                         java.lang.String fieldName)
        Retrieves the declared field with the specified name from the given type.
        Parameters:
        type - the type to search for the field; if null, null is returned
        fieldName - the name of the field to find
        Returns:
        the VariableElement representing the declared field, or null if not found
      • getDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> getDeclaredFields​(javax.lang.model.element.Element element)
        Retrieves all declared fields from the given element without any filtering.
        Parameters:
        element - the element to retrieve declared fields from
        Returns:
        a list of VariableElement objects representing the declared fields, or an empty list if the element is null or no fields are found
      • getDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> getDeclaredFields​(javax.lang.model.type.TypeMirror type)
        Retrieves all declared fields from the given type without any filtering.
        Parameters:
        type - the type to retrieve declared fields from
        Returns:
        a list of VariableElement objects representing the declared fields, or an empty list if the type is null or no fields are found
        See Also:
        findDeclaredFields(TypeMirror, Predicate[])
      • getAllDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> getAllDeclaredFields​(javax.lang.model.element.Element element)
        Retrieves all declared fields from the given element, including those from hierarchical types, without any filtering.
        Parameters:
        element - the element to retrieve all declared fields from
        Returns:
        a list of VariableElement objects representing all declared fields, or an empty list if the element is null or no fields are found
      • getAllDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> getAllDeclaredFields​(javax.lang.model.type.TypeMirror type)
        Retrieves all declared fields from the given type, including those from hierarchical types, without any filtering.
        Parameters:
        type - the type to retrieve all declared fields from
        Returns:
        a list of VariableElement objects representing all declared fields, or an empty list if the type is null or no fields are found
      • findField

        static javax.lang.model.element.VariableElement findField​(javax.lang.model.element.Element element,
                                                                  java.lang.String fieldName)
        Retrieves a field with the specified name from the given element.
        Parameters:
        element - the element to search for the field; if null, null is returned
        fieldName - the name of the field to find
        Returns:
        the VariableElement representing the field, or null if not found
      • findField

        static javax.lang.model.element.VariableElement findField​(javax.lang.model.type.TypeMirror type,
                                                                  java.lang.String fieldName)
        Retrieves the first matching field with the specified name from the given type.
        Parameters:
        type - the type to search for fields; if null, null is returned
        fieldName - the name of the field to find
        Returns:
        the VariableElement representing the first matching field, or null if not found
      • findDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> findDeclaredFields​(javax.lang.model.element.Element element,
                                                                                           java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
        Retrieves the declared fields from the given element after applying the provided filters.
        Parameters:
        element - the element to retrieve declared fields from; if null, an empty list is returned
        fieldFilters - the predicates used to filter the fields
        Returns:
        a list of VariableElement objects representing the filtered declared fields
      • findDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> findDeclaredFields​(javax.lang.model.type.TypeMirror type,
                                                                                           java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
        Retrieves the declared fields from the given type after applying the provided filters.
        Parameters:
        type - the type to retrieve declared fields from; if null, an empty list is returned
        fieldFilters - the predicates used to filter the fields
        Returns:
        a list of VariableElement objects representing the filtered declared fields
      • findAllDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> findAllDeclaredFields​(javax.lang.model.element.Element element,
                                                                                              java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
        Retrieves all declared fields from the given element, including those from hierarchical types, after applying the provided filters.
        Parameters:
        element - the element to retrieve all declared fields from; if null, an empty list is returned
        fieldFilters - the predicates used to filter the fields
        Returns:
        a list of VariableElement objects representing the filtered declared fields
      • findAllDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> findAllDeclaredFields​(javax.lang.model.type.TypeMirror type,
                                                                                              java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
        Retrieves all declared fields from the given type, including those from hierarchical types, after applying the provided filters.
        Parameters:
        type - the type to retrieve all declared fields from; if null, an empty list is returned
        fieldFilters - the predicates used to filter the fields
        Returns:
        a list of VariableElement objects representing the filtered declared fields
      • filterDeclaredFields

        static java.util.List<javax.lang.model.element.VariableElement> filterDeclaredFields​(javax.lang.model.type.TypeMirror type,
                                                                                             boolean includeHierarchicalTypes,
                                                                                             java.util.function.Predicate<? super javax.lang.model.element.VariableElement>... fieldFilters)
        Filters and retrieves the declared fields from the given type based on the provided criteria.
        Parameters:
        type - the type to retrieve declared fields from; if null, an empty list is returned
        includeHierarchicalTypes - whether to include fields from hierarchical types (e.g., superclasses)
        fieldFilters - the predicates used to filter the fields; optional
        Returns:
        a list of VariableElement objects representing the filtered declared fields
      • isEnumMemberField

        static boolean isEnumMemberField​(javax.lang.model.element.VariableElement field)
        is Enum's member field or not
        Parameters:
        field - VariableElement must be public static final fields
        Returns:
        if field is public static final, return true, or false
      • isNonStaticField

        static boolean isNonStaticField​(javax.lang.model.element.VariableElement field)
        Checks if the given field is a non-static field.
        Parameters:
        field - the VariableElement to check; may be null
        Returns:
        true if the field is a valid field (as per isField(VariableElement)) and does not have the 'static' modifier, false otherwise
      • isField

        static boolean isField​(javax.lang.model.element.VariableElement field)
        Checks if the given element is a field or an enum constant.
        Parameters:
        field - the VariableElement to check; may be null
        Returns:
        true if the element is a field (ElementKind.FIELD) or an enum constant (ElementKind.ENUM_CONSTANT), false otherwise
      • isField

        static boolean isField​(javax.lang.model.element.VariableElement field,
                               javax.lang.model.element.Modifier... modifiers)
        Checks if the given element is a field or an enum constant, and also has all the specified modifiers.
        Parameters:
        field - the VariableElement to check; may be null
        modifiers - the modifiers to match (e.g., Modifier.PUBLIC, Modifier.STATIC)
        Returns:
        true if the element is a field (ElementKind.FIELD) or an enum constant (ElementKind.ENUM_CONSTANT), and it has all of the specified modifiers, false otherwise
      • getNonStaticFields

        static java.util.List<javax.lang.model.element.VariableElement> getNonStaticFields​(javax.lang.model.type.TypeMirror type)
        Retrieves all declared non-static fields from the given type.
        Parameters:
        type - the type to search for non-static fields; if null, an empty list is returned
        Returns:
        a list of VariableElement objects representing the non-static fields, or an empty list if the type is null or no non-static fields are found
      • getNonStaticFields

        static java.util.List<javax.lang.model.element.VariableElement> getNonStaticFields​(javax.lang.model.element.Element element)
        Retrieves all declared non-static fields from the given element.
        Parameters:
        element - the element to search for non-static fields; if null, an empty list is returned
        Returns:
        a list of VariableElement objects representing the non-static fields, or an empty list if the element is null or no non-static fields are found
      • getAllNonStaticFields

        static java.util.List<javax.lang.model.element.VariableElement> getAllNonStaticFields​(javax.lang.model.type.TypeMirror type)
        Retrieves all non-static fields from the given type, including those from hierarchical types.
        Parameters:
        type - the type to search for non-static fields; if null, an empty list is returned
        Returns:
        a list of VariableElement objects representing all non-static fields, or an empty list if the type is null or no non-static fields are found
      • getAllNonStaticFields

        static java.util.List<javax.lang.model.element.VariableElement> getAllNonStaticFields​(javax.lang.model.element.Element element)
        Retrieves all non-static fields from the given element, including those from hierarchical types.
        Parameters:
        element - the element to retrieve all non-static fields from; if null, an empty list is returned
        Returns:
        a list of VariableElement objects representing all non-static fields, or an empty list if the element is null or no non-static fields are found
      • equalsFieldName

        static boolean equalsFieldName​(javax.lang.model.element.VariableElement field,
                                       java.lang.CharSequence fieldName)
        Checks if the simple name of the given field matches the specified field name.
        Parameters:
        field - the VariableElement representing the field; may be null
        fieldName - the CharSequence representing the expected field name; may be null
        Returns:
        true if both the field and fieldName are non-null and their string representations match, false otherwise