public class EmptyLineSeparatorCheck extends AbstractCheck
By default the check will check the following statements:
PACKAGE_DEF,
IMPORT,
CLASS_DEF,
INTERFACE_DEF,
STATIC_INIT,
INSTANCE_INIT,
METHOD_DEF,
CTOR_DEF,
VARIABLE_DEF.
Example of declarations without empty line separator:
///////////////////////////////////////////////////
//HEADER
///////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.whitespace;
import java.io.Serializable;
class Foo
{
public static final int FOO_CONST = 1;
public void foo() {} //should be separated from previous statement.
}
An example of how to configure the check with default parameters is:
<module name="EmptyLineSeparator"/>
Example of declarations with empty line separator that is expected by the Check by default:
///////////////////////////////////////////////////
//HEADER
///////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.whitespace;
import java.io.Serializable;
class Foo
{
public static final int FOO_CONST = 1;
public void foo() {}
}
An example how to check empty line after
VARIABLE_DEF and
METHOD_DEF:
<module name="EmptyLineSeparator">
<property name="tokens" value="VARIABLE_DEF, METHOD_DEF"/>
</module>
An example how to allow no empty line between fields:
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
Example of declarations with multiple empty lines between class members (allowed by default):
///////////////////////////////////////////////////
//HEADER
///////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.whitespace;
import java.io.Serializable;
class Foo
{
public static final int FOO_CONST = 1;
public void foo() {}
}
An example how to disallow multiple empty lines between class members:
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLines" value="false"/>
</module>
An example how to disallow multiple empty line inside methods, constructors, etc.:
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
</module>
The check is valid only for statements that have body:
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF
Example of declarations with multiple empty lines inside method:
///////////////////////////////////////////////////
//HEADER
///////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.whitespace;
class Foo
{
public void foo() {
System.out.println(1); // violation since method has 2 empty lines subsequently
}
}
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_MULTIPLE_LINES
A key is pointing to the warning message empty.line.separator.multiple.lines
in "messages.properties"
file.
|
static String |
MSG_MULTIPLE_LINES_AFTER
A key is pointing to the warning message empty.line.separator.lines.after
in "messages.properties" file.
|
static String |
MSG_MULTIPLE_LINES_INSIDE
A key is pointing to the warning message empty.line.separator.multiple.lines.inside
in "messages.properties" file.
|
static String |
MSG_SHOULD_BE_SEPARATED
A key is pointing to the warning message empty.line.separator in "messages.properties"
file.
|
| Constructor and Description |
|---|
EmptyLineSeparatorCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
boolean |
isCommentNodesRequired()
Whether comment nodes are required or not.
|
void |
setAllowMultipleEmptyLines(boolean allow)
Allow multiple empty lines between class members.
|
void |
setAllowMultipleEmptyLinesInsideClassMembers(boolean allow)
Allow multiple empty lines inside class members.
|
void |
setAllowNoEmptyLineBetweenFields(boolean allow)
Allow no empty line between fields.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, leaveToken, log, log, log, setClassLoader, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final String MSG_SHOULD_BE_SEPARATED
public static final String MSG_MULTIPLE_LINES
public static final String MSG_MULTIPLE_LINES_AFTER
public static final String MSG_MULTIPLE_LINES_INSIDE
public EmptyLineSeparatorCheck()
public final void setAllowNoEmptyLineBetweenFields(boolean allow)
allow - User's value.public void setAllowMultipleEmptyLines(boolean allow)
allow - User's value.public void setAllowMultipleEmptyLinesInsideClassMembers(boolean allow)
allow - User's value.public boolean isCommentNodesRequired()
AbstractCheckisCommentNodesRequired in class AbstractCheckpublic int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processCopyright © 2001–2018. All rights reserved.