org.fife.rsta.ac.java.rjc.ast
Class CodeBlock

java.lang.Object
  extended by org.fife.rsta.ac.java.rjc.ast.CodeBlock
All Implemented Interfaces:
ASTNode, Member

public class CodeBlock
extends Object

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
Author:
Robert Futrell

Field Summary
static String NAME
          The name of all CodeBlocks.
 
Constructor Summary
CodeBlock(boolean isStatic, Offset startOffs)
           
 
Method Summary
 void add(CodeBlock child)
           
 void addLocalVariable(LocalVariable localVar)
           
 boolean containsOffset(int offs)
           
 CodeBlock getChildBlock(int index)
           
 int getChildBlockCount()
           
 CodeBlock getDeepestCodeBlockContaining(int offs)
          Returns the deepest code block nested under this one (or this one itself) containing a given offset.
 String getDocComment()
           
 LocalVariable getLocalVar(int index)
           
 int getLocalVarCount()
           
 List getLocalVarsBefore(int offs)
          Returns all local variables declared before a given offset, both in this code block and in all parent blocks.
 Modifiers getModifiers()
          Always returns an empty modifiers instance, since blocks don't have modifiers.
 String getName()
          Returns the "name" of this node.
 int getNameEndOffset()
          Returns the end offset of the "name" of this node.
 int getNameStartOffset()
          Returns the start offset of the "name" of this node.
 CodeBlock getParent()
           
 TypeDeclaration getParentTypeDeclaration()
           
 Type getType()
          Returns null, since blocks don't have types.
 boolean isDeprecated()
           
 boolean isStatic()
          Returns whether this block is a static block (in a class declaration).
 void setDeclarationEndOffset(Offset end)
           
protected  void setDeclarationOffsets(Offset start, Offset end)
          Sets the start and end offsets of this node.
 void setParent(CodeBlock parent)
           
 void setParentTypeDeclaration(TypeDeclaration dec)
          
 String toString()
          Returns the name of this node (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.fife.rsta.ac.java.rjc.ast.Member
getName, getNameEndOffset, getNameStartOffset
 

Field Detail

NAME

public static final String NAME
The name of all CodeBlocks.

See Also:
Constant Field Values
Constructor Detail

CodeBlock

public CodeBlock(boolean isStatic,
                 Offset startOffs)
Method Detail

add

public void add(CodeBlock child)

addLocalVariable

public void addLocalVariable(LocalVariable localVar)

containsOffset

public boolean containsOffset(int offs)

getChildBlock

public CodeBlock getChildBlock(int index)

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

getLocalVar

public LocalVariable getLocalVar(int index)

getLocalVarCount

public int getLocalVarCount()

getLocalVarsBefore

public List 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()
Always returns an empty modifiers instance, since blocks don't have modifiers.

Returns:
An empty modifiers instance.

getParent

public CodeBlock getParent()

getType

public Type getType()
Returns null, since blocks don't have types.

Returns:
null always.

isDeprecated

public boolean isDeprecated()

isStatic

public boolean isStatic()
Returns whether this block is a static block (in a class declaration).

Returns:
Whether this is a static code block.

setParent

public void setParent(CodeBlock parent)

getParentTypeDeclaration

public TypeDeclaration getParentTypeDeclaration()
Specified by:
getParentTypeDeclaration in interface Member

setParentTypeDeclaration

public void setParentTypeDeclaration(TypeDeclaration dec)

Specified by:
setParentTypeDeclaration in interface Member

getName

public String getName()
Returns the "name" of this node. This will be the name of the method, the name of the member or local variable, etc. For CodeBlocks it will be NAME.

Note that this may not be unique. For example, a class with an overloaded method will have multiple methods with the same "name," just with different signatures.

Specified by:
getName in interface ASTNode
Returns:
The "name" of this node.

getNameEndOffset

public int getNameEndOffset()
Returns the end offset of the "name" of this node.

Specified by:
getNameEndOffset in interface ASTNode
Returns:
The end offset.

getNameStartOffset

public int getNameStartOffset()
Returns the start offset of the "name" of this node.

Specified by:
getNameStartOffset in interface ASTNode
Returns:
The start offset.

setDeclarationEndOffset

public void setDeclarationEndOffset(Offset end)

setDeclarationOffsets

protected void setDeclarationOffsets(Offset start,
                                     Offset end)
Sets the start and end offsets of this node.

Parameters:
start - The start offset.
end - The end offset.

toString

public String toString()
Returns the name of this node (e.g. the value of getName()). Subclasses can override this method if appropriate.

Overrides:
toString in class Object
Returns:
A string representation of this node.


Copyright © 2003-2011. All Rights Reserved.