public class RedundantReturnCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Highlights usage of redundant returns inside constructors and methods with void result.
For example:
1. Non-empty constructor
public HelloWorld(){
doStuff();
return;
}
2. Method with void result
public void testMethod1(){
doStuff();
return;
}
However, if your IDE does not support breakpoints on the method entry, you can allow the use of redundant returns in constructors and methods with void result without code except for 'return;'.
For example:
1. Empty constructor
public HelloWorld(){
return;
}
2. Method with void result and empty body
public void testMethod1(){
return;
}| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
RedundantReturnCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
void |
setAllowReturnInEmptyMethodsAndConstructors(boolean allowEmptyBlocks)
Setter for allowReturnInEmptyMethodsAndConstructors.
|
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) |
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, setSeveritypublic static final String MSG_KEY
public void setAllowReturnInEmptyMethodsAndConstructors(boolean allowEmptyBlocks)
allowEmptyBlocks - allow 'return' in empty constructors and methods that return void.public int[] getDefaultTokens()
getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getAcceptableTokens()
getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getRequiredTokens()
getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheckCopyright © 2021. All rights reserved.