Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

oracle.jdeveloper.java.util
Class SourceUtils

java.lang.Object
  extended by oracle.jdeveloper.java.util.SourceUtils

public class SourceUtils
extends java.lang.Object

This is a collection of utilities for making changes to the Java parser v2 source model.


Constructor Summary
SourceUtils()
           
 
Method Summary
static SourceStatement addAssignStatement(SourceBlock block, java.lang.String lhsName, SourceExpression rhsExpr)
          Adds (append) an assignment statement (=) to the block.
static SourceStatement addAssignStatement(SourceBlock block, java.lang.String lhsName, java.lang.String rhsText)
          Adds (append) an assignment statement (=) to the block.
static void addBlankLine(SourceBlock block)
          Adds (append) a blank line to the block.
static void addBlankLine(SourceClassBody body)
          Adds (append) a blank line to the block.
static void addBlankLine(SourceElement block, boolean before)
          Adds (append) a blank line before or after a source element.
static SourceCatchClause addCatchClause(SourceTryStatement tryStmt, java.lang.String catchType, java.lang.String catchName, SourceBlock catchBlock)
          Adds a catch clause to the block, usin gthe given catch info.
static SourceClass addClass(SourceFile file, java.lang.String name, int modifiers)
          Adds (append) a class to the file.
static SourceMethod addConstructor(SourceClass cls, int modifiers)
          Adds a constructor to the class.
static SourceDocComment addDocComment(SourceMember member, java.lang.String descText)
          Sets the Javadoc comment for the given member (class, method, field, ...).
static SourceDocTag addDocTag(SourceDocComment comment, java.lang.String tagNameText, java.lang.String tagText)
          Adds a doc tag to the given doc comment
static SourceStatement addExpressionStatement(SourceBlock block, SourceExpression expr)
          Adds (append) an expression as a statement to the block.
static SourceStatement addExpressionStatement(SourceBlock block, SourceExpression expr, SourceElement sibling, boolean before)
          Inserts an expression as a statement to the block by the specified sibling.
static SourceStatement addExpressionStatement(SourceBlock block, java.lang.String exprText)
          Adds (append) an expression as a statement to the block.
static SourceStatement addExpressionStatement(SourceBlock block, java.lang.String exprText, SourceElement sibling, boolean before)
          Inserts an expression as a statement to the block by the specified sibling.
static SourceFieldDeclaration addField(SourceClass cls, java.lang.String type, java.lang.String name, int modifiers, java.lang.String initText)
          Adds a field to the class with the given type, modifiers, and initializer text.
static SourceFinallyClause addFinallyClause(SourceTryStatement tryStmt, SourceBlock finallyBlock)
          Adds a finally clause to the try statement, using the given block
static SourceIfStatement addIfElseStatement(SourceBlock block, java.lang.String condition, SourceBlock ifBlock, SourceBlock elseBlock)
          Adds an if/else statement to the block, using the given condition and if/else blocks.
static SourceIfStatement addIfStatement(SourceBlock block, java.lang.String condition, SourceBlock ifBlock)
          Adds an if statement to the block, using the given condition and if block.
static void addImport(SourceFile file, java.lang.String importName)
          Adds an import to the file.
static SourceClass addInterface(SourceFile file, java.lang.String name, int modifiers)
          Adds (append) an interface to the file.
static void addLineComment(SourceBlock block, java.lang.String commentText)
          Adds (append) a line comment to the block.
static void addLineComment(SourceClassBody block, java.lang.String commentText)
          Adds (append) a line comment to the block.
static void addLineComment(SourceElement element, boolean before, java.lang.String commentText)
          Adds a line comment before or after a source element.
static SourceVariableDeclaration addLocalVariableDeclaration(SourceBlock block, java.lang.String type, java.lang.String name, SourceExpression initExpr)
          Adds (append) a local variable declaration to the given block.
static SourceVariableDeclaration addLocalVariableDeclaration(SourceBlock block, java.lang.String type, java.lang.String name, java.lang.String initText)
          Adds (append) a local variable declaration to the given block.
static SourceMethod addMainMethod(SourceClass cls)
          Adds (append) a "public static void main( String[] args )" method to the class.
