Class CheckUtils
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.utils.CheckUtils
-
public final class CheckUtils extends java.lang.Object
Contains utility methods for the checks.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BASE_10
Decimal radix.private static int
BASE_16
Hex radix.private static int
BASE_8
Octal radix.private static int
GETTER_BODY_SIZE
Maximum nodes allowed in a body of getter.private static java.util.regex.Pattern
GETTER_PATTERN
Pattern matching names of getter methods.private static int
SETTER_BODY_SIZE
Maximum nodes allowed in a body of setter.private static int
SETTER_GETTER_MAX_CHILDREN
Maximum children allowed in setter/getter.private static java.util.regex.Pattern
SETTER_PATTERN
Pattern matching names of setter methods.private static java.util.regex.Pattern
UNDERSCORE_PATTERN
Pattern matching underscore characters ('_').
-
Constructor Summary
Constructors Modifier Constructor Description private
CheckUtils()
Prevent instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FullIdent
createFullType(DetailAST typeAST)
CreatesFullIdent
for given type node.private static FullIdent
createFullTypeNoArrays(DetailAST typeAST)
Returns FullIndent for given type.static AccessModifier
getAccessModifierFromModifiersToken(DetailAST modifiersToken)
ReturnsAccessModifier
based on the information about access modifier taken from the given token of typeTokenTypes.MODIFIERS
.static DetailAST
getFirstNode(DetailAST node)
Finds sub-node for given node minimal (line, column) pair.static java.util.List<java.lang.String>
getTypeParameterNames(DetailAST node)
Retrieves the names of the type parameters to the node.static java.util.List<DetailAST>
getTypeParameters(DetailAST node)
Retrieves the type parameters to the node.private static boolean
isElse(DetailAST ast)
Returns whether a token represents an ELSE.static boolean
isElseIf(DetailAST ast)
Returns whether a token represents an ELSE as part of an ELSE / IF set.private static boolean
isElseWithCurlyBraces(DetailAST ast)
Returns whether a token represents an SLIST as part of an ELSE statement.static boolean
isEqualsMethod(DetailAST ast)
Tests whether a method definition AST defines an equals covariant.static boolean
isGetterMethod(DetailAST ast)
Returns whether an AST represents a getter method.static boolean
isNonVoidMethod(DetailAST methodDefAst)
Checks whether a method is a not void one.static boolean
isReceiverParameter(DetailAST parameterDefAst)
Checks whether a parameter is a receiver.static boolean
isSetterMethod(DetailAST ast)
Returns whether an AST represents a setter method.static double
parseDouble(java.lang.String text, int type)
Returns the value represented by the specified string of the specified type.private static int
parseInt(java.lang.String text, int radix)
Parses the string argument as a signed integer in the radix specified by the second argument.private static long
parseLong(java.lang.String text, int radix)
Parses the string argument as a signed long in the radix specified by the second argument.
-
-
-
Field Detail
-
BASE_8
private static final int BASE_8
Octal radix.- See Also:
- Constant Field Values
-
BASE_10
private static final int BASE_10
Decimal radix.- See Also:
- Constant Field Values
-
BASE_16
private static final int BASE_16
Hex radix.- See Also:
- Constant Field Values
-
SETTER_GETTER_MAX_CHILDREN
private static final int SETTER_GETTER_MAX_CHILDREN
Maximum children allowed in setter/getter.- See Also:
- Constant Field Values
-
SETTER_BODY_SIZE
private static final int SETTER_BODY_SIZE
Maximum nodes allowed in a body of setter.- See Also:
- Constant Field Values
-
GETTER_BODY_SIZE
private static final int GETTER_BODY_SIZE
Maximum nodes allowed in a body of getter.- See Also:
- Constant Field Values
-
UNDERSCORE_PATTERN
private static final java.util.regex.Pattern UNDERSCORE_PATTERN
Pattern matching underscore characters ('_').
-
SETTER_PATTERN
private static final java.util.regex.Pattern SETTER_PATTERN
Pattern matching names of setter methods.
-
GETTER_PATTERN
private static final java.util.regex.Pattern GETTER_PATTERN
Pattern matching names of getter methods.
-
-
Method Detail
-
createFullType
public static FullIdent createFullType(DetailAST typeAST)
CreatesFullIdent
for given type node.- Parameters:
typeAST
- a type node.- Returns:
FullIdent
for given type.
-
isEqualsMethod
public static boolean isEqualsMethod(DetailAST ast)
Tests whether a method definition AST defines an equals covariant.- Parameters:
ast
- the method definition AST to test. Precondition: ast is a TokenTypes.METHOD_DEF node.- Returns:
- true if ast defines an equals covariant.
-
isElseIf
public static boolean isElseIf(DetailAST ast)
Returns whether a token represents an ELSE as part of an ELSE / IF set.- Parameters:
ast
- the token to check- Returns:
- whether it is
-
isElse
private static boolean isElse(DetailAST ast)
Returns whether a token represents an ELSE.- Parameters:
ast
- the token to check- Returns:
- whether the token represents an ELSE
-
isElseWithCurlyBraces
private static boolean isElseWithCurlyBraces(DetailAST ast)
Returns whether a token represents an SLIST as part of an ELSE statement.- Parameters:
ast
- the token to check- Returns:
- whether the toke does represent an SLIST as part of an ELSE
-
createFullTypeNoArrays
private static FullIdent createFullTypeNoArrays(DetailAST typeAST)
Returns FullIndent for given type.- Parameters:
typeAST
- a type node (no array)- Returns:
FullIdent
for given type.
-
parseDouble
public static double parseDouble(java.lang.String text, int type)
Returns the value represented by the specified string of the specified type. Returns 0 for types other than float, double, int, and long.- Parameters:
text
- the string to be parsed.type
- the token type of the text. Should be a constant ofTokenTypes
.- Returns:
- the double value represented by the string argument.
-
parseInt
private static int parseInt(java.lang.String text, int radix)
Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix. Handles negative values, which method java.lang.Integer.parseInt(String, int) does not.- Parameters:
text
- the String containing the integer representation to be parsed. Precondition: text contains a parsable int.radix
- the radix to be used while parsing text.- Returns:
- the integer represented by the string argument in the specified radix.
-
parseLong
private static long parseLong(java.lang.String text, int radix)
Parses the string argument as a signed long in the radix specified by the second argument. The characters in the string must all be digits of the specified radix. Handles negative values, which method java.lang.Integer.parseInt(String, int) does not.- Parameters:
text
- the String containing the integer representation to be parsed. Precondition: text contains a parsable int.radix
- the radix to be used while parsing text.- Returns:
- the long represented by the string argument in the specified radix.
-
getFirstNode
public static DetailAST getFirstNode(DetailAST node)
Finds sub-node for given node minimal (line, column) pair.- Parameters:
node
- the root of tree for search.- Returns:
- sub-node with minimal (line, column) pair.
-
getTypeParameterNames
public static java.util.List<java.lang.String> getTypeParameterNames(DetailAST node)
Retrieves the names of the type parameters to the node.- Parameters:
node
- the parameterized AST node- Returns:
- a list of type parameter names
-
getTypeParameters
public static java.util.List<DetailAST> getTypeParameters(DetailAST node)
Retrieves the type parameters to the node.- Parameters:
node
- the parameterized AST node- Returns:
- a list of type parameter names
-
isSetterMethod
public static boolean isSetterMethod(DetailAST ast)
Returns whether an AST represents a setter method.- Parameters:
ast
- the AST to check with- Returns:
- whether the AST represents a setter method
-
isGetterMethod
public static boolean isGetterMethod(DetailAST ast)
Returns whether an AST represents a getter method.- Parameters:
ast
- the AST to check with- Returns:
- whether the AST represents a getter method
-
isNonVoidMethod
public static boolean isNonVoidMethod(DetailAST methodDefAst)
Checks whether a method is a not void one.- Parameters:
methodDefAst
- the method node.- Returns:
- true if method is a not void one.
-
isReceiverParameter
public static boolean isReceiverParameter(DetailAST parameterDefAst)
Checks whether a parameter is a receiver.- Parameters:
parameterDefAst
- the parameter node.- Returns:
- true if the parameter is a receiver.
-
getAccessModifierFromModifiersToken
public static AccessModifier getAccessModifierFromModifiersToken(DetailAST modifiersToken)
ReturnsAccessModifier
based on the information about access modifier taken from the given token of typeTokenTypes.MODIFIERS
.- Parameters:
modifiersToken
- token of typeTokenTypes.MODIFIERS
.- Returns:
AccessModifier
.
-
-