Package org.fife.rsta.ac.js.ast
Class CodeBlock
java.lang.Object
org.fife.rsta.ac.js.ast.CodeBlock
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.- Version:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate CodeBlockprivate intprivate List<JavaScriptVariableDeclaration> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddChildCodeBlock(int start) Creates and returns a child (nested) code block.voidAdds a variable declaration.booleancontains(int offset) Returns whether this code block contains a given offset.voiddebug()getChildCodeBlock(int index) Returns a child code block.intReturns the number of child code blocks.intReturns the end offset of this code block.Returns the parent code block.intReturns the start offset of this code block.getVariableDeclaration(int index) Returns a variable declaration.intReturns the number of variable declarations in this code block.private voidoutputChild(StringBuilder sb, CodeBlock block, int tab) voidsetEndOffset(int end) Sets the end offset of this code block.voidsetStartOffSet(int start) Sets the start offset of this code block.
-
Field Details
-
start
private int start -
end
private int end -
parent
-
children
-
varDeclarations
-
-
Constructor Details
-
CodeBlock
public CodeBlock(int start) Constructor.- Parameters:
start- The starting offset of the code block.
-
-
Method Details
-
addChildCodeBlock
Creates and returns a child (nested) code block.- Parameters:
start- The starting offset of the nested code block.- Returns:
- The code block.
-
addVariable
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
Returns a child code block.- Parameters:
index- The index of the child code block.- Returns:
- The child code block.
- See Also:
-
getChildCodeBlockCount
public int getChildCodeBlockCount()Returns the number of child code blocks.- Returns:
- The child code block count.
- See Also:
-
getEndOffset
public int getEndOffset()Returns the end offset of this code block.- Returns:
- The end offset.
- See Also:
-
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:
-
getVariableDeclaration
Returns a variable declaration.- Parameters:
index- The index of the declaration.- Returns:
- The declaration.
- See Also:
-
getVariableDeclarationCount
public int getVariableDeclarationCount()Returns the number of variable declarations in this code block.- Returns:
- The number of variable declarations.
- See Also:
-
setEndOffset
public void setEndOffset(int end) Sets the end offset of this code block.- Parameters:
end- The end offset.- See Also:
-
setStartOffSet
public void setStartOffSet(int start) Sets the start offset of this code block.- Parameters:
start- the start offset- See Also:
-
debug
public void debug() -
outputChild
-