com.borland.jbuilder.jot
Interface JotCodeBlock

All Superinterfaces:
JotCommentable, JotMarker, JotSourceElement, JotStatement
All Known Subinterfaces:
JotInitBlock

public interface JotCodeBlock
extends JotCommentable, JotMarker, JotStatement

This interface represents a code block. See section 14.2 in the Java Language Specification for more information.


Method Summary
 JotAssignment addAssignment(JotMarker marker, boolean before, java.lang.String variableName, java.lang.String value)
          Creates a JotAssignment object and adds it to the code block.
 JotDo addDoStatement(JotMarker marker, boolean before, java.lang.String condition)
          Creates a JotDo object with the given condition and adds it to the code block.
 JotFor addForStatement(JotMarker marker, boolean before, java.lang.String condition)
          Creates a JotFor object and adds it to the code block.
 JotIf addIfStatement(JotMarker marker, boolean before, java.lang.String condition)
          Creates a JotIf object with the given condition and adds it to the code block.
 JotIf addIfStatement(JotMarker marker, boolean before, java.lang.String condition, boolean hasElse)
          Creates a JotIf object with the given condition and adds it to the code block.
 JotInnerClass addInnerClass(JotMarker marker, boolean before, java.lang.String name)
          Adds an inner class to the code block and returns an instance of JotInnerClass that represents the class.
 JotMethodCall addMethodCall(JotMarker marker, boolean before, java.lang.String methodName, java.lang.String parameters)
          Creates a JotMethodCall object and adds it to the code block.
 JotReturn addReturnStatement(JotMarker marker, boolean before, java.lang.String expression)
          Creates a JotReturn object with the given expression and adds it to the code block.
 JotStatement addStatement(JotMarker marker, boolean before, boolean semi, java.lang.String text)
          Creates the appropriate JotStatement object from the specified text.
 JotStatement addStatement(JotMarker marker, boolean before, java.lang.String text)
          Creates the appropriate JotStatement object from the specified text.
 JotTry addTryStatement(JotMarker marker, boolean before, java.lang.String[] catches, boolean hasFinally)
          Creates a JotTry object and adds it to the code block.
 JotTry addTryStatement(JotMarker marker, boolean before, java.lang.String type, java.lang.String varName)
          Creates a JotTry object and adds it to the code block.
 JotVariableDeclaration addVariableDeclaration(JotMarker marker, boolean before, java.lang.String variableType, java.lang.String variableName)
          Creates a JotVariableDeclaration object and adds it to the code block.
 JotWhile addWhileStatement(JotMarker marker, boolean before, java.lang.String condition)
          Creates a JotWhile object with the given condition and adds it to the code block.
 JotAssignment[] getAssignments()
          Returns an array containing all the assignment expressions in this code block.
 int getComparableLocation(JotMarker m)
          Returns a value that can be used to determine the order of statements in this code block.
 JotClass[] getDeclaredInnerClasses()
          Returns an array of JotClass objects reflecting all inner classes defined in this code block.
 JotMethodCall getMethodCall(java.lang.String methodName)
          Returns the first method call in this code block that matches the specified method name.
 JotMethodCall[] getMethodCalls()
          Returns an array containing all the method call statements in this code block.
 JotMethodCall[] getMethodCalls(java.lang.String methodName)
          Returns an array containing all the method call statements in this code block that match the specified method name.
 JotStatement[] getStatements()
          Returns an array containing all of the statements contained by this code block.
 JotVariableDeclaration getVariableDeclaration(java.lang.String name)
          Returns the JotVariableDeclaration object that represents the declaration of the specified variable.
 JotVariableDeclaration[] getVariableDeclarations()
          Returns an array containing all the variable declarations in this block.
 void removeAssignment(JotAssignment assignment)
          Removes the specified assignment expression from this code block.
 void removeInnerClass(JotInnerClass inner)
          Removes the specified inner class from the class.
 void removeMethodCall(JotMethodCall mc)
          Removes the specified method call from this code block.
 void removeStatement(JotStatement s)
          Removes the specified statement object from this code block.
 void removeVariableDeclaration(JotVariableDeclaration declaration)
          Removes the specified declaration from this code block.
 
