public final class IllegalTypeCheck extends AbstractFormatCheck
Checks that particular class are never used as types in variable declarations, return values or parameters. Includes a pattern check that by default disallows abstract classes.
Rationale: Helps reduce coupling on concrete classes. In addition abstract classes should be thought of a convenience base class implementations of interfaces and as such are not types themselves.
Check has following properties:format - Pattern for illegal class names.
legalAbstractClassNames - Abstract classes that may be used as types.
illegalClassNames - Classes that should not be used as types in variable declarations, return values or parameters. It is possible to set illegal class names via short or canonical name. Specifying illegal type invokes analyzing imports and Check puts violations at corresponding declarations (of variables, methods or parameters). This helps to avoid ambiguous cases, e.g.:
java.awt.List
was set as illegal class name, then, code like:
import java.util.List;
...
List list; //No violation here
ignoredMethodNames - Methods that should not be checked.
memberModifiers - To check only methods and fields with only specified modifiers.
In most cases it's justified to put following classes to illegalClassNames:
Constructor and Description |
---|
IllegalTypeCheck()
Creates new instance of the check.
|
Modifier and Type | Method and Description |
---|---|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
String[] |
getIgnoredMethodNames()
Get the list of ignored method names.
|
String[] |
getIllegalClassNames()
Get the list of illegal variable types.
|
String[] |
getLegalAbstractClassNames()
Get the list of legal abstract class names.
|
void |
setIgnoredMethodNames(String[] methodNames)
Set the list of ignore method names.
|
void |
setIllegalClassNames(String[] classNames)
Set the list of illegal variable types.
|
void |
setLegalAbstractClassNames(String[] classNames)
Set the list of legal abstract class names.
|
void |
setMemberModifiers(String modifiers)
Set the list of member modifiers (of methods and fields) which should be checked.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
getFormat, getRegexp, setCompileFlags, setFormat
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLine, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public IllegalTypeCheck()
public int[] getDefaultTokens()
Check
getDefaultTokens
in class Check
TokenTypes
public void visitToken(DetailAST ast)
Check
visitToken
in class Check
ast
- the token to processpublic void setIllegalClassNames(String[] classNames)
classNames
- array of illegal variable typespublic String[] getIllegalClassNames()
public void setIgnoredMethodNames(String[] methodNames)
methodNames
- array of ignored method namespublic String[] getIgnoredMethodNames()
public void setLegalAbstractClassNames(String[] classNames)
classNames
- array of legal abstract class namespublic String[] getLegalAbstractClassNames()
public void setMemberModifiers(String modifiers)
modifiers
- String contains modifiers.Copyright © 2001–2015. All rights reserved.