Class RedundantModifierCompactSourceCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.modifier.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
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionModifiers that are redundant on a field declared directly in a compact source file.Modifiers that are redundant on a method declared directly in a compact source file.static final StringA key is pointing to the warning message text in "messages.properties" file.private DetailASTRoot of the file being processed.Simple and qualified names of theSafeVarargsannotation.One of these is mandatory on a valid @SafeVarargs method. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newRedundantModifierCompactSourceCheckinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled before the starting to process a tree.private voidcheckModifiers(DetailAST modifiers, Set<Integer> redundant, boolean keepRequired) Logs every modifier that is redundant for the declaration.private static intcountRequiredModifiers(DetailAST modifiers) Counts the modifiers that can make a@SafeVarargsmethod valid.int[]The configurable token set.int[]Returns the default token a check is interested in.int[]The tokens that this check must be registered for.private static booleanisRequiredModifierKept(DetailAST methodDef, DetailAST modifiers) Checks whether a modifier is the single one making@SafeVarargsvalid.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
METHOD_MODIFIERS
Modifiers that are redundant on a method declared directly in a compact source file. -
FIELD_MODIFIERS
Modifiers that are redundant on a field declared directly in a compact source file. -
SAFE_VARARGS_REQUIRED
One of these is mandatory on a valid @SafeVarargs method. -
SAFE_VARARGS_NAMES
Simple and qualified names of theSafeVarargsannotation. -
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
-
RedundantModifierCompactSourceCheck
public RedundantModifierCompactSourceCheck()Creates a newRedundantModifierCompactSourceCheckinstance.
-
-
Method Details
-
beginTree
Description copied from class:AbstractCheckCalled before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.- Overrides:
beginTreein classAbstractCheck- Parameters:
rootAST- the root of the tree
-
getDefaultTokens
Description copied from class:AbstractCheckReturns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
getDefaultTokensin classAbstractCheck- Returns:
- the default tokens
- See Also:
-
getAcceptableTokens
Description copied from class:AbstractCheckThe 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:
getAcceptableTokensin classAbstractCheck- Returns:
- the token set this check is designed for.
- See Also:
-
getRequiredTokens
Description copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
getRequiredTokensin classAbstractCheck- Returns:
- the token set this must be registered for.
- See Also:
-
visitToken
Description copied from class:AbstractCheckCalled to process a token.- Overrides:
visitTokenin classAbstractCheck- Parameters:
ast- the token to process
-
checkModifiers
Logs every modifier that is redundant for the declaration.- Parameters:
modifiers- the MODIFIERS node of the declarationredundant- token types of modifiers that are redundantkeepRequired- whether the modifier making@SafeVarargsvalid must be kept
-
isRequiredModifierKept
Checks whether a modifier is the single one making@SafeVarargsvalid.- Parameters:
methodDef- the METHOD_DEF nodemodifiers- the MODIFIERS node of the method- Returns:
- true if the required modifier must not be reported
-
countRequiredModifiers
Counts the modifiers that can make a@SafeVarargsmethod valid.- Parameters:
modifiers- the MODIFIERS node- Returns:
- number of such modifiers
-