org.mule.devkit.model.code
Class GeneratedBlock

java.lang.Object
  extended by org.mule.devkit.model.code.GeneratedBlock
All Implemented Interfaces:
Generable, Statement

public final class GeneratedBlock
extends Object
implements Generable, Statement

A block of Java code, which may contain statements and local declarations.

GeneratedBlock contains a large number of factory methods that creates new statements/declarations. Those newly created statements/declarations are inserted into the "current position". The position advances one every time you add a new instruction.


Constructor Summary
GeneratedBlock()
           
GeneratedBlock(boolean bracesRequired, boolean indentRequired)
           
 
Method Summary
 void _break()
          Create a break statement and add it to this block
 void _break(GeneratedLabel label)
           
 void _continue()
           
 void _continue(GeneratedLabel label)
          Create a continue statement and add it to this block
 GeneratedDoLoop _do(GeneratedExpression test)
          Create a Do statement and add it to this block
 GeneratedForLoop _for()
          Create a For statement and add it to this block
 GeneratedConditional _if(GeneratedExpression expr)
          Create an If statement and add it to this block
 void _return()
          Create a return statement and add it to this block
 void _return(GeneratedExpression exp)
          Create a return statement and add it to this block
 GeneratedSwitch _switch(GeneratedExpression test)
          Create a switch/case statement and add it to this block
 void _throw(GeneratedExpression exp)
          Create a throw statement and add it to this block
 GeneratedTry _try()
          Create a Try statement and add it to this block
 GeneratedWhileLoop _while(GeneratedExpression test)
          Create a While statement and add it to this block
 GeneratedBlock add(Statement s)
          Adds a statement to this block
 GeneratedBlock assign(AssignmentTarget lhs, GeneratedExpression exp)
          Creates an assignment statement and adds it to this block.
 GeneratedBlock assignPlus(AssignmentTarget lhs, GeneratedExpression exp)
           
 GeneratedBlock block()
          Create a sub-block and add it to this block
 GeneratedVariable decl(int mods, Type type, String name, GeneratedExpression init)
          Adds a local variable declaration to this block
 GeneratedVariable decl(Type type, String name)
          Adds a local variable declaration to this block
 GeneratedVariable decl(Type type, String name, GeneratedExpression init)
          Adds a local variable declaration to this block
 Statement directStatement(String source)
          Creates a "literal" statement directly.
 GeneratedForEach forEach(Type varType, String name, GeneratedExpression collection)
          Creates an enhanced For statement based on j2se 1.5 JLS and add it to this block
 void generate(Formatter f)
           
 List<Object> getContents()
          Returns a read-only view of Statements and Declaration in this block.
 GeneratedInvocation invoke(GeneratedExpression expr, GeneratedMethod method)
          Creates an invocation statement and adds it to this block.
 GeneratedInvocation invoke(GeneratedExpression expr, String method)
          Creates an invocation statement and adds it to this block.
 GeneratedInvocation invoke(GeneratedMethod method)
          Creates an invocation statement and adds it to this block.
 GeneratedInvocation invoke(String method)
          Creates an invocation statement and adds it to this block.
 boolean isEmpty()
          Returns true if this block is empty and does not contain any statement.
 GeneratedLabel label(String name)
          Create a label, which can be referenced from continue and break statements.
 int pos()
          Gets the current position to which new statements will be inserted.
 int pos(int newPos)
          Sets the current position.
 void state(Formatter f)
           
 GeneratedInvocation staticInvoke(TypeReference type, String method)
          Creates a static invocation statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneratedBlock

public GeneratedBlock()

GeneratedBlock

public GeneratedBlock(boolean bracesRequired,
                      boolean indentRequired)
Method Detail

getContents

public List<Object> getContents()
Returns a read-only view of Statements and Declaration in this block.


pos

public int pos()
Gets the current position to which new statements will be inserted.

For example if the value is 0, newly created instructions will be inserted at the very beginning of the block.

See Also:
pos(int)

pos

public int pos(int newPos)
Sets the current position.

Returns:
the old value of the current position.
Throws:
IllegalArgumentException - if the new position value is illegal.
See Also:
pos()

isEmpty

public boolean isEmpty()
Returns true if this block is empty and does not contain any statement.


decl

public GeneratedVariable decl(Type type,
                              String name)
Adds a local variable declaration to this block

