Interface MethodUtils

  • All Superinterfaces:
    Utils

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

      Static Methods 
      Modifier and Type Method Description
      static java.util.List<javax.lang.model.element.ExecutableElement> filterDeclaredMethods​(javax.lang.model.type.TypeMirror type, boolean includeHierarchicalTypes, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
      Filters the declared methods of the specified type based on the given predicates.
      static java.util.List<javax.lang.model.element.ExecutableElement> filterMethods​(java.util.List<javax.lang.model.element.ExecutableElement> methods, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
      Filters the given list of executable elements (methods) based on the provided predicates.
      static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.element.TypeElement type, java.lang.reflect.Type... excludedTypes)
      Find all declared methods of the specified type element, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.
      static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.element.TypeElement type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
      Find all declared methods of the specified TypeElement, including those inherited from superclasses and interfaces, and optionally filter them using the provided predicates.
      static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.type.TypeMirror type, java.lang.reflect.Type... excludedTypes)
      Find all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.
      static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
      Finds all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and optionally filters them using the provided predicates.
      static java.util.List<javax.lang.model.element.ExecutableElement> findDeclaredMethods​(javax.lang.model.element.TypeElement type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
      Find the declared methods of the specified TypeElement.
      static java.util.List<javax.lang.model.element.ExecutableElement> findDeclaredMethods​(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
      Find the declared methods of the specified type mirror.
      static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.element.TypeElement type, java.lang.String methodName)
      Finds a method with the specified name in the given type element, using an empty parameter type array as default.
      static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.element.TypeElement type, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
      Finds a method with the specified name and parameter type names in the given TypeElement.
      static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.element.TypeElement type, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
      Finds a method with the specified name and parameter types in the given TypeElement.
      static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.type.TypeMirror type, java.lang.String methodName)
      Finds a method with the specified name in the given type mirror, using an empty parameter type array as default.
      static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.type.TypeMirror type, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
      Finds a method with the specified name and parameter type names in the given type mirror.
      static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.type.TypeMirror type, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
      Finds a method with the specified name and parameter types in the given type mirror.
      static java.util.List<javax.lang.model.element.ExecutableElement> findPublicNonStaticMethods​(javax.lang.model.element.TypeElement type, java.lang.reflect.Type... excludedTypes)
      Finds all public non-static methods declared in the specified TypeElement, excluding those inherited from superclasses or interfaces, and optionally excludes methods declared in the specified excluded types.
      static java.util.List<javax.lang.model.element.ExecutableElement> findPublicNonStaticMethods​(javax.lang.model.type.TypeMirror type, java.lang.reflect.Type... excludedTypes)
      Find all public non-static methods declared in the specified type mirror, excluding those inherited from superclasses or interfaces, and optionally exclude methods declared in the specified excluded types.
      static java.util.List<javax.lang.model.element.ExecutableElement> getAllDeclaredMethods​(javax.lang.model.element.TypeElement type)
      Get all declared methods of the specified type element, including those inherited from superclasses and interfaces.
      static java.util.List<javax.lang.model.element.ExecutableElement> getAllDeclaredMethods​(javax.lang.model.type.TypeMirror type)
      Get all declared methods of the specified type mirror, including those inherited from superclasses and interfaces.
      static java.util.List<javax.lang.model.element.ExecutableElement> getDeclaredMethods​(javax.lang.model.element.TypeElement type)
      Gets all declared methods of the specified TypeElement.
      static java.util.List<javax.lang.model.element.ExecutableElement> getDeclaredMethods​(javax.lang.model.type.TypeMirror type)
      Gets all declared methods of the specified TypeMirror.
      static javax.lang.model.element.Element getEnclosingElement​(javax.lang.model.element.ExecutableElement method)
      Returns the enclosing element of the given executable method.
      static java.lang.String getMethodName​(javax.lang.model.element.ExecutableElement method)
      Gets the simple name of the method as a string.
      static java.util.List<javax.lang.model.type.TypeMirror> getMethodParameterTypeMirrors​(javax.lang.model.element.ExecutableElement method)
      Gets the parameter type mirrors of the given method.
      static java.lang.String[] getMethodParameterTypeNames​(javax.lang.model.element.ExecutableElement method)
      Gets the parameter type names of the given method.
      static javax.lang.model.element.ExecutableElement getOverrideMethod​(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement declaringMethod)
      Finds the overridden method in the specified type that corresponds to the given declaring method.
      static java.lang.String getReturnTypeName​(javax.lang.model.element.ExecutableElement method)
      Gets the return type name of the given method.
      static boolean isMethod​(javax.lang.model.element.ExecutableElement method)
      Checks if the given executable element is a method.
      static boolean isPublicNonStaticMethod​(javax.lang.model.element.ExecutableElement method)
      Checks whether the given method is a public non-static method.
      static boolean matches​(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
      Checks if the given method matches the specified method name and parameter type names.
      static boolean matches​(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
      Checks if the given method matches the specified method name and parameter types.
      static boolean matchesMethod​(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.CharSequence... parameterTypeNames)
      Checks if the given method matches the specified method name and parameter type names.
      static boolean matchesMethod​(javax.lang.model.element.ExecutableElement method, java.lang.String methodName, java.lang.reflect.Type... parameterTypes)
      Checks if the given method matches the specified method name and parameter types.
      static boolean matchesMethodName​(javax.lang.model.element.ExecutableElement method, java.lang.String methodName)
      Checks if the given method has the specified method name.
      static java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement> methodPredicateForExcludedTypes​(java.lang.reflect.Type... excludedTypes)
      Creates a predicate that filters out methods declared in the specified excluded types.
    • Method Detail

      • getDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> getDeclaredMethods​(javax.lang.model.element.TypeElement type)
        Gets all declared methods of the specified TypeElement.

        This method returns a list of methods directly declared in the given type element, excluding inherited methods. If the provided type element is null, an empty list is returned.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         List<ExecutableElement> methods = getDeclaredMethods(typeElement);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type element, may be null
        Returns:
        a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
      • getDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> getDeclaredMethods​(javax.lang.model.type.TypeMirror type)
        Gets all declared methods of the specified TypeMirror.

        This method returns a list of methods directly declared in the given type mirror, excluding inherited methods. If the provided type mirror is null, an empty list is returned.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = getDeclaredMethods(typeMirror);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type mirror, may be null
        Returns:
        a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
      • getAllDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> getAllDeclaredMethods​(javax.lang.model.element.TypeElement type)
        Get all declared methods of the specified type element, including those inherited from superclasses and interfaces.

        This method returns a list of methods directly declared in the given type element, including those inherited from superclasses and interfaces. If the provided type element is null, an empty list is returned.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         List<ExecutableElement> methods = getAllDeclaredMethods(typeElement);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method (including inherited): " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type element, may be null
        Returns:
        a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, or an empty list if the input type is null
      • getAllDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> getAllDeclaredMethods​(javax.lang.model.type.TypeMirror type)
        Get all declared methods of the specified type mirror, including those inherited from superclasses and interfaces.

        This method returns a list of methods directly declared in the given type mirror, including those inherited from superclasses and interfaces. If the provided type mirror is null, an empty list is returned.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = getAllDeclaredMethods(typeMirror);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method (including inherited): " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type mirror, may be null
        Returns:
        a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, or an empty list if the input type is null
      • findDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findDeclaredMethods​(javax.lang.model.element.TypeElement type,
                                                                                              java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
        Find the declared methods of the specified TypeElement.

        This method returns a list of methods directly declared in the given type element, excluding inherited methods. If the provided type element is null, an empty list is returned. Additional filters can be applied to narrow down the list of methods based on custom criteria.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         List<ExecutableElement> methods = findDeclaredMethods(typeElement);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method: " + method.getSimpleName());
         }
         

        Filtering usage example:

        
         List<ExecutableElement> publicNonStaticMethods = findDeclaredMethods(typeElement, MethodUtils::isPublicNonStaticMethod);
         for (ExecutableElement method : publicNonStaticMethods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type element, may be null
        methodFilters - the filters for method elements
        Returns:
        a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
      • findDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findDeclaredMethods​(javax.lang.model.type.TypeMirror type,
                                                                                              java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
        Find the declared methods of the specified type mirror.

        This method returns a list of methods directly declared in the given type mirror, excluding inherited methods. If the provided type mirror is null, an empty list is returned. Additional filters can be applied to narrow down the list of methods based on custom criteria.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = findDeclaredMethods(typeMirror);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method: " + method.getSimpleName());
         }
         

        Filtering usage example:

        
         List<ExecutableElement> publicNonStaticMethods = findDeclaredMethods(typeMirror, MethodUtils::isPublicNonStaticMethod);
         for (ExecutableElement method : publicNonStaticMethods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type mirror, may be null
        methodFilters - the filters for method elements
        Returns:
        a list of executable elements representing all declared methods of the specified type, or an empty list if the input type is null
      • findAllDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.element.TypeElement type,
                                                                                                 java.lang.reflect.Type... excludedTypes)
        Find all declared methods of the specified type element, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         List<ExecutableElement> methods = findAllDeclaredMethods(typeElement);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method (including inherited): " + method.getSimpleName());
         }
         

        Excluding methods from specific types:

        
         List<ExecutableElement> methodsExcludingObject = findAllDeclaredMethods(typeElement, Object.class);
         for (ExecutableElement method : methodsExcludingObject) {
             System.out.println("Method excluding Object: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type element, may be null
        excludedTypes - the types whose methods should be excluded from the result, optional
        Returns:
        a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, but excluding those declared in the excluded types, or an empty list if the input type is null
      • findAllDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.type.TypeMirror type,
                                                                                                 java.lang.reflect.Type... excludedTypes)
        Find all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and exclude methods declared in the specified excluded types.

        This method returns a list of methods directly declared in the given type mirror, including those inherited from superclasses and interfaces. If the provided type mirror is null, an empty list is returned. Additional filtering can be applied to exclude methods declared in specific types.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = findAllDeclaredMethods(typeMirror);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method (including inherited): " + method.getSimpleName());
         }
         

        Excluding methods from specific types:

        
         List<ExecutableElement> methodsExcludingObject = findAllDeclaredMethods(typeMirror, Object.class);
         for (ExecutableElement method : methodsExcludingObject) {
             System.out.println("Method excluding Object: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type mirror, may be null
        excludedTypes - the types whose methods should be excluded from the result, optional
        Returns:
        a list of executable elements representing all declared methods of the specified type, excluding those declared in the excluded types, or an empty list if the input type is null
      • findPublicNonStaticMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findPublicNonStaticMethods​(javax.lang.model.element.TypeElement type,
                                                                                                     java.lang.reflect.Type... excludedTypes)
        Finds all public non-static methods declared in the specified TypeElement, excluding those inherited from superclasses or interfaces, and optionally excludes methods declared in the specified excluded types.

        This method returns a list of executable elements representing public non-static methods directly declared in the given type element. If the provided type element is null, an empty list is returned.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         List<ExecutableElement> methods = findPublicNonStaticMethods(typeElement);
         for (ExecutableElement method : methods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         

        Excluding methods from specific types:

        
         List<ExecutableElement> methodsExcludingObject = findPublicNonStaticMethods(typeElement, Object.class);
         for (ExecutableElement method : methodsExcludingObject) {
             System.out.println("Public Non-Static Method (excluding Object): " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type element, may be null
        excludedTypes - the types whose methods should be excluded from the result, optional
        Returns:
        a list of executable elements representing all public non-static methods declared in the specified type, or an empty list if the input type is null
      • findPublicNonStaticMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findPublicNonStaticMethods​(javax.lang.model.type.TypeMirror type,
                                                                                                     java.lang.reflect.Type... excludedTypes)
        Find all public non-static methods declared in the specified type mirror, excluding those inherited from superclasses or interfaces, and optionally exclude methods declared in the specified excluded types.

        This method returns a list of executable elements representing public non-static methods directly declared in the given type. If the provided type is null, an empty list is returned.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = findPublicNonStaticMethods(typeMirror);
         for (ExecutableElement method : methods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         

        Excluding methods from specific types:

        
         List<ExecutableElement> methodsExcludingObject = findPublicNonStaticMethods(typeMirror, Object.class);
         for (ExecutableElement method : methodsExcludingObject) {
             System.out.println("Public Non-Static Method (excluding Object): " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type mirror, may be null
        excludedTypes - the types whose methods should be excluded from the result, optional
        Returns:
        a list of executable elements representing all public non-static methods declared in the specified type, excluding those declared in the excluded types, or an empty list if the input type is null
      • findAllDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.element.TypeElement type,
                                                                                                 java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
        Find all declared methods of the specified TypeElement, including those inherited from superclasses and interfaces, and optionally filter them using the provided predicates.

        This method returns a list of methods directly declared in the given type element, including those inherited from superclasses and interfaces. If the provided type element is null, an empty list is returned. Additional filters can be applied to narrow down the list of methods based on custom criteria.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         List<ExecutableElement> methods = findAllDeclaredMethods(typeElement);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method (including inherited): " + method.getSimpleName());
         }
         

        Filtering usage example:

        
         List<ExecutableElement> publicNonStaticMethods = findAllDeclaredMethods(typeElement, MethodUtils::isPublicNonStaticMethod);
         for (ExecutableElement method : publicNonStaticMethods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type element, may be null
        methodFilters - the filters for method elements, optional
        Returns:
        a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, or an empty list if the input type is null
      • findAllDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> findAllDeclaredMethods​(javax.lang.model.type.TypeMirror type,
                                                                                                 java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
        Finds all declared methods of the specified type mirror, including those inherited from superclasses and interfaces, and optionally filters them using the provided predicates.

        This method returns a list of methods directly declared in the given type mirror, including those inherited from superclasses and interfaces. If the provided type mirror is null, an empty list is returned. Additional filters can be applied to narrow down the list of methods based on custom criteria.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = findAllDeclaredMethods(typeMirror);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method (including inherited): " + method.getSimpleName());
         }
         

        Filtering usage example:

        
         List<ExecutableElement> publicNonStaticMethods = findAllDeclaredMethods(typeMirror, MethodUtils::isPublicNonStaticMethod);
         for (ExecutableElement method : publicNonStaticMethods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the specified type mirror, may be null
        methodFilters - the filters for method elements, optional
        Returns:
        a list of executable elements representing all declared methods of the specified type, including those inherited from superclasses and interfaces, or an empty list if the input type is null
      • filterDeclaredMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> filterDeclaredMethods​(javax.lang.model.type.TypeMirror type,
                                                                                                boolean includeHierarchicalTypes,
                                                                                                java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
        Filters the declared methods of the specified type based on the given predicates.

        This method returns a list of methods directly declared in the given type, optionally including those inherited from superclasses and interfaces. If the provided type is null, an empty list is returned. Additional filters can be applied to narrow down the list of methods based on custom criteria.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         List<ExecutableElement> methods = filterDeclaredMethods(typeMirror, false);
         for (ExecutableElement method : methods) {
             System.out.println("Declared Method: " + method.getSimpleName());
         }
         

        Filtering usage example:

        
         List<ExecutableElement> publicNonStaticMethods = filterDeclaredMethods(typeMirror, false, MethodUtils::isPublicNonStaticMethod);
         for (ExecutableElement method : publicNonStaticMethods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the type whose declared methods are to be filtered, may be null
        includeHierarchicalTypes - whether to include methods from superclasses and interfaces
        methodFilters - the predicates used to filter the methods, optional
        Returns:
        a list of executable elements representing the filtered methods, or an empty list if the input type is null or no methods match the filters
      • isMethod

        static boolean isMethod​(javax.lang.model.element.ExecutableElement method)
        Checks if the given executable element is a method.

        This method determines whether the provided executable element represents a method. If the element is null, the method returns false.

        Example Usage

        
         ExecutableElement executableElement = ...; // Obtain a valid ExecutableElement
         boolean isMethod = MethodUtils.isMethod(executableElement);
         if (isMethod) {
             System.out.println("The element is a method.");
         } else {
             System.out.println("The element is not a method.");
         }
         
        Parameters:
        method - the executable element to check, may be null
        Returns:
        true if the element is a method, false otherwise
      • isPublicNonStaticMethod

        static boolean isPublicNonStaticMethod​(javax.lang.model.element.ExecutableElement method)
        Checks whether the given method is a public non-static method.

        This method verifies if the provided executable element represents a method that is both public and non-static. If the method is null, the method returns false.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         boolean isPublicNonStatic = MethodUtils.isPublicNonStaticMethod(method);
         if (isPublicNonStatic) {
             System.out.println("The method is a public non-static method.");
         } else {
             System.out.println("The method is not a public non-static method.");
         }
         
        Parameters:
        method - the executable element to check, may be null
        Returns:
        true if the method is a public non-static method, false otherwise
      • findMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.element.TypeElement type,
                                                                     java.lang.String methodName)
        Finds a method with the specified name in the given type element, using an empty parameter type array as default.

        This method searches for a method with the specified name in the given type element. If no method with the specified name is found, it returns null. The search considers methods declared directly in the type, excluding inherited methods.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         String methodName = "myMethod";
         ExecutableElement method = MethodUtils.findMethod(typeElement, methodName);
        
         if (method != null) {
             System.out.println("Found method: " + method.getSimpleName());
         } else {
             System.out.println("Method not found.");
         }
         
        Parameters:
        type - the type element to search for the method
        methodName - the name of the method to find
        Returns:
        the first matching executable element representing the method, or null if none is found
      • findMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.type.TypeMirror type,
                                                                     java.lang.String methodName)
        Finds a method with the specified name in the given type mirror, using an empty parameter type array as default.

        This method searches for a method with the specified name in the given type mirror. If no method with the specified name is found, it returns null. The search considers methods declared directly in the type, excluding inherited methods.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         String methodName = "myMethod";
         ExecutableElement method = MethodUtils.findMethod(typeMirror, methodName);
        
         if (method != null) {
             System.out.println("Found method: " + method.getSimpleName());
         } else {
             System.out.println("Method not found.");
         }
         
        Parameters:
        type - the type mirror to search for the method
        methodName - the name of the method to find
        Returns:
        the first matching executable element representing the method, or null if none is found
      • findMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.element.TypeElement type,
                                                                     java.lang.String methodName,
                                                                     java.lang.reflect.Type... parameterTypes)
        Finds a method with the specified name and parameter types in the given TypeElement.

        This method searches for a method with the specified name and exact parameter types directly declared in the provided type element, excluding inherited methods. If no matching method is found, it returns null.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         String methodName = "myMethod";
         Type[] parameterTypes = new Type[] { String.class, int.class };
         ExecutableElement method = MethodUtils.findMethod(typeElement, methodName, parameterTypes);
        
         if (method != null) {
             System.out.println("Found method: " + method.getSimpleName());
         } else {
             System.out.println("Method not found.");
         }
         
        Parameters:
        type - the specified type element, may be null
        methodName - the name of the method to find, must not be null
        parameterTypes - the parameter types of the method to match, must not be null
        Returns:
        the first matching executable element representing the method, or null if none is found
      • findMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.type.TypeMirror type,
                                                                     java.lang.String methodName,
                                                                     java.lang.reflect.Type... parameterTypes)
        Finds a method with the specified name and parameter types in the given type mirror.

        This method searches for a method with the specified name and exact parameter types directly declared in the provided type mirror, excluding inherited methods. If no matching method is found, it returns null.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         String methodName = "myMethod";
         Type[] parameterTypes = new Type[] { String.class, int.class };
         ExecutableElement method = MethodUtils.findMethod(typeMirror, methodName, parameterTypes);
        
         if (method != null) {
             System.out.println("Found method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the type mirror to search for the method, may be null
        methodName - the name of the method to find, must not be null
        parameterTypes - the parameter types of the method to match, must not be null
        Returns:
        the first matching executable element representing the method, or null if none is found
      • findMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.element.TypeElement type,
                                                                     java.lang.String methodName,
                                                                     java.lang.CharSequence... parameterTypeNames)
        Finds a method with the specified name and parameter type names in the given TypeElement.

        This method searches for a method with the specified name and exact parameter type names directly declared in the provided type element, excluding inherited methods. If no matching method is found, it returns null.

        Example Usage

        
         TypeElement typeElement = ...; // Obtain a valid TypeElement
         String methodName = "myMethod";
         CharSequence[] paramTypeNames = new CharSequence[] { "java.lang.String", "int" };
         ExecutableElement method = MethodUtils.findMethod(typeElement, methodName, paramTypeNames);
        
         if (method != null) {
             System.out.println("Found method: " + method.getSimpleName());
         } else {
             System.out.println("Method not found.");
         }
         
        Parameters:
        type - the type element to search for the method, may be null
        methodName - the name of the method to find, must not be null
        parameterTypeNames - the names of the parameter types of the method to match, must not be null
        Returns:
        the first matching executable element representing the method, or null if none is found
      • findMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement findMethod​(javax.lang.model.type.TypeMirror type,
                                                                     java.lang.String methodName,
                                                                     java.lang.CharSequence... parameterTypeNames)
        Finds a method with the specified name and parameter type names in the given type mirror.

        This method searches for a method with the specified name and exact parameter type names directly declared in the provided type mirror, excluding inherited methods. If no matching method is found, it returns null.

        Example Usage

        
         TypeMirror typeMirror = ...; // Obtain a valid TypeMirror
         String methodName = "myMethod";
         CharSequence[] paramTypeNames = new CharSequence[] { "java.lang.String", "int" };
         ExecutableElement method = MethodUtils.findMethod(typeMirror, methodName, paramTypeNames);
        
         if (method != null) {
             System.out.println("Found method: " + method.getSimpleName());
         }
         
        Parameters:
        type - the type mirror to search for the method, may be null
        methodName - the name of the method to find, must not be null
        parameterTypeNames - the names of the parameter types of the method to match, must not be null
        Returns:
        the first matching executable element representing the method, or null if none is found
      • getOverrideMethod

        @Nullable
        static javax.lang.model.element.ExecutableElement getOverrideMethod​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                                                            javax.lang.model.element.TypeElement type,
                                                                            javax.lang.model.element.ExecutableElement declaringMethod)
        Finds the overridden method in the specified type that corresponds to the given declaring method.

        This method searches for a method in the provided type element that overrides the specified declaring method. It utilizes the processing environment to determine method overriding using the Elements.overrides(ExecutableElement, ExecutableElement, TypeElement) method.

        Example Usage

        
         ProcessingEnvironment processingEnv = ...; // Obtain a valid ProcessingEnvironment
         TypeElement typeElement = ...; // The type in which to find the overridden method
         ExecutableElement declaringMethod = ...; // The method being overridden
        
         ExecutableElement overriddenMethod = getOverrideMethod(processingEnv, typeElement, declaringMethod);
        
         if (overriddenMethod != null) {
             System.out.println("Overridden Method Found: " + overriddenMethod.getSimpleName());
         } else {
             System.out.println("No overridden method found.");
         }
         
        Parameters:
        processingEnv - the processing environment used to determine overriding
        type - the type element in which to search for the overridden method
        declaringMethod - the method element whose override is to be found
        Returns:
        the overridden method in the specified type, or null if no such method exists
      • filterMethods

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.element.ExecutableElement> filterMethods​(java.util.List<javax.lang.model.element.ExecutableElement> methods,
                                                                                        java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement>... methodFilters)
        Filters the given list of executable elements (methods) based on the provided predicates.

        This method applies a set of filtering predicates to a list of methods and returns a new list containing only the methods that satisfy all the provided conditions. If no method matches, an empty list is returned. If no filters are provided, the original list is returned unchanged.

        Example Usage

        
         List<ExecutableElement> methods = MethodUtils.getDeclaredMethods(typeElement);
         List<ExecutableElement> publicNonStaticMethods = MethodUtils.filterMethods(methods, MethodUtils::isPublicNonStaticMethod);
        
         for (ExecutableElement method : publicNonStaticMethods) {
             System.out.println("Public Non-Static Method: " + method.getSimpleName());
         }
         

        Multiple filters can be combined:

        
         Predicate<ExecutableElement> isPublic = method -> method.getModifiers().contains(Modifier.PUBLIC);
         Predicate<ExecutableElement> isVoidReturnType = method -> "void".equals(TypeUtils.toString(method.getReturnType()));
        
         List<ExecutableElement> filteredMethods = MethodUtils.filterMethods(methods, isPublic, isVoidReturnType);
         for (ExecutableElement method : filteredMethods) {
             System.out.println("Public Method with Void Return Type: " + method.getSimpleName());
         }
         
        Parameters:
        methods - the list of executable elements (methods) to be filtered
        methodFilters - the array of predicates used for filtering the methods
        Returns:
        a filtered list of executable elements matching all the provided predicates, or an empty list if the input list is null or empty, or no methods match the filters
      • getMethodName

        @Nullable
        static java.lang.String getMethodName​(javax.lang.model.element.ExecutableElement method)
        Gets the simple name of the method as a string.

        If the provided method is null, this method returns null. Otherwise, it returns the simple name of the method as a string.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement representing a method
         String methodName = MethodUtils.getMethodName(method);
         if (methodName != null) {
             System.out.println("Method Name: " + methodName);
         } else {
             System.out.println("Method is null.");
         }
         
        Parameters:
        method - the executable element representing the method, may be null
        Returns:
        the simple name of the method as a string, or null if the method is null
      • getReturnTypeName

        @Nullable
        static java.lang.String getReturnTypeName​(javax.lang.model.element.ExecutableElement method)
        Gets the return type name of the given method.

        If the provided method is null, this method returns null. Otherwise, it returns the fully qualified name of the method's return type.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement representing a method
         String returnTypeName = MethodUtils.getReturnTypeName(method);
         if (returnTypeName != null) {
             System.out.println("Return Type Name: " + returnTypeName);
         } else {
             System.out.println("Method is null or has no return type.");
         }
         
        Parameters:
        method - the executable element representing the method, may be null
        Returns:
        the fully qualified name of the method's return type as a string, or null if the method is null
      • getMethodParameterTypeMirrors

        @Nonnull
        @Immutable
        static java.util.List<javax.lang.model.type.TypeMirror> getMethodParameterTypeMirrors​(javax.lang.model.element.ExecutableElement method)
        Gets the parameter type mirrors of the given method.

        This method returns a list of type mirrors representing the parameter types of the provided method. If the method is null or has no parameters, an empty list is returned.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement representing a method
         List<TypeMirror> parameterTypeMirrors = MethodUtils.getMethodParameterTypeMirrors(method);
        
         if (!parameterTypeMirrors.isEmpty()) {
             for (TypeMirror typeMirror : parameterTypeMirrors) {
                 System.out.println("Parameter Type: " + TypeUtils.toString(typeMirror));
             }
         } else {
             System.out.println("Method is null or has no parameters.");
         }
         
        Parameters:
        method - the executable element representing the method, may be null
        Returns:
        a list of type mirrors representing the parameter types of the method, or an empty list if the method is null or has no parameters
      • getMethodParameterTypeNames

        static java.lang.String[] getMethodParameterTypeNames​(javax.lang.model.element.ExecutableElement method)
        Gets the parameter type names of the given method.

        This method returns an array of strings representing the fully qualified names of the parameter types of the provided method. If the method is null or has no parameters, an empty array is returned.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement representing a method
         String[] parameterTypeNames = MethodUtils.getMethodParameterTypeNames(method);
        
         if (parameterTypeNames.length > 0) {
             for (String typeName : parameterTypeNames) {
                 System.out.println("Parameter Type: " + typeName);
             }
         } else {
             System.out.println("Method is null or has no parameters.");
         }
         
        Parameters:
        method - the executable element representing the method, may be null
        Returns:
        an array of strings representing the fully qualified names of the parameter types, or an empty array if the method is null or has no parameters
      • matches

        static boolean matches​(javax.lang.model.element.ExecutableElement method,
                               java.lang.String methodName,
                               java.lang.reflect.Type... parameterTypes)
        Checks if the given method matches the specified method name and parameter types.

        This method determines whether the provided executable element (method) has the same name and parameter types as specified. If the method is null or any of the parameters are null, the result will be false.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         boolean isMatch = matches(method, "myMethod", String.class, int.class);
         if (isMatch) {
             System.out.println("The method matches the specified name and parameter types.");
         } else {
             System.out.println("The method does not match.");
         }
         
        Parameters:
        method - the executable element representing the method to check
        methodName - the name of the method to match
        parameterTypes - the parameter types of the method to match
        Returns:
        true if the method matches the given name and parameter types, false otherwise
      • matches

        static boolean matches​(javax.lang.model.element.ExecutableElement method,
                               java.lang.String methodName,
                               java.lang.CharSequence... parameterTypeNames)
        Checks if the given method matches the specified method name and parameter type names.

        This method determines whether the provided executable element (method) has the same name and parameter type names as specified. If the method is null or any of the parameters are null, the result will be false.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         boolean isMatch = matches(method, "myMethod", "java.lang.String", "int");
         if (isMatch) {
             System.out.println("The method matches the specified name and parameter type names.");
         } else {
             System.out.println("The method does not match.");
         }
         
        Parameters:
        method - the executable element representing the method to check
        methodName - the name of the method to match
        parameterTypeNames - the names of the parameter types to match
        Returns:
        true if the method matches the given name and parameter type names, false otherwise
      • matchesMethodName

        static boolean matchesMethodName​(javax.lang.model.element.ExecutableElement method,
                                         java.lang.String methodName)
        Checks if the given method has the specified method name.

        This method compares the simple name of the provided executable element (method) with the given method name. If either the method or the method name is null, the comparison is performed using Objects.equals(Object, Object).

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         boolean isMatch = MethodUtils.matchesMethodName(method, "myMethod");
        
         if (isMatch) {
             System.out.println("The method name matches.");
         } else {
             System.out.println("The method name does not match.");
         }
         
        Parameters:
        method - the executable element representing the method to check
        methodName - the name of the method to match, may be null
        Returns:
        true if the method's name matches the given method name, false otherwise
      • matchesMethod

        static boolean matchesMethod​(javax.lang.model.element.ExecutableElement method,
                                     java.lang.String methodName,
                                     java.lang.reflect.Type... parameterTypes)
        Checks if the given method matches the specified method name and parameter types.

        This method determines whether the provided executable element (method) has the same name and parameter types as specified. If the method is null or any of the parameters are null, the result will be false.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         boolean isMatch = MethodUtils.matchesMethod(method, "myMethod", String.class, int.class);
         if (isMatch) {
             System.out.println("The method matches the specified name and parameter types.");
         } else {
             System.out.println("The method does not match.");
         }
         
        Parameters:
        method - the executable element representing the method to check
        methodName - the name of the method to match
        parameterTypes - the parameter types of the method to match
        Returns:
        true if the method matches the given name and parameter types, false otherwise
      • matchesMethod

        static boolean matchesMethod​(javax.lang.model.element.ExecutableElement method,
                                     java.lang.String methodName,
                                     java.lang.CharSequence... parameterTypeNames)
        Checks if the given method matches the specified method name and parameter type names.

        This method determines whether the provided executable element (method) has the same name and parameter type names as specified. If the method is null or any of the parameters are null, the result will be false.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         boolean isMatch = MethodUtils.matchesMethod(method, "myMethod", "java.lang.String", "int");
         if (isMatch) {
             System.out.println("The method matches the specified name and parameter type names.");
         } else {
             System.out.println("The method does not match.");
         }
         
        Parameters:
        method - the executable element representing the method to check
        methodName - the name of the method to match
        parameterTypeNames - the names of the parameter types to match
        Returns:
        true if the method matches the given name and parameter type names, false otherwise
      • getEnclosingElement

        @Nullable
        static javax.lang.model.element.Element getEnclosingElement​(javax.lang.model.element.ExecutableElement method)
        Returns the enclosing element of the given executable method.

        This method retrieves the element that directly encloses the provided method. If the method is null, the method returns null.

        Example Usage

        
         ExecutableElement method = ...; // Obtain a valid ExecutableElement
         Element enclosingElement = MethodUtils.getEnclosingElement(method);
         if (enclosingElement != null) {
             System.out.println("Enclosing Element: " + enclosingElement.getSimpleName());
         } else {
             System.out.println("Method is null or has no enclosing element.");
         }
         
        Parameters:
        method - the executable element representing the method, may be null
        Returns:
        the enclosing element of the method, or null if the method is null
      • methodPredicateForExcludedTypes

        @Nonnull
        static java.util.function.Predicate<? super javax.lang.model.element.ExecutableElement> methodPredicateForExcludedTypes​(java.lang.reflect.Type... excludedTypes)
        Creates a predicate that filters out methods declared in the specified excluded types.

        This predicate can be used to exclude methods that are declared in certain types, such as standard Java types like Object, when searching or filtering through methods. If no excluded types are provided, the predicate will allow all methods.

        Example Usage

        
         Predicate<ExecutableElement> excludeObjectMethods = methodPredicateForExcludedTypes(Object.class);
         List<ExecutableElement> filteredMethods = findDeclaredMethods(typeMirror, excludeObjectMethods);
        
         for (ExecutableElement method : filteredMethods) {
             System.out.println("Filtered Method: " + method.getSimpleName());
         }
         
        Parameters:
        excludedTypes - the types whose methods should be excluded from the result, optional
        Returns:
        a predicate that returns true for methods not declared in any of the excluded types