Class EmptyLineSeparatorCheck
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.EmptyLineSeparatorCheck
- All Implemented Interfaces:
- Configurable,- Contextualizable
 Checks for empty line separators before package, all import declarations,
 fields, constructors, methods, nested classes,
 static initializers and instance initializers.
 
 Checks for empty line separators before not only statements but implementation and documentation comments and blocks as well.
ATTENTION: empty line separator is required between token siblings, not after line where token is found. If token does not have a sibling of the same type, then empty line is required at its end (for example for CLASS_DEF it is after '}'). Also, trailing comments are skipped.
- Since:
- 5.8
- 
Nested Class SummaryNested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanAbstractAutomaticBean.OutputStreamOptions
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate booleanAllow multiple empty lines between class members.private booleanAllow multiple empty lines inside class members.private booleanAllow no empty line between fields.static final StringA key is pointing to the warning message empty.line.separator.multiple.lines in "messages.properties" file.static final StringA key is pointing to the warning message empty.line.separator.lines.after in "messages.properties" file.static final StringA key is pointing to the warning message empty.line.separator.multiple.lines.inside in "messages.properties" file.static final StringA key is pointing to the warning message empty.line.separator in "messages.properties" file.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprivate voidcheckCommentInModifiers(DetailAST packageDef) Checks that packageDef token is separated from comment in modifiers.private voidcheckComments(DetailAST token) Check if group of comments located right before token has more than one previous empty line.private voidCheck if group of comments located at the start of token has more than one previous empty line.private voidcheckToken(DetailAST ast, DetailAST nextToken) Checks that token and next token are separated.findCommentUnder(DetailAST packageDef) Finds comment in next sibling of given packageDef.int[]The configurable token set.int[]Returns the default token a check is interested in.getEmptyLines(DetailAST ast) Get list of empty lines.getEmptyLinesToLog(Iterable<Integer> emptyLines) Get list of empty lines to log.private static DetailASTgetLastElementBeforeEmptyLines(DetailAST ast, int line) Returns the element after which empty lines exist.getPostFixNode(DetailAST ast) Gets postfix Node from AST if present.int[]The tokens that this check must be registered for.private static DetailASTGets the Ast on which violation is to be given for package declaration.private booleanhasEmptyLine(int startLine, int endLine) Checks, whether there are empty lines within the specified line range.private booleanhasEmptyLineAfter(DetailAST token) Checks if token have empty line after.private booleanhasEmptyLineBefore(DetailAST token) Checks if a token has an empty line before.private booleanWhether the token has not allowed multiple empty lines before.private booleanChecks if a token has empty two previous lines and multiple empty lines is not allowed.private static booleanisClassMemberBlock(int astType) Whether the AST is a class member block.private booleanisCommentInBeginningOfLine(DetailAST comment) Check if token is comment, which starting in beginning of line.booleanWhether comment nodes are required or not.private static booleanChecks if there is another element at next line of package declaration.private static booleanisPrecededByJavadoc(DetailAST token) Check if token is preceded by javadoc comment.private booleanisPrePreviousLineEmpty(DetailAST token) Checks if a token has empty pre-previous line.private static booleanisTokenNotOnPreviousSiblingLines(DetailAST token, DetailAST parentToken) Checks if token is not placed on the realm of previous sibling of token's parent.private booleanChecks if token has two preceding lines empty, starting from its describing comment.private static booleanisTypeField(DetailAST variableDef) If variable definition is a type field.private booleanisViolatingEmptyLineBetweenFieldsPolicy(DetailAST detailAST) Checks whether token placement violates policy of empty line between fields.private voidprocessImport(DetailAST ast, DetailAST nextToken) Process Import.private voidLog violation in case there are multiple empty lines inside constructor, initialization block or method.private voidprocessPackage(DetailAST ast, DetailAST nextToken) Process Package.private voidprocessVariableDef(DetailAST ast, DetailAST nextToken) Process Variable.voidsetAllowMultipleEmptyLines(boolean allow) Setter to allow multiple empty lines between class members.voidsetAllowMultipleEmptyLinesInsideClassMembers(boolean allow) Setter to allow multiple empty lines inside class members.final voidsetAllowNoEmptyLineBetweenFields(boolean allow) Setter to allow no empty line between fields.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheckbeginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporterfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanconfigure, contextualize, getConfiguration, setupChild
- 
Field Details- 
MSG_SHOULD_BE_SEPARATEDA key is pointing to the warning message empty.line.separator in "messages.properties" file.- See Also:
 
- 
MSG_MULTIPLE_LINESA key is pointing to the warning message empty.line.separator.multiple.lines in "messages.properties" file.- See Also:
 
- 
MSG_MULTIPLE_LINES_AFTERA key is pointing to the warning message empty.line.separator.lines.after in "messages.properties" file.- See Also:
 
- 
MSG_MULTIPLE_LINES_INSIDEA key is pointing to the warning message empty.line.separator.multiple.lines.inside in "messages.properties" file.- See Also:
 
- 
allowNoEmptyLineBetweenFieldsAllow no empty line between fields.
- 
allowMultipleEmptyLinesAllow multiple empty lines between class members.
- 
allowMultipleEmptyLinesInsideClassMembersAllow multiple empty lines inside class members.
 
- 
- 
Constructor Details- 
EmptyLineSeparatorCheckpublic EmptyLineSeparatorCheck()
 
- 
- 
Method Details- 
setAllowNoEmptyLineBetweenFieldsSetter to allow no empty line between fields.- Parameters:
- allow- User's value.
- Since:
- 5.8
 
- 
setAllowMultipleEmptyLinesSetter to allow multiple empty lines between class members.- Parameters:
- allow- User's value.
- Since:
- 6.3
 
