类 CodeBlock


  • public class CodeBlock
    extends java.lang.Object
    A block of code. This can be used to implement very simple parsing for languages that have some concept of code blocks, such as C, Perl, Java, etc. Currently, using CodeBlocks provides a means of remembering where variables are defined, as well as their scopes.
    版本:
    1.0
    作者:
    Robert Futrell
    另请参阅:
    VariableDeclaration
    • 构造器详细资料

      • CodeBlock

        public CodeBlock​(int start)
        Constructor.
        参数:
        start - The starting offset of the code block.
    • 方法详细资料

      • addChildCodeBlock

        public CodeBlock addChildCodeBlock​(int start)
        Creates and returns a child (nested) code block.
        参数:
        start - The starting offset of the nested code block.
        返回:
        The code block.
      • addVariable

        public void addVariable​(VariableDeclaration varDec)
        Adds a variable declaration.
        参数:
        varDec - The variable declaration.
      • contains

        public boolean contains​(int offset)
        Returns whether this code block contains a given offset.
        参数:
        offset - The offset.
        返回:
        Whether this code block contains that offset.
      • getChildCodeBlock

        public CodeBlock getChildCodeBlock​(int index)
        Returns a child code block.
        参数:
        index - The index of the child code block.
        返回:
        The child code block.
        另请参阅:
        getChildCodeBlockCount()
      • getChildCodeBlockCount

        public int getChildCodeBlockCount()
        Returns the number of child code blocks.
        返回:
        The child code block count.
        另请参阅:
        getChildCodeBlock(int)
      • getDeepestCodeBlockContaining

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

        public CodeBlock getParent()
        Returns the parent code block.
        返回:
        The parent code block, or null if there isn't one.
      • getStartOffset

        public int getStartOffset()
        Returns the start offset of this code block.
        返回:
        The start offset.
        另请参阅:
        getEndOffset()
      • getVariableDeclarationCount

        public int getVariableDeclarationCount()
        Returns the number of variable declarations in this code block.
        返回:
        The number of variable declarations.
        另请参阅:
        getVariableDeclaration(int)
      • getVariableDeclarationsBefore

        public java.util.List<VariableDeclaration> getVariableDeclarationsBefore​(int offs)
        Returns all local variables declared before a given offset, both in this code block and in all parent blocks.
        参数:
        offs - The offset.
        返回:
        The VariableDeclarations, or an empty list of none were declared before the offset.
      • setEndOffset

        public void setEndOffset​(int end)
        Sets the end offset of this code block.
        参数:
        end - The end offset.
        另请参阅:
        getEndOffset()