| java.lang.Object com.sun.codemodel.JBlock
JBlock | final public class JBlock implements JGenerable,JStatement(Code) | | A block of Java code, which may contain statements and local declarations.
JBlock contains a large number of factory methods that creates new
statements/declarations. Those newly created statements/declarations are
inserted into the
JBlock.pos() "current position" . The position advances
one every time you add a new instruction.
|
Constructor Summary | |
public | JBlock() | public | JBlock(boolean bracesRequired, boolean indentRequired) |
Method Summary | |
public void | _break() | public void | _break(JLabel label) | public void | _continue(JLabel label) | public void | _continue() | public JDoLoop | _do(JExpression test) | public JForLoop | _for() | public JConditional | _if(JExpression expr) | public void | _return() | public void | _return(JExpression exp) | public JSwitch | _switch(JExpression test) | public void | _throw(JExpression exp) | public JTryBlock | _try() | public JWhileLoop | _while(JExpression test) | public JBlock | add(JStatement s) | public JBlock | assign(JAssignmentTarget lhs, JExpression exp) Creates an assignment statement and adds it to this block. | public JBlock | assignPlus(JAssignmentTarget lhs, JExpression exp) | public JBlock | block() | public JVar | decl(JType type, String name) | public JVar | decl(JType type, String name, JExpression init) Adds a local variable declaration to this block
Parameters: type - JType of the variable Parameters: name - Name of the variable Parameters: init - Initialization expression for this variable. | public JVar | decl(int mods, JType type, String name, JExpression init) Adds a local variable declaration to this block
Parameters: mods - Modifiers for the variable Parameters: type - JType of the variable Parameters: name - Name of the variable Parameters: init - Initialization expression for this variable. | public JStatement | directStatement(String source) Creates a "literal" statement directly. | public JForEach | forEach(JType varType, String name, JExpression collection) | public void | generate(JFormatter f) | void | generateBody(JFormatter f) | public List<Object> | getContents() Returns a read-only view of
JStatement s and
JDeclaration in this block. | public JInvocation | invoke(JExpression expr, String method) Creates an invocation statement and adds it to this block. | public JInvocation | invoke(JExpression expr, JMethod method) Creates an invocation statement and adds it to this block. | public JInvocation | invoke(String method) Creates an invocation statement and adds it to this block. | public JInvocation | invoke(JMethod method) Creates an invocation statement and adds it to this block. | public JLabel | label(String name) Create a label, which can be referenced from
continue and break statements. | public int | pos() Gets the current position to which new statements will be inserted. | public int | pos(int newPos) Sets the current position. | public void | state(JFormatter f) | public JInvocation | staticInvoke(JClass type, String method) Creates a static invocation statement. |
JBlock | public JBlock(boolean bracesRequired, boolean indentRequired)(Code) | | |
_break | public void _break()(Code) | | Create a break statement and add it to this block
|
_continue | public void _continue(JLabel label)(Code) | | Create a continue statement and add it to this block
|
_continue | public void _continue()(Code) | | |
_do | public JDoLoop _do(JExpression test)(Code) | | Create a Do statement and add it to this block
Newly generated Do statement |
_for | public JForLoop _for()(Code) | | Create a For statement and add it to this block
Newly generated For statement |
_if | public JConditional _if(JExpression expr)(Code) | | Create an If statement and add it to this block
Parameters: expr - JExpression to be tested to determine branching Newly generated conditional statement |
_return | public void _return()(Code) | | Create a return statement and add it to this block
|
_return | public void _return(JExpression exp)(Code) | | Create a return statement and add it to this block
|
_throw | public void _throw(JExpression exp)(Code) | | Create a throw statement and add it to this block
|
_try | public JTryBlock _try()(Code) | | Create a Try statement and add it to this block
Newly generated Try statement |
_while | public JWhileLoop _while(JExpression test)(Code) | | Create a While statement and add it to this block
Newly generated While statement |
add | public JBlock add(JStatement s)(Code) | | Adds a statement to this block
Parameters: s - JStatement to be added This block |
assign | public JBlock assign(JAssignmentTarget lhs, JExpression exp)(Code) | | Creates an assignment statement and adds it to this block.
Parameters: lhs - Assignable variable or field for left hand side of expression Parameters: exp - Right hand side expression |
block | public JBlock block()(Code) | | Create a sub-block and add it to this block
|
decl | public JVar decl(JType type, String name)(Code) | | Adds a local variable declaration to this block
Parameters: type - JType of the variable Parameters: name - Name of the variable Newly generated JVar |
decl | public JVar decl(JType type, String name, JExpression init)(Code) | | Adds a local variable declaration to this block
Parameters: type - JType of the variable Parameters: name - Name of the variable Parameters: init - Initialization expression for this variable. May be null. Newly generated JVar |
decl | public JVar decl(int mods, JType type, String name, JExpression init)(Code) | | Adds a local variable declaration to this block
Parameters: mods - Modifiers for the variable Parameters: type - JType of the variable Parameters: name - Name of the variable Parameters: init - Initialization expression for this variable. May be null. Newly generated JVar |
directStatement | public JStatement directStatement(String source)(Code) | | 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;") .
|
forEach | public JForEach forEach(JType varType, String name, JExpression collection)(Code) | | Creates an enhanced For statement based on j2se 1.5 JLS
and add it to this block
Newly generated enhanced For statement per j2se 1.5specification |
invoke | public JInvocation invoke(JExpression expr, String method)(Code) | | Creates an invocation statement and adds it to this block.
Parameters: expr - JExpression evaluating to the class or object upon whichthe named method will be invoked Parameters: method - Name of method to invoke Newly generated JInvocation |
invoke | public JInvocation invoke(JExpression expr, JMethod method)(Code) | | Creates an invocation statement and adds it to this block.
Parameters: expr - JExpression evaluating to the class or object upon whichthe method will be invoked Parameters: method - JMethod to invoke Newly generated JInvocation |
invoke | public JInvocation invoke(String method)(Code) | | Creates an invocation statement and adds it to this block.
Parameters: method - Name of method to invoke Newly generated JInvocation |
invoke | public JInvocation invoke(JMethod method)(Code) | | Creates an invocation statement and adds it to this block.
Parameters: method - JMethod to invoke Newly generated JInvocation |
label | public JLabel label(String name)(Code) | | Create a label, which can be referenced from
continue and break statements.
|
pos | public int pos()(Code) | | 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: JBlock.pos(int) |
|
|