- 
setAllowMultipleEmptyLinesInsideClassMembersSetter to allow multiple empty lines inside class members.- Parameters:
- allow- User's value.
- Since:
- 6.18
 
- 
isCommentNodesRequiredDescription copied from class:AbstractCheckWhether comment nodes are required or not.- Overrides:
- isCommentNodesRequiredin class- AbstractCheck
- Returns:
- false as a default value.
 
- 
getDefaultTokensDescription 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 class- AbstractCheck
- Returns:
- the default tokens
- See Also:
 
- 
getAcceptableTokensDescription 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 class- AbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
 
- 
getRequiredTokensDescription copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
- getRequiredTokensin class- AbstractCheck
- Returns:
- the token set this must be registered for.
- See Also:
 
- 
visitTokenDescription copied from class:AbstractCheckCalled to process a token.- Overrides:
- visitTokenin class- AbstractCheck
- Parameters:
- ast- the token to process
 
- 
checkTokenChecks that token and next token are separated.- Parameters:
- ast- token to validate
- nextToken- next sibling of the token
 
- 
checkCommentInModifiersChecks that packageDef token is separated from comment in modifiers.- Parameters:
- packageDef- package def token
 
- 
processMultipleLinesInsideLog violation in case there are multiple empty lines inside constructor, initialization block or method.- Parameters:
- ast- the ast to check.
 
- 
getLastElementBeforeEmptyLinesReturns the element after which empty lines exist.- Parameters:
- ast- the ast to check.
- line- the empty line which gives violation.
- Returns:
- The DetailAST after which empty lines are present.
 
- 
getPostFixNodeGets postfix Node from AST if present.- Parameters:
- ast- the AST used to get postfix Node.
- Returns:
- Optional postfix node.
 
- 
isClassMemberBlockWhether the AST is a class member block.- Parameters:
- astType- the AST to check.
- Returns:
- true if the AST is a class member block.
 
- 
getEmptyLinesGet list of empty lines.- Parameters:
- ast- the ast to check.
- Returns:
- list of line numbers for empty lines.
 
- 
getEmptyLinesToLogGet list of empty lines to log.- Parameters:
- emptyLines- list of empty lines.
- Returns:
- list of empty lines to log.
 
- 
hasMultipleLinesBeforeWhether the token has not allowed multiple empty lines before.- Parameters:
- ast- the ast to check.
- Returns:
- true if the token has not allowed multiple empty lines before.
 
- 
processPackageProcess Package.- Parameters:
- ast- token
- nextToken- next token
 
- 
isLineEmptyAfterPackageChecks if there is another element at next line of package declaration.- Parameters:
- ast- Package ast.
- Returns:
- true, if there is an element.
 
- 
getViolationAstForPackageGets the Ast on which violation is to be given for package declaration.- Parameters:
- ast- Package ast.
- Returns:
- Violation ast.
 
- 
processImportProcess Import.- Parameters:
- ast- token
- nextToken- next token
 
- 
processVariableDefProcess Variable.- Parameters:
- ast- token
- nextToken- next Token
 
- 
isViolatingEmptyLineBetweenFieldsPolicyChecks whether token placement violates policy of empty line between fields.- Parameters:
- detailAST- token to be analyzed
- Returns:
- true if policy is violated and warning should be raised; false otherwise
 
- 
hasNotAllowedTwoEmptyLinesBeforeChecks if a token has empty two previous lines and multiple empty lines is not allowed.- Parameters:
- token- DetailAST token
- Returns:
- true, if token has empty two lines before and allowMultipleEmptyLines is false
 
- 
checkCommentsCheck if group of comments located right before token has more than one previous empty line.- Parameters:
- token- DetailAST token
 
- 
checkCommentsInsideTokenCheck if group of comments located at the start of token has more than one previous empty line.- Parameters:
- token- DetailAST token
 
- 
isPrePreviousLineEmptyChecks if a token has empty pre-previous line.- Parameters:
- token- DetailAST token.
- Returns:
- true, if token has empty lines before.
 
- 
isTwoPrecedingPreviousLinesFromCommentEmptyChecks if token has two preceding lines empty, starting from its describing comment.- Parameters:
- token- token checked.
- Returns:
- true, if both previous and pre-previous lines from dependent comment are empty
 
- 
isTokenNotOnPreviousSiblingLinesChecks if token is not placed on the realm of previous sibling of token's parent.- Parameters:
- token- token checked.
- parentToken- parent token.
- Returns:
- true, if child token doesn't occupy parent token's previous sibling's realm.
 
- 
hasEmptyLineAfterChecks if token have empty line after.- Parameters:
- token- token.
- Returns:
- true if token have empty line after.
 
- 
findCommentUnderFinds comment in next sibling of given packageDef.- Parameters:
- packageDef- token to check
- Returns:
- comment under the token
 
- 
hasEmptyLineChecks, whether there are empty lines within the specified line range. Line numbering is started from 1 for parameter values- Parameters:
- startLine- number of the first line in the range
- endLine- number of the second line in the range
- Returns:
- trueif found any blank line within the range,- falseotherwise
 
- 
hasEmptyLineBeforeChecks if a token has an empty line before.- Parameters:
- token- token.
- Returns:
- true, if token have empty line before.
 
- 
isCommentInBeginningOfLineCheck if token is comment, which starting in beginning of line.- Parameters:
- comment- comment token for check.
- Returns:
- true, if token is comment, which starting in beginning of line.
 
- 
isPrecededByJavadocCheck if token is preceded by javadoc comment.- Parameters:
- token- token for check.
- Returns:
- true, if token is preceded by javadoc comment.
 
- 
isTypeFieldIf variable definition is a type field.- Parameters:
- variableDef- variable definition.
- Returns:
- true variable definition is a type field.
 
 
-