Class ScopeUtil
java.lang.Object
com.puppycrawl.tools.checkstyle.utils.ScopeUtil
Contains utility methods for working on scope.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Scope
Returns theScope
explicitly specified by the modifier set.private static Scope
getDefaultScope
(DetailAST ast) Returns the defaultScope
for aDetailAST
.static Scope
Returns theScope
for a givenDetailAST
.static Scope
getScopeFromMods
(DetailAST aMods) Returns theScope
specified by the modifier set.static Scope
getSurroundingScope
(DetailAST node) Returns the scope of the surrounding "block".static boolean
isClassFieldDef
(DetailAST node) Determines whether a node is a class field definition.static boolean
isInAnnotationBlock
(DetailAST node) Returns whether a node is directly contained within an annotation block.private static boolean
isInBlockOf
(DetailAST node, int tokenType) Returns whether a node is directly contained within a specified block.static boolean
isInClassBlock
(DetailAST node) Returns whether a node is directly contained within a class block.static boolean
isInCodeBlock
(DetailAST node) Returns whether the scope of a node is restricted to a code block.static boolean
isInEnumBlock
(DetailAST node) Returns whether a node is directly contained within an enum block.static boolean
isInInterfaceBlock
(DetailAST node) Returns whether a node is directly contained within an interface block.static boolean
Returns whether a node is directly contained within an interface or annotation block.static boolean
isInRecordBlock
(DetailAST node) Returns whether a node is directly contained within a record block.static boolean
Checks whether ast node is in a specific scope.static boolean
isLocalVariableDef
(DetailAST node) Determines whether a node is a local variable definition.static boolean
isOuterMostType
(DetailAST node) Returns whether a node is contained in the outermost type block.
-
Constructor Details
-
ScopeUtil
private ScopeUtil()Prevent instantiation.
-
-
Method Details
-
getDeclaredScopeFromMods
Returns theScope
explicitly specified by the modifier set. Returnsnull
if there are no modifiers.- Parameters:
aMods
- root node of a modifier set- Returns:
- a
Scope
value ornull
-
getScope
Returns theScope
for a givenDetailAST
.- Parameters:
ast
- the DetailAST to examine- Returns:
- a
Scope
value
-
getScopeFromMods
Returns theScope
specified by the modifier set. If no modifiers are present, the default scope is used.- Parameters:
aMods
- root node of a modifier set- Returns:
- a
Scope
value - See Also:
-
getDefaultScope
Returns the defaultScope
for aDetailAST
.The following rules are taken into account:
- enum constants are public
- enum constructors are private
- interface members are public
- everything else is package private
- Parameters:
ast
- DetailAST to process- Returns:
- a
Scope
value
-
getSurroundingScope
Returns the scope of the surrounding "block".- Parameters:
node
- the node to return the scope for- Returns:
- the Scope of the surrounding block
-
isInClassBlock
Returns whether a node is directly contained within a class block.- Parameters:
node
- the node to check if directly contained within a class block.- Returns:
- a
boolean
value
-
isInRecordBlock
Returns whether a node is directly contained within a record block.- Parameters:
node
- the node to check if directly contained within a record block.- Returns:
- a
boolean
value
-
isInInterfaceBlock
Returns whether a node is directly contained within an interface block.- Parameters:
node
- the node to check if directly contained within an interface block.- Returns:
- a
boolean
value
-
isInAnnotationBlock
Returns whether a node is directly contained within an annotation block.- Parameters:
node
- the node to check if directly contained within an annotation block.- Returns:
- a
boolean
value
-
isInBlockOf
Returns whether a node is directly contained within a specified block.- Parameters:
node
- the node to check if directly contained within a specified block.tokenType
- type of token.- Returns:
- a
boolean
value
-
isInInterfaceOrAnnotationBlock
Returns whether a node is directly contained within an interface or annotation block.- Parameters:
node
- the node to check if directly contained within an interface or annotation block.- Returns:
- a
boolean
value
-
isInEnumBlock
Returns whether a node is directly contained within an enum block.- Parameters:
node
- the node to check if directly contained within an enum block.- Returns:
- a
boolean
value
-
isInCodeBlock
Returns whether the scope of a node is restricted to a code block. A code block is a method or constructor body, an initializer block, or lambda body.- Parameters:
node
- the node to check- Returns:
- a
boolean
value
-
isOuterMostType
Returns whether a node is contained in the outermost type block.- Parameters:
node
- the node to check- Returns:
- a
boolean
value
-
isLocalVariableDef
Determines whether a node is a local variable definition. I.e. if it is declared in a code block, a for initializer, or a catch parameter.- Parameters:
node
- the node to check.- Returns:
- whether aAST is a local variable definition.
-
isClassFieldDef
Determines whether a node is a class field definition. I.e. if a variable is not declared in a code block, a for initializer, or a catch parameter.- Parameters:
node
- the node to check.- Returns:
- whether a node is a class field definition.
-
isInScope
Checks whether ast node is in a specific scope.- Parameters:
ast
- the node to check.scope
- aScope
value.- Returns:
- true if the ast node is in the scope.
-