Class CheckUtil
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.utils.CheckUtil
-
public final class CheckUtil extends java.lang.Object
Contains utility methods for the checks.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FullIdent
createFullType(DetailAST typeAST)
CreatesFullIdent
for given type node.static AccessModifierOption
getAccessModifierFromModifiersToken(DetailAST modifiersToken)
ReturnsAccessModifierOption
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.static boolean
isBeforeInSource(DetailAST ast1, DetailAST ast2)
Retrieves whether ast1 is located before ast2.static boolean
isElseIf(DetailAST ast)
Returns whether a token represents an ELSE as part of an ELSE / IF set.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 java.util.Set<java.lang.String>
parseClassNames(java.lang.String... classNames)
Create set of class names and short class names.static double
parseDouble(java.lang.String text, int type)
Returns the value represented by the specified string of the specified type.static java.lang.String
stripIndentAndInitialNewLineFromTextBlock(java.lang.String textBlockContent)
Strip initial newline and preceding whitespace on each line from text block content.
-
-
-
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
-
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.
-
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.
-
isBeforeInSource
public static boolean isBeforeInSource(DetailAST ast1, DetailAST ast2)
Retrieves whether ast1 is located before ast2.- Parameters:
ast1
- the first node.ast2
- the second node.- Returns:
- true, if ast1 is located before ast2.
-
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 AccessModifierOption getAccessModifierFromModifiersToken(DetailAST modifiersToken)
ReturnsAccessModifierOption
based on the information about access modifier taken from the given token of typeTokenTypes.MODIFIERS
.- Parameters:
modifiersToken
- token of typeTokenTypes.MODIFIERS
.- Returns:
AccessModifierOption
.- Throws:
java.lang.IllegalArgumentException
- when expected non-null modifiersToken with type 'MODIFIERS'
-
parseClassNames
public static java.util.Set<java.lang.String> parseClassNames(java.lang.String... classNames)
Create set of class names and short class names.- Parameters:
classNames
- array of class names.- Returns:
- set of class names and short class names.
-
stripIndentAndInitialNewLineFromTextBlock
public static java.lang.String stripIndentAndInitialNewLineFromTextBlock(java.lang.String textBlockContent)
Strip initial newline and preceding whitespace on each line from text block content. In order to be consistent with how javac handles this task, we have modeled this implementation after the code from: github.com/openjdk/jdk14u/blob/master/src/java.base/share/classes/java/lang/String.java- Parameters:
textBlockContent
- the actual content of the text block.- Returns:
- string consistent with javac representation.
-
-