public class UncommentedMainCheck extends AbstractCheck
Detects uncommented main methods.
Rationale: A main method is often used for debugging purposes.
When debugging is finished, developers often forget to remove the method,
which changes the API and increases the size of the resulting class or JAR file.
With the exception of the real program entry points, all main methods
should be removed or commented out of the sources.
excludedClasses - Specify pattern for qualified names of
classes which are allowed to have a main method.
Type is java.util.regex.Pattern.
Default value is "^$" (empty).
To configure the check:
<module name="UncommentedMain"/>
Example:
public class Game {
public static void main(String... args){} // violation
}
public class Main {
public static void main(String[] args){} // violation
}
public class Launch {
//public static void main(String[] args){} // OK
}
public class Start {
public void main(){} // OK
}
To configure the check to allow the main method for all classes with "Main" name:
<module name="UncommentedMain"> <property name="excludedClasses" value="\.Main$"/> </module>
Example:
public class Game {
public static void main(String... args){} // violation
}
public class Main {
public static void main(String[] args){} // OK
}
public class Launch {
//public static void main(String[] args){} // OK
}
public class Start {
public void main(){} // OK
}
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
uncommented.main
AutomaticBean.OutputStreamOptions| 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 |
|---|
UncommentedMainCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
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 |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
void |
setExcludedClasses(Pattern excludedClasses)
Setter to specify pattern for qualified names of classes which are allowed
to have a
main method. |
void |
visitToken(DetailAST ast)
Called to process a token.
|
clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final String MSG_KEY
public UncommentedMainCheck()
public void setExcludedClasses(Pattern excludedClasses)
main method.excludedClasses - a patternpublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void beginTree(DetailAST rootAST)
AbstractCheckbeginTree in class AbstractCheckrootAST - the root of the treepublic void leaveToken(DetailAST ast)
AbstractCheckleaveToken in class AbstractCheckast - the token leavingpublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processCopyright © 2001–2020. All rights reserved.