public final class UnnecessarySemicolonAfterTypeMemberDeclarationCheck extends AbstractCheck
Checks if unnecessary semicolon is used after type member declaration.
This check is not applicable to empty statements (unnecessary semicolons inside methods or init blocks), EmptyStatement is responsible for it.
tokens - tokens to check
Type is java.lang.String[].
Validation type is tokenSet.
Default value is:
CLASS_DEF,
INTERFACE_DEF,
ENUM_DEF,
ANNOTATION_DEF,
VARIABLE_DEF,
ANNOTATION_FIELD_DEF,
STATIC_INIT,
INSTANCE_INIT,
CTOR_DEF,
METHOD_DEF,
ENUM_CONSTANT_DEF,
COMPACT_CTOR_DEF,
RECORD_DEF.
To configure the check:
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration"/>
Results in following:
class A {
; // violation, standalone semicolon
{}; // violation, extra semicolon after init block
static {}; // violation, extra semicolon after static init block
A(){}; // violation, extra semicolon after constructor definition
void method() {}; // violation, extra semicolon after method definition
int field = 10;; // violation, extra semicolon after field declaration
{
; // no violation, it is empty statement inside init block
}
static {
; // no violation, it is empty statement inside static init block
}
void anotherMethod() {
; // no violation, it is empty statement
if(true); // no violation, it is empty statement
}
}
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
unnecessary.semicolon
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_SEMI
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
UnnecessarySemicolonAfterTypeMemberDeclarationCheck() |
| Modifier and Type | Method and Description |
|---|---|
private void |
checkEnumConstant(DetailAST ast)
Checks if enum constant has unnecessary semicolon.
|
private void |
checkTypeDefinition(DetailAST ast)
Checks if type definition has unnecessary semicolon.
|
private void |
checkTypeMember(DetailAST ast)
Checks if type member has unnecessary semicolon.
|
private void |
checkVariableDefinition(DetailAST variableDef)
Checks if variable definition has unnecessary semicolon.
|
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.
|
private static boolean |
isSemicolon(DetailAST ast)
Checks that
ast is a semicolon. |
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearViolations, destroy, finishTree, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_SEMI
public UnnecessarySemicolonAfterTypeMemberDeclarationCheck()
public 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 processprivate void checkTypeMember(DetailAST ast)
ast - type memberprivate void checkTypeDefinition(DetailAST ast)
ast - type definitionprivate void checkVariableDefinition(DetailAST variableDef)
variableDef - variable definitionprivate void checkEnumConstant(DetailAST ast)
ast - enum constantprivate static boolean isSemicolon(DetailAST ast)
ast is a semicolon.ast - token to checkCopyright © 2001-2022. All Rights Reserved.