Methods inherited from interface com.borland.jbuilder.jot.JotCommentable
addBlankLine, addComment, getComment, removeComment
 
Methods inherited from interface com.borland.jbuilder.jot.JotMarker
addUserData, getEndPosition, getStartPosition, getUserData
 
Methods inherited from interface com.borland.jbuilder.jot.JotStatement
getCodeBlock
 
Methods inherited from interface com.borland.jbuilder.jot.JotSourceElement
getIndentLevel, getParent, getText, isModified, setModified, setText
 

Method Detail

getStatements

public JotStatement[] getStatements()
Returns an array containing all of the statements contained by this code block. The array does not contain statements that are substatements of statements in this block. If there are no statements in this block, then a zero-length array is returned.
Specified by:
getStatements in interface JotStatement

addStatement

public JotStatement addStatement(JotMarker marker,
                                 boolean before,
                                 java.lang.String text)
Creates the appropriate JotStatement object from the specified text. The text will be terminated by a semicolon if necessary. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
text - is the body of the statement being added

addStatement

public JotStatement addStatement(JotMarker marker,
                                 boolean before,
                                 boolean semi,
                                 java.lang.String text)
Creates the appropriate JotStatement object from the specified text. If semi is true, then a semicolon will be appending to the end of the statement. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
semi - controls if a semi-colon is to be placed at the end of the statement by JOT. true adds a semi-colon, false does not.
text - is the body of the statement being added

addReturnStatement

public JotReturn addReturnStatement(JotMarker marker,
                                    boolean before,
                                    java.lang.String expression)
Creates a JotReturn object with the given expression and adds it to the code block. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
expression - is the expression in the return statement. JOT will add the keyword return and the trailing semi-colon to the expression.

addIfStatement

public JotIf addIfStatement(JotMarker marker,
                            boolean before,
                            java.lang.String condition)
Creates a JotIf object with the given condition and adds it to the code block. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
condition - is condition inside the parenthesis of the if statement.

addIfStatement

public JotIf addIfStatement(JotMarker marker,
                            boolean before,
                            java.lang.String condition,
                            boolean hasElse)
Creates a JotIf object with the given condition and adds it to the code block. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before. If hasElse is true then the statement will have an else part.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
condition - is condition inside the parenthesis of the if statement.
hasElse - will generate an empty else statement if set to true.

addDoStatement

public JotDo addDoStatement(JotMarker marker,
                            boolean before,
                            java.lang.String condition)
Creates a JotDo object with the given condition and adds it to the code block. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
condition - is condition in the while portion of the do-while loop.

addWhileStatement

public JotWhile addWhileStatement(JotMarker marker,
                                  boolean before,
                                  java.lang.String condition)
Creates a JotWhile object with the given condition and adds it to the code block. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
condition - is condition for the while statement

addForStatement

public JotFor addForStatement(JotMarker marker,
                              boolean before,
                              java.lang.String condition)
Creates a JotFor object and adds it to the code block. The new statement will have the parameters specified by condition. For example, the condition int i=0; i<n; i++ would create the statement

   for (int i=0; i<n; i++) {
   }
 
If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
condition - is for the expressions that control the for statement

addTryStatement

public JotTry addTryStatement(JotMarker marker,
                              boolean before,
                              java.lang.String type,
                              java.lang.String varName)
Creates a JotTry object and adds it to the code block. The new try block will contain a catch block that declares an expection variable of the given type and name. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
type - is the exception being caught
varName - is the variable name to be used for the exception

addTryStatement

public JotTry addTryStatement(JotMarker marker,
                              boolean before,
                              java.lang.String[] catches,
                              boolean hasFinally)
Creates a JotTry object and adds it to the code block. The new try block will have catch blocks for the exceptions specified in catches. If the length of catches is 0, then no catch blocks will be added. If hasFinally is true, then a finally block will also be added. If marker is non-null, then the statement will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
catches - is an array of Exceptions to be caught
hasFinally - controls if a finally clause is added. A value of true will generate a finally clause

removeStatement

public void removeStatement(JotStatement s)
Removes the specified statement object from this code block. If the statement isn't in this block, this does nothing.

