public class EmptyLineSeparatorCheck extends Check
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>
| 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_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[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
void |
setAllowMultipleEmptyLines(boolean allow)
Allow multiple empty lines between class members.
|
void |
setAllowNoEmptyLineBetweenFields(boolean allow)
Allow no empty line between fields.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLine, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokensgetCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverityconfigure, contextualize, finishLocalSetup, getConfiguration, setupChildpublic static final String MSG_SHOULD_BE_SEPARATED
public static final String MSG_MULTIPLE_LINES
public EmptyLineSeparatorCheck()
public final void setAllowNoEmptyLineBetweenFields(boolean allow)
allow - User's value.public void setAllowMultipleEmptyLines(boolean allow)
allow - User's value.public int[] getDefaultTokens()
CheckgetDefaultTokens in class CheckTokenTypespublic void visitToken(DetailAST ast)
CheckvisitToken in class Checkast - the token to processCopyright © 2001–2015. All rights reserved.