public final class GeneratedBlock extends Object implements Generable, Statement
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 and Description |
---|
GeneratedBlock() |
GeneratedBlock(boolean bracesRequired,
boolean indentRequired) |
Modifier and Type | Method and Description |
---|---|
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
Statement s 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.
|
public GeneratedBlock()
public GeneratedBlock(boolean bracesRequired, boolean indentRequired)
public List<Object> getContents()
Statement
s and Declaration
in this block.public int pos()
pos(int)
public int pos(int newPos)
IllegalArgumentException
- if the new position value is illegal.pos()
public boolean isEmpty()
public GeneratedVariable decl(Type type, String name)
type
- Type of the variablename
- Name of the variablepublic GeneratedVariable decl(Type type, String name, GeneratedExpression init)
type
- Type of the variablename
- Name of the variableinit
- Initialization expression for this variable. May be null.public GeneratedVariable decl(int mods, Type type, String name, GeneratedExpression init)
mods
- Modifiers for the variabletype
- Type of the variablename
- Name of the variableinit
- Initialization expression for this variable. May be null.public GeneratedBlock assign(AssignmentTarget lhs, GeneratedExpression exp)
lhs
- Assignable variable or field for left hand side of expressionexp
- Right hand side expressionpublic GeneratedBlock assignPlus(AssignmentTarget lhs, GeneratedExpression exp)
public GeneratedInvocation invoke(GeneratedExpression expr, String method)
expr
- Expression evaluating to the class or object upon which
the named method will be invokedmethod
- Name of method to invokepublic GeneratedInvocation invoke(GeneratedExpression expr, GeneratedMethod method)
expr
- Expression evaluating to the class or object upon which
the method will be invokedmethod
- Method to invokepublic GeneratedInvocation staticInvoke(TypeReference type, String method)
public GeneratedInvocation invoke(String method)
method
- Name of method to invokepublic GeneratedInvocation invoke(GeneratedMethod method)
method
- Method to invokepublic GeneratedBlock add(Statement s)
s
- Statement to be addedpublic GeneratedConditional _if(GeneratedExpression expr)
expr
- Expression to be tested to determine branchingpublic GeneratedForLoop _for()
public GeneratedWhileLoop _while(GeneratedExpression test)
public GeneratedSwitch _switch(GeneratedExpression test)
public GeneratedDoLoop _do(GeneratedExpression test)
public GeneratedTry _try()
public void _return()
public void _return(GeneratedExpression exp)
public void _throw(GeneratedExpression exp)
public void _break()
public void _break(GeneratedLabel label)
public GeneratedLabel label(String name)
continue
and break
statements.public void _continue(GeneratedLabel label)
public void _continue()
public GeneratedBlock block()
public Statement directStatement(String source)
directStatement("a=b+c;")
.public GeneratedForEach forEach(Type varType, String name, GeneratedExpression collection)
Copyright © 2010–2015 MuleSoft, Inc.. All rights reserved.