类 CodeBlock
- java.lang.Object
-
- org.meteoinfo.laboratory.codecomplete.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.- 版本:
- 1.0
- 作者:
- Robert Futrell
- 另请参阅:
VariableDeclaration
-
-
构造器概要
构造器 构造器 说明 CodeBlock(int start)Constructor.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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.
-
-
-
方法详细资料
-
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
nullif this code block and none of its children contain the offset.
-
getEndOffset
public int getEndOffset()
Returns the end offset of this code block.- 返回:
- The end offset.
- 另请参阅:
getStartOffset(),setEndOffset(int)
-
getParent
public CodeBlock getParent()
Returns the parent code block.- 返回:
- The parent code block, or
nullif there isn't one.
-
getStartOffset
public int getStartOffset()
Returns the start offset of this code block.- 返回:
- The start offset.
- 另请参阅:
getEndOffset()
-
getVariableDeclaration
public VariableDeclaration getVariableDeclaration(int index)
Returns a variable declaration.- 参数:
index- The index of the declaration.- 返回:
- The declaration.
- 另请参阅:
getVariableDeclarationCount()
-
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()
-
-