getVariableDeclaration

public JotVariableDeclaration getVariableDeclaration(java.lang.String name)
Returns the JotVariableDeclaration object that represents the declaration of the specified variable. If the variable is not declared in this block, then returns null.

getVariableDeclarations

public JotVariableDeclaration[] getVariableDeclarations()
Returns an array containing all the variable declarations in this block. If there are no variable declarations in this block, returns a zero-length array.

addVariableDeclaration

public JotVariableDeclaration addVariableDeclaration(JotMarker marker,
                                                     boolean before,
                                                     java.lang.String variableType,
                                                     java.lang.String variableName)
Creates a JotVariableDeclaration object and adds it to the code block. The new variable will have the specified name and type. If marker is non-null, then the declaration will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
variableType - The data type for the variable being declared.
variableName - The name to use for the variable being declared.

removeVariableDeclaration

public void removeVariableDeclaration(JotVariableDeclaration declaration)
Removes the specified declaration from this code block. If the declaration isn't in this block, then does nothing.

getMethodCalls

public JotMethodCall[] getMethodCalls()
Returns an array containing all the method call statements in this code block. Nested method calls are represented by one entry for the outer-most method call. If no method calls are in this code block, then returns a zero-length array.

getMethodCalls

public JotMethodCall[] getMethodCalls(java.lang.String methodName)
Returns an array containing all the method call statements in this code block that match the specified method name. In the case of nested method calls, only the outer-most call is matched. If no matching method calls are in this code block, then returns a zero-length array.

getMethodCall

public JotMethodCall getMethodCall(java.lang.String methodName)
Returns the first method call in this code block that matches the specified method name. In the case of nested method calls, only the outer-most call is matched. If no matching method calls are in this code block, then returns null.

addMethodCall

public JotMethodCall addMethodCall(JotMarker marker,
                                   boolean before,
                                   java.lang.String methodName,
                                   java.lang.String parameters)
Creates a JotMethodCall object and adds it to the code block. The new call will have the specified method name and parameters. The method name may include a variable reference and/or nested method call, e.g. obj.getClass().getName. If marker is non-null, then the call will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
methodName - The name to use for the method being added.
parameters - The parameter list for the method being added.

removeMethodCall

public void removeMethodCall(JotMethodCall mc)
Removes the specified method call from this code block. If the call isn't in this block, then does nothing.

getAssignments

public JotAssignment[] getAssignments()
Returns an array containing all the assignment expressions in this code block. An expression containing nested assignments will only be returned if the outer-most expression is an assignment. If there are no assignments in the code block, then a zero-length array is returned.

addAssignment

public JotAssignment addAssignment(JotMarker marker,
                                   boolean before,
                                   java.lang.String variableName,
                                   java.lang.String value)
Creates a JotAssignment object and adds it to the code block. The new expression will have the specified variable name and value. If marker is non-null, then the call will be inserted in the code block either before or after the marker depending on the value of before.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
variableName - The name of the variable being assigned.
value - The value or expression for the RHS of the assignment.

removeAssignment

public void removeAssignment(JotAssignment assignment)
Removes the specified assignment expression from this code block. If the expression isn't in this block, then does nothing.

getDeclaredInnerClasses

public JotClass[] getDeclaredInnerClasses()
Returns an array of JotClass objects reflecting all inner classes defined in this code block.

addInnerClass

public JotInnerClass addInnerClass(JotMarker marker,
                                   boolean before,
                                   java.lang.String name)
Adds an inner class to the code block and returns an instance of JotInnerClass that represents the class. If 'marker' is not null, then the field will be inserted in the class either before or after the marker depending on the value of 'before'.

Parameters:
marker - the Jot object relative to which the code is being added
before - controls where, relative to the marker, code will be added. true places the statement before the marker false places the statement after the marker.
name - The name of the inner class.

removeInnerClass

public void removeInnerClass(JotInnerClass inner)
Removes the specified inner class from the class.

getComparableLocation

public int getComparableLocation(JotMarker m)
Returns a value that can be used to determine the order of statements in this code block. When comparing two statements in the code block, the value returned for the statement that comes first will be less than the value returned for the other.