static SourceMember addMember(SourceClass cls, SourceMember member, SourceMember sibling, boolean before)
          Inserts a member into the class by the specified sibling.
static SourceMethod addMethod(SourceClass cls, java.lang.String type, java.lang.String name, int modifiers)
          Adds (append) a method to the class.
static SourceMethod addMethod(SourceClass cls, java.lang.String type, java.lang.String name, int modifiers, SourceMember sibling, boolean before)
          Inserts a method into the class by the specified sibling.
static SourceStatement addMethodCallStatement(SourceBlock block, java.lang.String lhs, java.lang.String methodName, SourceExpression[] args)
          Adds a method call invocation as a statement to the block.
static SourceStatement addMethodCallStatement(SourceBlock block, java.lang.String lhs, java.lang.String methodName, java.lang.String[] args)
          Adds a method call invocation as a statement to the block.
static SourceLocalVariable addMethodParameter(SourceMethod method, java.lang.String type, java.lang.String name)
          Adds (append) a parameter to the method.
static SourceStatement addReturn(SourceBlock block, java.lang.String stmtText)
          Adds (append) a return statement to the given block.
static SourceStatement addStatement(SourceBlock block, SourceStatement stmt, SourceElement sibling, boolean before)
          Inserts a statement to the block by the specified sibling.
static SourceStatement addStatement(SourceBlock block, java.lang.String stmtText)
          Adds (append) a statement to the block.
static SourceClassInitializer addStaticClassInitializer(SourceClass cls, SourceBlock block)
          Adds (append) a static class initializer to the class.
static void addSuperInterface(SourceClass cls, java.lang.String fqName)
          Adds the given super interface to the specified class or interface.
static SourceSwitchLabel addSwitchCaseLabel(SourceBlock switchBlock, java.lang.String caseText)
          Add a case label to a switch block.
static SourceSwitchStatement addSwitchStatement(SourceBlock block, java.lang.String switchText, SourceBlock switchBlock)
          Add a switch statement to the block.
static void addThrows(SourceMethod method, java.lang.String throwName)
          Adds a (class) type to the throws clause of the method declaration.
static SourceThrowStatement addThrowStatement(SourceBlock block, java.lang.String throwText)
          Adds a throw statement to the block, using the given throw text.
static SourceTryStatement addTryCatchStatement(SourceBlock block, SourceBlock tryBlock, java.lang.String catchType, java.lang.String catchName, SourceBlock catchBlock)
          Adds a try/catch statement to the block, using the given catch text.
static SourceWhileStatement addWhileStatement(SourceBlock block, java.lang.String condition, SourceBlock whileBlock)
          Adds a while statement to the block, using the given condition and while block.
static SourceExpression createAssign(SourceBlock block, java.lang.String lhsName, java.lang.String rhsText)
          Adds (append) an assignment statement (=) to the block.
static SourceBlock createBlock(SourceElement element)
          Create a new empty block.
static SourceMethod createConstructor(SourceClass cls, int modifiers)
          Creates a new constructor.
static SourceFieldDeclaration createField(SourceClass cls, java.lang.String fieldText)
          Creates a field to the class with the given text.
static SourceFieldDeclaration createField(SourceClass cls, java.lang.String fieldText, int modifiers)
          Creates a field to the class with the given text, sets the given modifiers on the result.
static SourceFieldDeclaration createField(SourceClass cls, java.lang.String type, java.lang.String name, int modifiers, java.lang.String initText)
          Creates a field to the class with the given type, modifiers, and initializer text.
static SourceLocalVariable createLocalVariable(SourceFile file, java.lang.String type, java.lang.String name)
          Creates a new local variable of the given type and name.
static SourceMethod createMainMethod(SourceClass cls)
          Creates a "public static void main( String[] args )" method.
static SourceMethod createMethod(SourceClass cls, java.lang.String type, java.lang.String name, int modifiers)
          Constructs a new method.
static SourceExpression createMethodCall(SourceBlock block, java.lang.String lhs, java.lang.String methodName, SourceExpression[] args)
          Creates an expression that is a method invocation.
static SourceExpression createMethodCall(SourceBlock block, java.lang.String lhs, java.lang.String methodName, java.lang.String[] args)
          Creates an expression that is a method invocation.
