Class ScopeUtil


  • public final class ScopeUtil
    extends Object
    Contains utility methods for working on scope.
    • Constructor Detail

      • ScopeUtil

        private ScopeUtil()
        Prevent instantiation.
    • Method Detail

      • getDeclaredScopeFromMods

        public static Scope getDeclaredScopeFromMods​(DetailAST aMods)
        Returns the Scope explicitly specified by the modifier set. Returns null if there are no modifiers.
        Parameters:
        aMods - root node of a modifier set
        Returns:
        a Scope value or null
      • getScope

        public static Scope getScope​(DetailAST ast)
        Returns the Scope for a given DetailAST.
        Parameters:
        ast - the DetailAST to examine
        Returns:
        a Scope value
      • getScopeFromMods

        public static Scope getScopeFromMods​(DetailAST aMods)
        Returns the Scope 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(DetailAST)
      • getDefaultScope

        private static Scope getDefaultScope​(DetailAST ast)
        Returns the default Scope for a DetailAST.

        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

        public static Scope getSurroundingScope​(DetailAST node)
        Returns the scope of the surrounding "block".
        Parameters:
        node - the node to return the scope for
        Returns:
        the Scope of the surrounding block
      • isInClassBlock

        public static boolean isInClassBlock​(DetailAST node)
        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

        public static boolean isInRecordBlock​(DetailAST node)
        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

        public static boolean isInInterfaceBlock​(DetailAST node)
        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

        public static boolean isInAnnotationBlock​(DetailAST node)
        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

        private static boolean isInBlockOf​(DetailAST node,
                                           int tokenType)
        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

        public static boolean isInInterfaceOrAnnotationBlock​(DetailAST node)
        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

        public static boolean isInEnumBlock​(DetailAST node)
        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

        public static boolean isInCodeBlock​(DetailAST node)
        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

        public static boolean isOuterMostType​(DetailAST node)
        Returns whether a node is contained in the outermost type block.
        Parameters:
        node - the node to check
        Returns:
        a boolean value
      • isLocalVariableDef

        public static boolean isLocalVariableDef​(DetailAST node)
        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

        public static boolean isClassFieldDef​(DetailAST node)
        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

        public static boolean isInScope​(DetailAST ast,
                                        Scope scope)
        Checks whether ast node is in a specific scope.
        Parameters:
        ast - the node to check.
        scope - a Scope value.
        Returns:
        true if the ast node is in the scope.