Class CodeBlock

  • All Implemented Interfaces:
    ASTNode, Member

    public class CodeBlock
    extends AbstractMember
    A block of code in curly braces in a class.

    This class implements the Member interface because a block can be a member (say, a static block in a class declaration), but usually it's not actually a Member, but something else, e.g. the body of a method, or the content of an if-statement, etc.

    Version:
    1.0
    • Field Detail

      • NAME

        public static final java.lang.String NAME
        The name of all CodeBlocks.
        See Also:
        Constant Field Values
      • children

        private java.util.List<CodeBlock> children
      • isStatic

        private boolean isStatic
    • Constructor Detail

      • CodeBlock

        public CodeBlock​(boolean isStatic,
                         Offset startOffs)
    • Method Detail

      • add

        public void add​(CodeBlock child)
        Adds a child code block to this code block.
        Parameters:
        child - The child code block to add.
        See Also:
        getChildBlock(int)
      • addLocalVariable

        public void addLocalVariable​(LocalVariable localVar)
        Adds a local variable to this code block.
        Parameters:
        localVar - The local variable to add.
        See Also:
        getLocalVar(int)
      • containsOffset

        public boolean containsOffset​(int offs)
        Returns whether this code block contains the specified offset.
        Parameters:
        offs - The offset.
        Returns:
        Whether this code block contains the offset.
      • getChildBlock

        public CodeBlock getChildBlock​(int index)
        Returns the specified child block.
        Parameters:
        index - The index of the child block.
        Returns:
        The child block.
        See Also:
        getChildBlockCount()
      • getChildBlockCount

        public int getChildBlockCount()
      • getDeepestCodeBlockContaining

        public CodeBlock getDeepestCodeBlockContaining​(int offs)
        Returns the deepest code block nested under this one (or this one itself) containing a given offset.
        Parameters:
        offs - The offset to look for.
        Returns:
        The deepest-nested code block containing the offset, or null if this code block and none of its children contain the offset.
      • getDocComment

        public java.lang.String getDocComment()
        Description copied from interface: Member
        Returns the doc comment for this member.
        Returns:
        This member's doc comment.
      • getLocalVar

        public LocalVariable getLocalVar​(int index)
        Returns the specified local variable.
        Parameters:
        index - The index of the variable.
        Returns:
        The local variable.
        See Also:
        getLocalVarCount()
      • getLocalVarCount

        public int getLocalVarCount()
      • getLocalVarsBefore

        public java.util.List<LocalVariable> getLocalVarsBefore​(int offs)
        Returns all local variables declared before a given offset, both in this code block and in all parent blocks.
        Parameters:
        offs - The offset.
        Returns:
        The LocalVariables, or an empty list of none were declared before the offset.
      • getModifiers

        public Modifiers getModifiers()
        Description copied from interface: Member
        Returns the modifiers of this member.
        Returns:
        The modifiers.
      • getType

        public Type getType()
        Returns null, since blocks don't have types.
        Returns:
        null always.
      • isDeprecated

        public boolean isDeprecated()
        Description copied from interface: Member
        Returns whether this member is deprecated.
        Returns:
        Whether this member is deprecated.
      • setParent

        public void setParent​(CodeBlock parent)