static SourceStatement createReturn(SourceBlock block, java.lang.String stmtText)
          Creates a return statement.
static SourceTryStatement createTryCatchStatement(SourceBlock block, SourceBlock tryBlock, java.lang.String catchType, java.lang.String catchName, SourceBlock catchBlock)
          Creates a try/catch statement to the block, using the given catch text.
static SourceMethod getDefaultConstructor(SourceClass cls)
          Fetch the default constructor for this class.
static SourceFactory getFactory(SourceElement element)
          Fetch a factory from the element.
static SourceBlock getFinallyBlock(SourceTryStatement tryStatement)
          Fetch the SourceBlock for the finally clause of a try-finally.
static SourceMethod getMainMethod(SourceClass cls)
          Find the main method in the cls.
static SourceMethod getMethod(SourceClass cls, java.lang.String name, java.lang.String[] paramTypes)
          Find the method in the cls with the given name and parameter types.
static SourceVariable getMethodParameter(SourceMethod method, int index)
          Fetch a parameter from the method.
static JavaType getType(JavaProvider provider, java.lang.String type)
          Fetch a JavaType instance for the given type.
static void removeThrows(SourceMethod method, java.lang.String throwName)
          Removes a class (type) from the throws clause of the method declaration.
static void setSuperclass(SourceClass cls, java.lang.String fqName)
          Set the super class for the given class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceUtils

public SourceUtils()
Method Detail

addImport

public static void addImport(SourceFile file,
                             java.lang.String importName)
Adds an import to the file. Note that explicitly adding imports to the SourceFile is not required if clients specify fully-qualified type names when adding to the Source* model. The parser will automatically add the appropriate import and trim the package-prefix from the fully-qualified type name


addLineComment

public static void addLineComment(SourceBlock block,
                                  java.lang.String commentText)
Adds (append) a line comment to the block.

Parameters:
commentText - should include the contents of the comment, minus the initial // line comment token

addLineComment

public static void addLineComment(SourceClassBody block,
                                  java.lang.String commentText)
Adds (append) a line comment to the block.

Parameters:
commentText - should include the contents of the comment, minus the initial // line comment token

addLineComment

public static void addLineComment(SourceElement element,
                                  boolean before,
                                  java.lang.String commentText)
Adds a line comment before or after a source element.

Parameters:
commentText - shoudl include the contents of the comment, minus the initial // line comment token

addBlankLine

public static void addBlankLine(SourceBlock block)
Adds (append) a blank line to the block.


addBlankLine

public static void addBlankLine(SourceClassBody body)
Adds (append) a blank line to the block.


addBlankLine

public static void addBlankLine(SourceElement block,
                                boolean before)
Adds (append) a blank line before or after a source element.


addClass

public static SourceClass addClass(SourceFile file,
                                   java.lang.String name,
                                   int modifiers)
Adds (append) a class to the file.

Parameters:
name - the name of the class
modifiers - the modifiers to set on the class
Returns:
the SourceClass corresponding to the newly added class

addInterface

public static SourceClass addInterface(SourceFile file,
                                       java.lang.String name,
                                       int modifiers)
Adds (append) an interface to the file.

Parameters:
name - the name of the interface
modifiers - the modifiers to set on the interface
Returns:
the SourceClass corresponding to the newly added interface

setSuperclass

public static void setSuperclass(SourceClass cls,
                                 java.lang.String fqName)
Set the super class for the given class

Parameters:
fqName - the fully-qualified class name

addSuperInterface

public static void addSuperInterface(SourceClass cls,
                                     java.lang.String fqName)
Adds the given super interface to the specified class or interface.

Parameters:
fqName - the name of the interface to add as a super interface

addConstructor

public static SourceMethod addConstructor(SourceClass cls,
                                          int modifiers)
Adds a constructor to the class. This will attempt to add constructor to the top of the class.

Parameters:
modifiers - the modifiers for the constructor
Returns:
the SourceMethod corresponding to the newly added constructor

getDefaultConstructor

public static SourceMethod getDefaultConstructor(SourceClass cls)
Fetch the default constructor for this class.

Returns:
the default constructor for the class, or null if it can't be found

addMethod

public static SourceMethod addMethod(SourceClass cls,
                                     java.lang.String type,
                                     java.lang.String name,
                                     int modifiers)
