Class TypeBodyPaddingCheck
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.whitespace.TypeBodyPaddingCheck
- All Implemented Interfaces:
Configurable,Contextualizable
Checks the padding of the body of type definitions (classes, interfaces,
enums, records).
That is, whether a blank line is required immediately after the opening brace
and/or immediately before the closing brace of type bodies.
Empty type bodies are exempt from this check by default.
A blank line (padding) line is a line containing only whitespace characters.
- Since:
- 13.9.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanAllow empty type bodies (those with no members) to omit blank line padding.private booleanRequire a blank line before the type body closing brace.private booleanRequire a blank line after the type body opening brace.static final StringA key pointing to the warning message text in "messages.properties" file.static final StringA key pointing to the warning message text in "messages.properties" file.private booleanWhether to skip inner types.private booleanWhether to skip local types (types defined inside methods or constructors). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]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 booleanhaveBlankLineAfterLeftCurly(DetailAST lcurly) Checks that a blank line exists after the opening brace of the type body.private booleanChecks that a blank line exists before the closing brace of the type body.private booleanrequirePaddingAfterLcurly(DetailAST lcurly, DetailAST rcurly) Checks if padding is required after the left curly brace.private booleanrequirePaddingBeforeRcurly(DetailAST lcurly, DetailAST rcurly) Checks if padding is required before the right curly brace.voidsetAllowEmpty(boolean allowEmpty) Setter to allow empty type bodies to omit blank line padding.voidsetAtEndOfBody(boolean atEndOfBody) Setter to require a blank line before the type body closing brace.voidsetAtStartOfBody(boolean atStartOfBody) Setter to require a blank line after the type body opening brace.voidsetSkipInner(boolean skipInner) Setter to control whether to skip checking of inner types.voidsetSkipLocal(boolean skipLocal) Setter to control whether to skip checking of local types.private booleanshouldSkipType(DetailAST ast, boolean isEmpty) Determines whether to skip checking the given AST node.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, 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_AFTER_LCURLY
A key pointing to the warning message text in "messages.properties" file. Emitted when a blank line is missing after the opening brace of a type body.- See Also:
-
MSG_BEFORE_RCURLY
A key pointing to the warning message text in "messages.properties" file. Emitted when a blank line is missing before the closing brace of a type body.- See Also:
-
atStartOfBody
Require a blank line after the type body opening brace. -
atEndOfBody
Require a blank line before the type body closing brace. -
allowEmpty
Allow empty type bodies (those with no members) to omit blank line padding. -
skipInner
Whether to skip inner types. -
skipLocal
Whether to skip local types (types defined inside methods or constructors).
-
-
Constructor Details
-
TypeBodyPaddingCheck
public TypeBodyPaddingCheck()Creates a newTypeBodyPaddingCheckinstance.
-
-
Method Details
-
setAtStartOfBody
Setter to require a blank line after the type body opening brace.- Parameters:
atStartOfBody- the value to set.- Since:
- 13.9.0
-
setAtEndOfBody
Setter to require a blank line before the type body closing brace.- Parameters:
atEndOfBody- the value to set.- Since:
- 13.9.0
-
setAllowEmpty
Setter to allow empty type bodies to omit blank line padding.- Parameters:
allowEmpty- the value to set.- Since:
- 13.9.0
-
setSkipInner
Setter to control whether to skip checking of inner types.- Parameters:
skipInner-falseto also check inner types.- Since:
- 13.9.0
-
setSkipLocal
Setter to control whether to skip checking of local types.- Parameters:
skipLocal-falseto also check local types.- Since:
- 13.9.0
-
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
-
requirePaddingAfterLcurly
Checks if padding is required after the left curly brace.- Parameters:
lcurly- the left curly brace.rcurly- the right curly brace.- Returns:
- true if padding is required.
-
requirePaddingBeforeRcurly
Checks if padding is required before the right curly brace.- Parameters:
lcurly- the left curly brace.rcurly- the right curly brace.- Returns:
- true if padding is required.
-
haveBlankLineAfterLeftCurly
Checks that a blank line exists after the opening brace of the type body. The line immediately following the LCURLY line must be blank (contain only whitespace).- Parameters:
lcurly- the LCURLY token.- Returns:
- true if there is a blank line after the opening brace.
-
haveBlankLineBeforeRightCurly
Checks that a blank line exists before the closing brace of the type body. The line immediately preceding the RCURLY line must be blank.- Parameters:
rcurly- the RCURLY token.- Returns:
- true if there is a blank line before the closing brace.
-
shouldSkipType
Determines whether to skip checking the given AST node.- Parameters:
ast- the AST node to checkisEmpty- whether the type body is empty- Returns:
trueif the node should be skipped,falseotherwise
-