public final class UnnecessarySemicolonInTryWithResourcesCheck extends AbstractCheck
Checks if unnecessary semicolon is used in last resource declaration.
allowWhenNoBraceAfterSemicolon -
Allow unnecessary semicolon if closing paren is not on the same line.
Type is boolean.
Default value is true.
To configure the check:
<module name="UnnecessarySemicolonInTryWithResources"/>
Example of violations
class A {
void method() throws IOException {
try(Reader r1 = new PipedReader();){} // violation
try(Reader r4 = new PipedReader();Reader r5 = new PipedReader()
;){} // violation
try(Reader r6 = new PipedReader();
Reader r7
= new PipedReader();
){}
}
}
To configure the check to detect unnecessary semicolon if closing paren is not on same line
<module name="UnnecessarySemicolonInTryWithResources"> <property name="allowWhenNoBraceAfterSemicolon" value="false"/> </module>
Example of exclusion
class A {
void method() throws IOException {
try(Reader r1 = new PipedReader();){} // violation
try(Reader r6 = new PipedReader();
Reader r7 = new PipedReader(); // violation
){}
}
}
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
unnecessary.semicolon
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_SEMI
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
UnnecessarySemicolonInTryWithResourcesCheck() |
| 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.
|
void |
setAllowWhenNoBraceAfterSemicolon(boolean allowWhenNoBraceAfterSemicolon)
Setter to allow unnecessary semicolon if closing paren is not on the same line.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final String MSG_SEMI
public UnnecessarySemicolonInTryWithResourcesCheck()
public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void setAllowWhenNoBraceAfterSemicolon(boolean allowWhenNoBraceAfterSemicolon)
allowWhenNoBraceAfterSemicolon - a value to set.public void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processCopyright © 2001–2020. All rights reserved.