Adds (append) a method to the class.

Parameters:
type - the fully-qualified type for the method return type
name - the name of the method
modifiers - the modifiers for the method
Returns:
the SourceMethod corresponding to the newly added method

addMethod

public static SourceMethod addMethod(SourceClass cls,
                                     java.lang.String type,
                                     java.lang.String name,
                                     int modifiers,
                                     SourceMember sibling,
                                     boolean before)
Inserts a method into the class by the specified sibling. If the sibling is null, then an append is performed.

Parameters:
type - the fully-qualified type for the method return type
name - the name of the method
modifiers - the modifiers for the method
sibling - the sibling element to insert relative to
before - true to insert before the sibling, false for after
Returns:
the SourceMethod corresponding to the newly added method

addMember

public static SourceMember addMember(SourceClass cls,
                                     SourceMember member,
                                     SourceMember sibling,
                                     boolean before)
Inserts a member into the class by the specified sibling. If the sibling is null, then it is added to the top if before is true, to the bottom if before is false.

Parameters:
member - the member to add
sibling - the sibling element to insert relative to
before - true to insert before the sibling, false for after
Returns:
the SourceMember that was just added

createMethod

public static SourceMethod createMethod(SourceClass cls,
                                        java.lang.String type,
                                        java.lang.String name,
                                        int modifiers)
Constructs a new method.

Parameters:
type - the fully-qualified tyep for the method return type
name - the name of the method
modifiers - the modifiers for the method
Returns:
the newly created SourceMethod

createConstructor

public static SourceMethod createConstructor(SourceClass cls,
                                             int modifiers)
Creates a new constructor.

Parameters:
modifiers - the modifiers for the constructor
Returns:
the SourceMethod corresponding to the newly created constructor

addThrows

public static void addThrows(SourceMethod method,
                             java.lang.String throwName)
Adds a (class) type to the throws clause of the method declaration.

Parameters:
throwName - the fully-qualified class name to add

removeThrows

public static void removeThrows(SourceMethod method,
                                java.lang.String throwName)
Removes a class (type) from the throws clause of the method declaration.

Parameters:
throwName - the fully-qualified class name to remove

addMainMethod

public static SourceMethod addMainMethod(SourceClass cls)
Adds (append) a "public static void main( String[] args )" method to the class.


createMainMethod

public static SourceMethod createMainMethod(SourceClass cls)
Creates a "public static void main( String[] args )" method.

Returns:
the main method that is ready to be added to a class

getMainMethod

public static SourceMethod getMainMethod(SourceClass cls)
Find the main method in the cls.


getMethod

public static SourceMethod getMethod(SourceClass cls,
                                     java.lang.String name,
                                     java.lang.String[] paramTypes)
Find the method in the cls with the given name and parameter types.

Parameters:
name - the name of the method to find
paramTypes - the fully-qualified parameter types of the method

getType

public static JavaType getType(JavaProvider provider,
                               java.lang.String type)
Fetch a JavaType instance for the given type.

Parameters:
provider - the provider to use
type - the fully-qualified type name (class, array, primitive)

addMethodParameter

public static SourceLocalVariable addMethodParameter(SourceMethod method,
                                                     java.lang.String type,
                                                     java.lang.String name)
Adds (append) a parameter to the method.

Parameters:
type - the fully-qualified type for the parameter
name - the name of the parameter
Returns:
the SourceLocalVariable representing the newly added parameter

addStaticClassInitializer

public static SourceClassInitializer addStaticClassInitializer(SourceClass cls,
                                                               SourceBlock block)
Adds (append) a static class initializer to the class.

Parameters:
block - the block to use for the initializer

addDocComment

public static SourceDocComment addDocComment(SourceMember member,
                                             java.lang.String descText)
Sets the Javadoc comment for the given member (class, method, field, ...). If a description is specified, adds it to the comment.

Parameters:
descText - the description to use (if any)
Returns:
the newly added SourceDocComment instance

addDocTag

public static SourceDocTag addDocTag(SourceDocComment comment,
                                     java.lang.String tagNameText,
                                     java.lang.String tagText)
Adds a doc tag to the given doc comment

