Package org.fife.rsta.ac.common
Class CodeBlock
- java.lang.Object
-
- org.fife.rsta.ac.common.CodeBlock
-
public class CodeBlock extends java.lang.ObjectA 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, usingCodeBlocks provides a means of remembering where variables are defined, as well as their scopes.- Version:
- 1.0
- See Also:
VariableDeclaration
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<CodeBlock>childrenprivate intendprivate CodeBlockparentprivate intstartprivate java.util.List<VariableDeclaration>varDeclarations
-
Constructor Summary
Constructors Constructor Description CodeBlock(int start)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CodeBlockaddChildCodeBlock(int start)Creates and returns a child (nested) code block.voidaddVariable(VariableDeclaration varDec)Adds a variable declaration.booleancontains(int offset)Returns whether this code block contains a given offset.CodeBlockgetChildCodeBlock(int index)Returns a child code block.intgetChildCodeBlockCount()Returns the number of child code blocks.CodeBlockgetDeepestCodeBlockContaining(int offs)Returns the deepest code block nested under this one (or this one itself) containing a given offset.intgetEndOffset()Returns the end offset of this code block.CodeBlockgetParent()Returns the parent code block.intgetStartOffset()Returns the start offset of this code block.VariableDeclarationgetVariableDeclaration(int index)Returns a variable declaration.intgetVariableDeclarationCount()Returns the number of variable declarations in this code block.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.voidsetEndOffset(int end)Sets the end offset of this code block.
-
-
-
Field Detail
-
start
private int start
-
end
private int end
-
parent
private CodeBlock parent
-
children
private java.util.List<CodeBlock> children
-
varDeclarations
private java.util.List<VariableDeclaration> varDeclarations
-
-
Method Detail
-
addChildCodeBlock
public CodeBlock addChildCodeBlock(int start)
Creates and returns a child (nested) code block.- Parameters:
start- The starting offset of the nested code block.- Returns:
- The code block.
-
addVariable
public void addVariable(VariableDeclaration varDec)
Adds a variable declaration.- Parameters:
varDec- The variable declaration.
-
contains
public boolean contains(int offset)
Returns whether this code block contains a given offset.- Parameters:
offset- The offset.- Returns:
- Whether this code block contains that offset.
-
getChildCodeBlock
public CodeBlock getChildCodeBlock(int index)
Returns a child code block.- Parameters:
index- The index of the child code block.- Returns:
- The child code block.
- See Also:
getChildCodeBlockCount()
-
getChildCodeBlockCount
public int getChildCodeBlockCount()
Returns the number of child code blocks.- Returns:
- The child code block count.
- See Also:
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.- Parameters:
offs- The offset to look for.- Returns:
- The deepest-nested code block containing the offset, or
nullif this code block and none of its children contain the offset.
-
getEndOffset
public int getEndOffset()
Returns the end offset of this code block.- Returns:
- The end offset.
- See Also:
getStartOffset(),setEndOffset(int)
-
getParent
public CodeBlock getParent()
Returns the parent code block.- Returns:
- The parent code block, or
nullif there isn't one.
-
getStartOffset
public int getStartOffset()
Returns the start offset of this code block.- Returns:
- The start offset.
- See Also:
getEndOffset()
-
getVariableDeclaration
public VariableDeclaration getVariableDeclaration(int index)
Returns a variable declaration.- Parameters:
index- The index of the declaration.- Returns:
- The declaration.
- See Also:
getVariableDeclarationCount()
-
getVariableDeclarationCount
public int getVariableDeclarationCount()
Returns the number of variable declarations in this code block.- Returns:
- The number of variable declarations.
- See Also:
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.- Parameters:
offs- The offset.- Returns:
- 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.- Parameters:
end- The end offset.- See Also:
getEndOffset()
-
-