Class RedundantModifierCompactSourceCheck

All Implemented Interfaces:
Configurable, Contextualizable

Checks for redundant modifiers on fields and methods declared directly in a compact source file. Ordinary and nested declarations are checked by RedundantModifier.
Since:
14.4.0
  • Field Details

    • MSG_KEY

      public static final String MSG_KEY
      A key is pointing to the warning message text in "messages.properties" file.
      See Also:
    • METHOD_MODIFIERS

      private static final Set<Integer> METHOD_MODIFIERS
      Modifiers that are redundant on a method declared directly in a compact source file.
    • FIELD_MODIFIERS

      private static final Set<Integer> FIELD_MODIFIERS
      Modifiers that are redundant on a field declared directly in a compact source file.
    • SAFE_VARARGS_REQUIRED

      private static final Set<Integer> SAFE_VARARGS_REQUIRED
      One of these is mandatory on a valid @SafeVarargs method.
    • SAFE_VARARGS_NAMES

      private static final Set<String> SAFE_VARARGS_NAMES
      Simple and qualified names of the SafeVarargs annotation.
    • root

      private DetailAST root
      Root of the file being processed. Only a compact source file can have a field or method as a direct child of its root.
  • Constructor Details

  • Method Details

    • 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:
    • 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:
    • 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:
    • 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
    • checkModifiers

      private void checkModifiers(DetailAST modifiers, Set<Integer> redundant, boolean keepRequired)
      Logs every modifier that is redundant for the declaration.
      Parameters:
      modifiers - the MODIFIERS node of the declaration
      redundant - token types of modifiers that are redundant
      keepRequired - whether the modifier making @SafeVarargs valid must be kept
    • isRequiredModifierKept

      private static boolean isRequiredModifierKept(DetailAST methodDef, DetailAST modifiers)
      Checks whether a modifier is the single one making @SafeVarargs valid.
      Parameters:
      methodDef - the METHOD_DEF node
      modifiers - the MODIFIERS node of the method
      Returns:
      true if the required modifier must not be reported
    • countRequiredModifiers

      private static int countRequiredModifiers(DetailAST modifiers)
      Counts the modifiers that can make a @SafeVarargs method valid.
      Parameters:
      modifiers - the MODIFIERS node
      Returns:
      number of such modifiers