Parameters:
tagNameText - the tag name, such as "see"
tagText - the tag text, such as "java.lang.String"

addField

public static SourceFieldDeclaration addField(SourceClass cls,
                                              java.lang.String type,
                                              java.lang.String name,
                                              int modifiers,
                                              java.lang.String initText)
Adds a field to the class with the given type, modifiers, and initializer text.

Parameters:
type - the fully-qualified type name, such as "java.lang.String"
name - the name of the field
modifiers - the modifiers for the field
initText - the expression text for the initializer, or null for none
Returns:
the SourceFieldDeclaration corresponding to the newly added field declaration

createField

public static SourceFieldDeclaration createField(SourceClass cls,
                                                 java.lang.String type,
                                                 java.lang.String name,
                                                 int modifiers,
                                                 java.lang.String initText)
Creates a field to the class with the given type, modifiers, and initializer text.

Parameters:
type - the fully-qualified type name, such as "java.lang.String"
name - the name of the field
modifiers - the modifiers for the field
initText - the expression text for the initializer, or null for none
Returns:
the newly created SourceFieldDeclaration

createField

public static SourceFieldDeclaration createField(SourceClass cls,
                                                 java.lang.String fieldText,
                                                 int modifiers)
Creates a field to the class with the given text, sets the given modifiers on the result.

Parameters:
fieldText - the full text of the field, including the trailing semicolon
modifiers - the modifiers for the field
Returns:
the newly created SourceFieldDeclaration

createField

public static SourceFieldDeclaration createField(SourceClass cls,
                                                 java.lang.String fieldText)
Creates a field to the class with the given text.

Parameters:
fieldText - the full text of the field, including the trailing semicolon
Returns:
the newly created SourceFieldDeclaration

createLocalVariable

public static SourceLocalVariable createLocalVariable(SourceFile file,
                                                      java.lang.String type,
                                                      java.lang.String name)
Creates a new local variable of the given type and name.

Parameters:
type - the fully-qualified class or primitivetype
name - the name of the method parameter or local variable
Returns:
the newly created variable

addLocalVariableDeclaration

public static SourceVariableDeclaration addLocalVariableDeclaration(SourceBlock block,
                                                                    java.lang.String type,
                                                                    java.lang.String name,
                                                                    java.lang.String initText)
Adds (append) a local variable declaration to the given block.

Parameters:
type - the fully-qualified class or primitive type
name - the name of the local variable
initText - the initializer text, or null for none
Returns:
the newly created declaration

addLocalVariableDeclaration

public static SourceVariableDeclaration addLocalVariableDeclaration(SourceBlock block,
                                                                    java.lang.String type,
                                                                    java.lang.String name,
                                                                    SourceExpression initExpr)
Adds (append) a local variable declaration to the given block.

Parameters:
type - the fully-qualified class or primitive type
name - the name of the local variable
initExpr - the initializer expression, or null for none
Returns:
the newly created declaration

createMethodCall

public static SourceExpression createMethodCall(SourceBlock block,
                                                java.lang.String lhs,
                                                java.lang.String methodName,
                                                java.lang.String[] args)
Creates an expression that is a method invocation.

Parameters:
lhs - the expression text for the left-hand side, or null if there is none
methodName - the name of the method being invoked
args - the arguments for the method call, or null for none
Returns:
the method invocation expression

createMethodCall

public static SourceExpression createMethodCall(SourceBlock block,
                                                java.lang.String lhs,
                                                java.lang.String methodName,
                                                SourceExpression[] args)
Creates an expression that is a method invocation.

Parameters:
lhs - the expressionn text for the left-hand side, or null if there is none
methodName - the name of the method being invoked
args - the arguments for the method call, or null for none
Returns:
the method invocation expression

addMethodCallStatement

public static SourceStatement addMethodCallStatement(SourceBlock block,
                                                     java.lang.String lhs,
                                                     java.lang.String methodName,
                                                     java.lang.String[] args)
Adds a method call invocation as a statement to the block.

Parameters:
lhs - the expressionn text for the left-hand side, or null if there is none
methodName - the name of the method being invoked
args - the arguments for the method call, or null for none
Returns:
the statement containing the method invocation

addMethodCallStatement

