edu.ksu.cis.projects.bogor.ast
Class TryCatchStatement

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.ast.Node
      extended by edu.ksu.cis.projects.bogor.ast.Statement
          extended by edu.ksu.cis.projects.bogor.ast.TryCatchStatement
All Implemented Interfaces:
IStatementParent, Disposable, Serializable, Cloneable

public class TryCatchStatement
extends Statement
implements IStatementParent

The try-catch statement AST.

Version:
CVS $Revision: 1.6 $ $Date: 2005/05/06 17:25:17 $
Author:
Robby , Matt Hoosier
See Also:
Serialized Form

Field Summary
protected  ArrayList<String> locals
          Holds the catch local ids.
protected  ArrayList<String> records
          Holds the catch record ids.
protected  Statement stmt
          Holds the statement.
protected  ArrayList<Statement> stmts
          Holds the choose statements.
 
Fields inherited from class edu.ksu.cis.projects.bogor.ast.Node
ILLEGAL_LOCAL_ID_CHAR
 
Constructor Summary
TryCatchStatement(Statement stmt, List<String> recordIds, List<String> localIds, List<? extends Statement> stmts)
          Default constructor.
 
Method Summary
 TryCatchStatement clone()
          Clones this object (deep clone); including location info.
 void dispose()
          Disposes exp and stmt.
 int getCatchCount()
          Gets the number of catches.
 String getCatchLocalId(int index)
          Gets a catch local id at a specified index.
 String getCatchRecordId(int index)
          Gets a catch record id at a specified index.
 Statement getCatchStatement(int index)
          Gets a catch statement at a specified index.
 Statement getTryStatement()
          Gets the try statement.
 void setCatches(List<String> recordIds, List<String> localIds, List<? extends Statement> stmts)
          Sets the catches.
 void setTryStatement(Statement stmt)
          Sets the try statement.
protected  String toString(String indent)
          Returns the string representation of this object.
 void visit(ASTVisitor visitor)
           
 
Methods inherited from class edu.ksu.cis.projects.bogor.ast.Statement
getParent, setParent, toString
 
Methods inherited from class edu.ksu.cis.projects.bogor.ast.Node
getLocationInfo, getProperty, putProperty, setLocationInfo
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stmt

protected Statement stmt
Holds the statement. Must be non-null.


records

protected ArrayList<String> records
Holds the catch record ids. Must be non-null.


locals

protected ArrayList<String> locals
Holds the catch local ids. Must be non-null.


stmts

protected ArrayList<Statement> stmts
Holds the choose statements. Must be non-null.

Constructor Detail

TryCatchStatement

public TryCatchStatement(Statement stmt,
                         List<String> recordIds,
                         List<String> localIds,
                         List<? extends Statement> stmts)
Default constructor. Sets this object as the try stmt's parent. Sets this object as the parent of each of the catch's stmt.

Parameters:
stmt - The try statement. Must be non-null.
recordIds - The catch record ids. Must be non-null. Each element must be non-null. There must be at least one element.
localIds - The catch local ids. Must agree with recordIds
stmts - The catch statements. Must agree with recordIds.
Method Detail

clone

public TryCatchStatement clone()
Clones this object (deep clone); including location info.

Specified by:
clone in class Statement
Returns:
The clone of this object. Non-null.

dispose

public void dispose()
Disposes exp and stmt. Can be called repeatedly. Once called, avoid using this object.

Specified by:
dispose in interface Disposable
Overrides:
dispose in class Statement

getTryStatement

public Statement getTryStatement()
Gets the try statement.

Returns:
The try statement. Non-null.

setTryStatement

public void setTryStatement(Statement stmt)
Sets the try statement. Sets this object as the stmt's parent.

Parameters:
stmt - The try statement. Must be non-null.

setCatches

public void setCatches(List<String> recordIds,
                       List<String> localIds,
                       List<? extends Statement> stmts)
Sets the catches. Sets this object as each of the catch stmt's parent.

Parameters:
recordIds -
localIds -
stmts - The catch statements . Must be non-null. Each element must be non-null. Should be the same size as recordIds.

getCatchRecordId

public String getCatchRecordId(int index)
Gets a catch record id at a specified index.

Parameters:
index - The index of the the catch record id. Must be between 0 and getCatchCount() - 1, inclusive.
Returns:
The catch record id at the given index. Non-null.

getCatchLocalId

public String getCatchLocalId(int index)
Gets a catch local id at a specified index.

Parameters:
index - The index of the the catch local id. Must be between 0 and getCatchCount() - 1, inclusive.
Returns:
The catch local id at the given index. Non-null.

getCatchStatement

public Statement getCatchStatement(int index)
Gets a catch statement at a specified index.

Parameters:
index - The index of the the catch statement. Must be between 0 and getCatchCount() - 1, inclusive.
Returns:
The catch statement at the given index. Non-null.

getCatchCount

public int getCatchCount()
Gets the number of catches.

Returns:
The number of catches.

visit

public void visit(ASTVisitor visitor)
Specified by:
visit in class Node

toString

protected String toString(String indent)
Returns the string representation of this object.

Specified by:
toString in class Statement
Parameters:
indent - The indentation for this statement.
Returns:
 
  
   
    
     
                       "try\n" + 
                       "    stmt\n" + 
                       "catch (record-id1 local-id1)\n" + 
                       "    stmt1\n" + 
                       "catch (record-id2 local-id2)\n" + 
                       "    stmt2\n" + 
                       "..." + 
                       "catch (record-idN local-idN)\n" + 
                       "    stmtN\n" + 
                       "end\n".