public class RecordComponentNumberCheck extends AbstractCheck
Checks the number of record components in the header of a record definition.
max - Specify the maximum number of components allowed in the header of a
record definition.
Type is int.
Default value is 8.
accessModifiers - Access modifiers of record definitions where
the number of record components should be checked.
Type is com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption[].
Default value is public, protected, package, private.
To configure the check:
<module name="RecordComponentNumber"/>
Java code example:
public record MyRecord1(int x, int y) { // ok, 2 components
...
}
record MyRecord2(int x, int y, String str,
Node node, Order order, Data data
String location, Date date, Image image) { // violation, 9 components
...
}
To configure the check to allow 5 record components at all access modifier levels for record definitions:
<module name="RecordComponentNumber"> <property name="max" value="5"/> </module>
Java code example:
public record MyRecord1(int x, int y, String str) { // ok, 3 components
...
}
public record MyRecord2(int x, int y, String str,
Node node, Order order, Data data) { // violation, 6 components
...
}
To configure the check to allow 10 record components for a public record definition, but 3 for private record definitions:
<module name="RecordComponentNumber"> <property name="max" value="3"/> <property name="accessModifiers" value="private"/> </module> <module name="RecordComponentNumber"> <property name="max" value="10"/> <property name="accessModifiers" value="public"/> </module>
Java code example:
public record MyRecord1(int x, int y, String str) { // ok, public record definition allowed 10
...
}
private record MyRecord2(int x, int y, String str, Node node) { // violation
... // private record definition allowed 3 components
}
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
too.many.components
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
RecordComponentNumberCheck() |
| 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 |
setAccessModifiers(AccessModifierOption... accessModifiers)
Setter to access modifiers of record definitions where the number of record
components should be checked.
|
void |
setMax(int value)
Setter to specify the maximum number of components allowed in the header
of a record definition.
|
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 java.lang.String MSG_KEY
public RecordComponentNumberCheck()
public void setMax(int value)
value - the maximum allowed.public void setAccessModifiers(AccessModifierOption... accessModifiers)
accessModifiers - access modifiers of record definitions which should be checked.public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processCopyright © 2001-2020. All Rights Reserved.