public static SourceStatement addMethodCallStatement(SourceBlock block,
                                                     java.lang.String lhs,
                                                     java.lang.String methodName,
                                                     SourceExpression[] args)
Adds a method call invocation as a statement to the block.

Parameters:
lhs - the expressionn text for the left-hand side, or null if there is none
methodName - the name of the method being invoked
args - the arguments for the method call, or null for none
Returns:
the statement containing the method invocation

createAssign

public static SourceExpression createAssign(SourceBlock block,
                                            java.lang.String lhsName,
                                            java.lang.String rhsText)
Adds (append) an assignment statement (=) to the block.

Parameters:
lhsName - the lhs name, like a variable or field name
rhsText - the rhs expression, like a method call expression
Returns:
the statement containing the assignment expression

addAssignStatement

public static SourceStatement addAssignStatement(SourceBlock block,
                                                 java.lang.String lhsName,
                                                 java.lang.String rhsText)
Adds (append) an assignment statement (=) to the block.

Parameters:
lhsName - the lhs name, like a variable or field name
rhsText - the rhs expression text, like a method call expression
Returns:
the statement containing the assignment expression

addAssignStatement

public static SourceStatement addAssignStatement(SourceBlock block,
                                                 java.lang.String lhsName,
                                                 SourceExpression rhsExpr)
Adds (append) an assignment statement (=) to the block.

Parameters:
lhsName - the lhs name, like a variable or field name
rhsExpr - the rhs expression, like a method call expression
Returns:
the statement containing the assignment expression

addExpressionStatement

public static SourceStatement addExpressionStatement(SourceBlock block,
                                                     java.lang.String exprText)
Adds (append) an expression as a statement to the block.

Parameters:
exprText - the expression text to add to the block as a statement
Returns:
the statement containing the expression

addExpressionStatement

public static SourceStatement addExpressionStatement(SourceBlock block,
                                                     SourceExpression expr)
Adds (append) an expression as a statement to the block.

Parameters:
expr - the expression to add to the block as a statement
Returns:
the statement containing the expression

addStatement

public static SourceStatement addStatement(SourceBlock block,
                                           java.lang.String stmtText)
Adds (append) a statement to the block.

Parameters:
stmtText - the statement text to add to the block
Returns:
the statement that was added

addExpressionStatement

public static SourceStatement addExpressionStatement(SourceBlock block,
                                                     java.lang.String exprText,
                                                     SourceElement sibling,
                                                     boolean before)
Inserts an expression as a statement to the block by the specified sibling. If the sibling is null, then the expression is added at the top if before is true, at the bottom otherwise.

Parameters:
exprText - the expression text to insert
sibling - the sibling element to insert relative to
before - true to insert before the sibling, false for after

addExpressionStatement

public static SourceStatement addExpressionStatement(SourceBlock block,
                                                     SourceExpression expr,
                                                     SourceElement sibling,
                                                     boolean before)
Inserts an expression as a statement to the block by the specified sibling. If the sibling is null, then the expression is added at the top if before is true, at the bottom otherwise.

Parameters:
expr - the expression to insert
sibling - the sibling element to insert relative to
before - true to insert before the sibling, false for after

addStatement

public static SourceStatement addStatement(SourceBlock block,
                                           SourceStatement stmt,
                                           SourceElement sibling,
                                           boolean before)
Inserts a statement to the block by the specified sibling. If the sibling is null, then the statement is added at the top of the block, at the bottom otherwise.

Parameters:
stmt - the statement to insert
sibling - the sibling element to insert relative to
true - to insert before the sibling, false for after

addIfStatement

public static SourceIfStatement addIfStatement(SourceBlock block,
                                               java.lang.String condition,
                                               SourceBlock ifBlock)
Adds an if statement to the block, using the given condition and if block.

Parameters:
condition - the expression text for the if condition
ifBlock - the block to use for the if
Returns:
the statement containing the if

addWhileStatement

public static SourceWhileStatement addWhileStatement(SourceBlock block,
                                                     java.lang.String condition,
                                                     SourceBlock whileBlock)
Adds a while statement to the block, using the given condition and while block.

Parameters:
condition - the expression text for the while condition
whileBlock - the block to use for the while
Returns:
the statement containing the while

addIfElseStatement

