public class GenericWhitespaceCheck extends AbstractCheck
Checks that the whitespace around the Generic tokens (angle brackets) "<" and ">" are correct to the typical convention. The convention is not configurable.
Left angle bracket ("<"):
Right angle bracket (">"):
To configure the check:
<module name="GenericWhitespace"/>
Examples with correct spacing:
// Generic methods definitions public void <K, V extends Number> boolean foo(K, V) {} // Generic type definition class name<T1, T2, ..., Tn> {} // Generic type reference OrderedPair<String, Box<Integer>> p; // Generic preceded method name boolean same = Util.<Integer, String>compare(p1, p2); // Diamond operator Pair<Integer, String> p1 = new Pair<>(1, "apple"); // Method reference List<T> list = ImmutableList.Builder<T>::new; // Method reference sort(list, Comparable::<String>compareTo); // Constructor call MyClass obj = new <String>MyClass();
Examples with incorrect spacing:
List< String> l; // violation, "<" followed by whitespace Box b = Box. <String>of("foo"); // violation, "<" preceded with whitespace public<T> void foo() {} // violation, "<" not preceded with whitespace List a = new ArrayList<> (); // violation, ">" followed by whitespace Map<Integer, String>m; // violation, ">" not followed by whitespace Pair<Integer, Integer > p; // violation, ">" preceded with whitespace
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
ws.followed
ws.illegalFollow
ws.notPreceded
ws.preceded
AutomaticBean.OutputStreamOptions
Modifier and Type | Field and Description |
---|---|
static String |
MSG_WS_FOLLOWED
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_WS_ILLEGAL_FOLLOW
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_WS_NOT_PRECEDED
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_WS_PRECEDED
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
GenericWhitespaceCheck() |
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 |
visitToken(DetailAST ast)
Called to process a token.
|
clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final String MSG_WS_PRECEDED
public static final String MSG_WS_FOLLOWED
public static final String MSG_WS_NOT_PRECEDED
public static final String MSG_WS_ILLEGAL_FOLLOW
public GenericWhitespaceCheck()
public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void beginTree(DetailAST rootAST)
AbstractCheck
beginTree
in class AbstractCheck
rootAST
- the root of the treepublic void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processCopyright © 2001–2020. All rights reserved.