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 ScopeReturns theScopeexplicitly specified by the modifier set.private static ScopegetDefaultScope(DetailAST ast) Returns the defaultScopefor aDetailAST.static ScopeReturns theScopefor a givenDetailAST.static ScopegetScopeFromMods(DetailAST aMods) Returns theScopespecified by the modifier set.static ScopegetSurroundingScope(DetailAST node) Returns the scope of the surrounding "block".static booleanisClassFieldDef(DetailAST node) Determines whether a node is a class field definition.static booleanisInAnnotationBlock(DetailAST node) Returns whether a node is directly contained within an annotation block.static booleanisInBlockOf(DetailAST node, int tokenType) Returns whether a node is directly contained within a specified block.static booleanisInClassBlock(DetailAST node) Returns whether a node is directly contained within a class block.static booleanisInCodeBlock(DetailAST node) Returns whether the scope of a node is restricted to a code block.static booleanisInEnumBlock(DetailAST node) Returns whether a node is directly contained within an enum block.static booleanisInInterfaceBlock(DetailAST node) Returns whether a node is directly contained within an interface block.static booleanReturns whether a node is directly contained within an interface or annotation block.static booleanisInRecordBlock(DetailAST node) Returns whether a node is directly contained within a record block.static booleanChecks whether ast node is in a specific scope.static booleanisLocalVariableDef(DetailAST node) Determines whether a node is a local variable definition.static booleanisOuterMostType(DetailAST node) Returns whether a node is contained in the outermost type block.
-
Constructor Details
-
ScopeUtil
private ScopeUtil()Prevent instantiation.
-
-
Method Details
-
getDeclaredScopeFromMods
Returns theScopeexplicitly specified by the modifier set. Returnsnullif there are no modifiers.- Parameters:
aMods- root node of a modifier set- Returns:
- a
Scopevalue ornull
-
getScope
Returns theScopefor a givenDetailAST.- Parameters:
ast- the DetailAST to examine- Returns:
- a
Scopevalue
-
getScopeFromMods
Returns theScopespecified by the modifier set. If no modifiers are present, the default scope is used.- Parameters:
aMods- root node of a modifier set- Returns:
- a
Scopevalue - See Also:
-
getDefaultScope
Returns the defaultScopefor 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
Scopevalue
-
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
booleanvalue
-
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
booleanvalue
-
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
booleanvalue
-
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
booleanvalue
-
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
booleanvalue
-
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
booleanvalue
-
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
booleanvalue
-
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
booleanvalue
-
isOuterMostType
Returns whether a node is contained in the outermost type block.- Parameters:
node- the node to check- Returns:
- a
booleanvalue
-
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- aScopevalue.- Returns:
- true if the ast node is in the scope.
-