public static SourceIfStatement addIfElseStatement(SourceBlock block,
                                                   java.lang.String condition,
                                                   SourceBlock ifBlock,
                                                   SourceBlock elseBlock)
Adds an if/else statement to the block, using the given condition and if/else blocks.

Parameters:
condition - the expression text for the if condition
ifBlock - the block to use for the if
elseBlock - the block to use for the else
Returns:
the statement containing the if/else

addReturn

public static SourceStatement addReturn(SourceBlock block,
                                        java.lang.String stmtText)
Adds (append) a return statement to the given block.

Parameters:
stmtText - should have the return contents minus the actual return keyword and the trailing semicolon

createReturn

public static SourceStatement createReturn(SourceBlock block,
                                           java.lang.String stmtText)
Creates a return statement.

Parameters:
stmtText - should have the return contents minus the actual return keyword and the trailing semicolon

addThrowStatement

public static SourceThrowStatement addThrowStatement(SourceBlock block,
                                                     java.lang.String throwText)
Adds a throw statement to the block, using the given throw text.

Parameters:
throwText - the throw text, such as "new Exception()"

addSwitchStatement

public static SourceSwitchStatement addSwitchStatement(SourceBlock block,
                                                       java.lang.String switchText,
                                                       SourceBlock switchBlock)
Add a switch statement to the block.

Parameters:
switchText - the text for the switch parens
switchBlock - the block for the switch statement

addSwitchCaseLabel

public static SourceSwitchLabel addSwitchCaseLabel(SourceBlock switchBlock,
                                                   java.lang.String caseText)
Add a case label to a switch block.

Parameters:
caseText - the text for the case label

addTryCatchStatement

public static SourceTryStatement addTryCatchStatement(SourceBlock block,
                                                      SourceBlock tryBlock,
                                                      java.lang.String catchType,
                                                      java.lang.String catchName,
                                                      SourceBlock catchBlock)
Adds a try/catch statement to the block, using the given catch text.

Parameters:
block - the block to add the try/catch to
tryBlock - the block for the try
catchType - the catch parameter type, such as "IOException"
catchName - the catch parameter name, such as "e"
catchBlock - the block for the catch
Returns:
the statement for the try/catch

getFinallyBlock

public static SourceBlock getFinallyBlock(SourceTryStatement tryStatement)
Fetch the SourceBlock for the finally clause of a try-finally. Returns null if there is no finally clause.


addFinallyClause

public static SourceFinallyClause addFinallyClause(SourceTryStatement tryStmt,
                                                   SourceBlock finallyBlock)
Adds a finally clause to the try statement, using the given block


addCatchClause

public static SourceCatchClause addCatchClause(SourceTryStatement tryStmt,
                                               java.lang.String catchType,
                                               java.lang.String catchName,
                                               SourceBlock catchBlock)
Adds a catch clause to the block, usin gthe given catch info.

Parameters:
tryStmt - the try statement to add to
catchType - the catch parameter type, such as "IOException"
catchName - the catch parameter name, such as "e"
catchBlock - the block for the catch
Returns:
the newly added SourceCatchClause

createTryCatchStatement

public static SourceTryStatement createTryCatchStatement(SourceBlock block,
                                                         SourceBlock tryBlock,
                                                         java.lang.String catchType,
                                                         java.lang.String catchName,
                                                         SourceBlock catchBlock)
Creates a try/catch statement to the block, using the given catch text.

Parameters:
block - the block to add the try/catch to
tryBlock - the block for the try
catchType - the catch parameter type, such as "IOException"
catchName - the catch parameter name, such as "e"
catchBlock - the block for the catch
Returns:
the newly created statement for the try/catch

getMethodParameter

public static SourceVariable getMethodParameter(SourceMethod method,
                                                int index)
Fetch a parameter from the method.

Parameters:
index - the parameter index (0-based) to fetch
Returns:
the requested parameter, or null if there is no such parameter

getFactory

public static SourceFactory getFactory(SourceElement element)
Fetch a factory from the element. This is a convenience routine.


createBlock

public static SourceBlock createBlock(SourceElement element)
Create a new empty block. The element is specified only to fetch a factory from the SourceFile containing the given element. This is a convenience routine.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

Copyright © 1997, 2011, Oracle. All rights reserved.