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 Details

  • Constructor Details

    • CodeBlock

      public CodeBlock(boolean isStatic, Offset startOffs)
  • Method Details

    • 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:
    • addLocalVariable

      public void addLocalVariable(LocalVariable localVar)
      Adds a local variable to this code block.
      Parameters:
      localVar - The local variable to add.
      See Also:
    • 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

      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 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

      public int getLocalVarCount()
    • getLocalVarsBefore

      public 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.
    • getParent

      public CodeBlock getParent()
    • 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.
    • isStatic

      public boolean isStatic()
      Returns whether this block is a static block (in a class declaration).
      Specified by:
      isStatic in interface Member
      Overrides:
      isStatic in class AbstractMember
      Returns:
      Whether this is a static code block.
      See Also:
    • setParent

      public void setParent(CodeBlock parent)