Class AnnotationService

java.lang.Object
org.openrewrite.java.service.AnnotationService

@Incubating(since="8.12.0") public class AnnotationService extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    annotatedWith(org.openrewrite.java.tree.J j, String annotationFqn)
    Finds all instances of the specified annotation in the type hierarchy, including direct annotations, inherited annotations, and meta-annotations.
    annotatedWith(org.openrewrite.java.tree.J j, String annotationFqn, boolean includeMetaAnnotations)
    Finds all instances of the specified annotation in the type hierarchy, including direct annotations, inherited annotations, and optionally meta-annotations.
    List<org.openrewrite.java.tree.J.Annotation>
    getAllAnnotations(org.openrewrite.Cursor cursor)
     
    boolean
    isAnnotatedWith(org.openrewrite.java.tree.J j, String annotationFqn)
    Checks if the given element has the specified annotation, searching through type information including: - Direct annotations on the element - Inherited annotations from parent classes (for class declarations) - Inherited annotations from overridden methods (for method declarations) - Meta-annotations (annotations on annotations)
    boolean
    isAnnotatedWith(org.openrewrite.java.tree.J j, String annotationFqn, boolean includeMetaAnnotations)
    Checks if the given element has the specified annotation, searching through type information including: - Direct annotations on the element - Inherited annotations from parent classes (for class declarations) - Inherited annotations from overridden methods (for method declarations) - Optionally, meta-annotations (annotations on annotations)
    boolean
    matches(org.openrewrite.Cursor cursor, AnnotationMatcher matcher)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AnnotationService

      public AnnotationService()
  • Method Details

    • matches

      public boolean matches(org.openrewrite.Cursor cursor, AnnotationMatcher matcher)
    • getAllAnnotations

      public List<org.openrewrite.java.tree.J.Annotation> getAllAnnotations(org.openrewrite.Cursor cursor)
    • isAnnotatedWith

      public boolean isAnnotatedWith(org.openrewrite.java.tree.J j, String annotationFqn)
      Checks if the given element has the specified annotation, searching through type information including: - Direct annotations on the element - Inherited annotations from parent classes (for class declarations) - Inherited annotations from overridden methods (for method declarations) - Meta-annotations (annotations on annotations)
      Parameters:
      j - The element to check (J.ClassDeclaration, J.MethodDeclaration, or J.VariableDeclarations)
      annotationFqn - The fully qualified name of the annotation to search for
      Returns:
      true if the annotation is found anywhere in the hierarchy, false otherwise
    • isAnnotatedWith

      public boolean isAnnotatedWith(org.openrewrite.java.tree.J j, String annotationFqn, boolean includeMetaAnnotations)
      Checks if the given element has the specified annotation, searching through type information including: - Direct annotations on the element - Inherited annotations from parent classes (for class declarations) - Inherited annotations from overridden methods (for method declarations) - Optionally, meta-annotations (annotations on annotations)
      Parameters:
      j - The element to check (J.ClassDeclaration, J.MethodDeclaration, or J.VariableDeclarations)
      annotationFqn - The fully qualified name of the annotation to search for
      includeMetaAnnotations - Whether to search for meta-annotations (annotations on annotations)
      Returns:
      true if the annotation is found anywhere in the hierarchy, false otherwise
    • annotatedWith

      public List<JavaType.FullyQualified> annotatedWith(org.openrewrite.java.tree.J j, String annotationFqn)
      Finds all instances of the specified annotation in the type hierarchy, including direct annotations, inherited annotations, and meta-annotations.
      Parameters:
      j - The element to check (J.ClassDeclaration, J.MethodDeclaration, or J.VariableDeclarations)
      annotationFqn - The fully qualified name of the annotation to search for
      Returns:
      A list of all matching annotations found in the hierarchy
    • annotatedWith

      public List<JavaType.FullyQualified> annotatedWith(org.openrewrite.java.tree.J j, String annotationFqn, boolean includeMetaAnnotations)
      Finds all instances of the specified annotation in the type hierarchy, including direct annotations, inherited annotations, and optionally meta-annotations.
      Parameters:
      j - The element to check (J.ClassDeclaration, J.MethodDeclaration, or J.VariableDeclarations)
      annotationFqn - The fully qualified name of the annotation to search for
      includeMetaAnnotations - Whether to search for meta-annotations (annotations on annotations)
      Returns:
      A list of all matching annotations found in the hierarchy