Class AnnotatedDeclarationVisibilityCheck

All Implemented Interfaces:
Configurable, Contextualizable

Checks that elements annotated with specified annotations have only allowed visibility modifiers.

This check enforces consistency between annotation presence and declared visibility. If a configured annotation is found on a target element, its visibility modifier must match one of the allowed values.

Since:
13.9.0
  • Field Details

  • Constructor Details

  • Method Details

    • setAnnotations

      public void setAnnotations(String... values)
      Setter for annotation canonical names.
      Parameters:
      values - comma-separated fully qualified annotation names
      Since:
      13.9.0
    • setVisibility

      public void setVisibility(AccessModifierOption... values)
      Setter for allowed visibility modifiers. Allowed values: public, protected, package, private.
      Parameters:
      values - allowed visibility values
      Since:
      13.9.0
    • beginTree

      public void beginTree(DetailAST rootAST)
      Description copied from class: AbstractCheck
      Called before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.
      Overrides:
      beginTree in class AbstractCheck
      Parameters:
      rootAST - the root of the tree
    • getDefaultTokens

      public int[] getDefaultTokens()
      Description copied from class: AbstractCheck
      Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.
      Specified by:
      getDefaultTokens in class AbstractCheck
      Returns:
      the default tokens
      See Also:
    • getRequiredTokens

      public int[] getRequiredTokens()
      Description copied from class: AbstractCheck
      The tokens that this check must be registered for.
      Specified by:
      getRequiredTokens in class AbstractCheck
      Returns:
      the token set this must be registered for.
      See Also:
    • getAcceptableTokens

      public int[] getAcceptableTokens()
      Description copied from class: AbstractCheck
      The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.
      Specified by:
      getAcceptableTokens in class AbstractCheck
      Returns:
      the token set this check is designed for.
      See Also:
    • visitToken

      public void visitToken(DetailAST ast)
      Description copied from class: AbstractCheck
      Called to process a token.
      Overrides:
      visitToken in class AbstractCheck
      Parameters:
      ast - the token to process
    • handlePackage

      private void handlePackage(DetailAST ast)
      Handles package declarations and stores the current package name.
      Parameters:
      ast - package definition node
    • handleImport

      private void handleImport(DetailAST ast)
      Processes import statements and records imported annotations.
      Parameters:
      ast - import node
    • checkAnnotatedVisibility

      private void checkAnnotatedVisibility(DetailAST ast)
      Checks the visibility of annotated elements.
      Parameters:
      ast - AST node to inspect
    • hasConfiguredAnnotation

      private boolean hasConfiguredAnnotation(DetailAST ast)
      Determines whether the AST node contains a configured annotation.
      Parameters:
      ast - AST node to inspect
      Returns:
      true if the annotation is present
    • resolveAnnotation

      Resolves the fully qualified name of an annotation.
      Parameters:
      name - annotation name
      Returns:
      resolved canonical name
    • isAllowedVisibility

      private boolean isAllowedVisibility(AccessModifierOption accessModifier)
      Checks whether the given visibility value is allowed.
      Parameters:
      accessModifier - visibility value
      Returns:
      true if given visibility value is allowed
    • getVisibilityName

      private static String getVisibilityName(AccessModifierOption accessModifier)
      Gets the visibility value to display in violation messages.
      Parameters:
      accessModifier - visibility value
      Returns:
      display name of the visibility value