Parameters:
type - Type of the variable
name - Name of the variable
Returns:
Newly generated Variable

decl

public GeneratedVariable decl(Type type,
                              String name,
                              GeneratedExpression init)
Adds a local variable declaration to this block

Parameters:
type - Type of the variable
name - Name of the variable
init - Initialization expression for this variable. May be null.
Returns:
Newly generated Variable

decl

public GeneratedVariable decl(int mods,
                              Type type,
                              String name,
                              GeneratedExpression init)
Adds a local variable declaration to this block

Parameters:
mods - Modifiers for the variable
type - Type of the variable
name - Name of the variable
init - Initialization expression for this variable. May be null.
Returns:
Newly generated Variable

assign

public GeneratedBlock assign(AssignmentTarget lhs,
                             GeneratedExpression exp)
Creates an assignment statement and adds it to this block.

Parameters:
lhs - Assignable variable or field for left hand side of expression
exp - Right hand side expression

assignPlus

public GeneratedBlock assignPlus(AssignmentTarget lhs,
                                 GeneratedExpression exp)

invoke

public GeneratedInvocation invoke(GeneratedExpression expr,
                                  String method)
Creates an invocation statement and adds it to this block.

Parameters:
expr - Expression evaluating to the class or object upon which the named method will be invoked
method - Name of method to invoke
Returns:
Newly generated Invocation

invoke

public GeneratedInvocation invoke(GeneratedExpression expr,
                                  GeneratedMethod method)
Creates an invocation statement and adds it to this block.

Parameters:
expr - Expression evaluating to the class or object upon which the method will be invoked
method - Method to invoke
Returns:
Newly generated Invocation

staticInvoke

public GeneratedInvocation staticInvoke(TypeReference type,
                                        String method)
Creates a static invocation statement.


invoke

public GeneratedInvocation invoke(String method)
Creates an invocation statement and adds it to this block.

Parameters:
method - Name of method to invoke
Returns:
Newly generated Invocation

invoke

public GeneratedInvocation invoke(GeneratedMethod method)
Creates an invocation statement and adds it to this block.

Parameters:
method - Method to invoke
Returns:
Newly generated Invocation

add

public GeneratedBlock add(Statement s)
Adds a statement to this block

Parameters:
s - Statement to be added
Returns:
This block

_if

public GeneratedConditional _if(GeneratedExpression expr)
Create an If statement and add it to this block

Parameters:
expr - Expression to be tested to determine branching
Returns:
Newly generated conditional statement

_for

public GeneratedForLoop _for()
Create a For statement and add it to this block

Returns:
Newly generated For statement

_while

public GeneratedWhileLoop _while(GeneratedExpression test)
Create a While statement and add it to this block

Returns:
Newly generated While statement

_switch

public GeneratedSwitch _switch(GeneratedExpression test)
Create a switch/case statement and add it to this block


_do

public GeneratedDoLoop _do(GeneratedExpression test)
Create a Do statement and add it to this block

Returns:
Newly generated Do statement

_try

public GeneratedTry _try()
Create a Try statement and add it to this block

Returns:
Newly generated Try statement

_return

public void _return()
Create a return statement and add it to this block


_return

public void _return(GeneratedExpression exp)
Create a return statement and add it to this block


_throw

public void _throw(GeneratedExpression exp)
Create a throw statement and add it to this block


_break

public void _break()
Create a break statement and add it to this block


_break

public void _break(GeneratedLabel label)

label

public GeneratedLabel label(String name)
Create a label, which can be referenced from continue and break statements.


_continue

public void _continue(GeneratedLabel label)
Create a continue statement and add it to this block


_continue

public void _continue()

block

public GeneratedBlock block()
Create a sub-block and add it to this block


directStatement

public Statement directStatement(String source)
Creates a "literal" statement directly.

Specified string is printed as-is. This is useful as a short-cut.

For example, you can invoke this method as: directStatement("a=b+c;").


generate

public void generate(Formatter f)
Specified by:
generate in interface Generable

forEach

public GeneratedForEach forEach(Type varType,
                                String name,
                                GeneratedExpression collection)
Creates an enhanced For statement based on j2se 1.5 JLS and add it to this block

Returns:
Newly generated enhanced For statement per j2se 1.5 specification

state

public void state(Formatter f)
Specified by:
state in interface Statement


Copyright © 2010–2015 MuleSoft, Inc.. All rights reserved.