class BasicJBlock extends BasicJCommentable implements JBlock, BlockContent
JBlock.Braces
Modifier and Type | Field and Description |
---|---|
private JBlock.Braces |
braces |
private java.util.ArrayList<BlockContent> |
content |
private BasicJBlock |
parent |
private int |
tmpId |
Constructor and Description |
---|
BasicJBlock(BasicJBlock parent,
JBlock.Braces braces) |
Modifier and Type | Method and Description |
---|---|
JStatement |
_assert(JExpr expr)
Insert an
assert statement at this point. |
JStatement |
_assert(JExpr expr,
JExpr message)
Insert an
assert statement at this point with a message. |
JStatement |
_break()
Insert a
break statement at this point. |
JStatement |
_break(JLabel label)
Insert a labelled
break statement at this point. |
JClassDef |
_class(int mods,
java.lang.String name)
Insert a local class definition at this point.
|
JStatement |
_continue()
Insert a
continue statement at this point. |
JStatement |
_continue(JLabel label)
Insert a labelled
continue statement at this point. |
JBlock |
_do(JExpr cond)
Insert a
do /while statement at this point. |
JFor |
_for()
Insert a
for loop at this point. |
JIf |
_if(JExpr cond)
Insert an
if statement at this point. |
JCall |
_new(java.lang.Class<?> type)
Insert an object construction statement at this point.
|
JCall |
_new(JType type)
Insert an object construction statement at this point.
|
JCall |
_new(java.lang.String type)
Insert an object construction statement at this point.
|
JAnonymousClassDef |
_newAnon(java.lang.Class<?> type)
Insert an object construction statement for an anonymous class at this point.
|
JAnonymousClassDef |
_newAnon(JType type)
Insert an object construction statement for an anonymous class at this point.
|
JAnonymousClassDef |
_newAnon(java.lang.String type)
Insert an object construction statement for an anonymous class at this point.
|
JStatement |
_return()
Insert a
void return statement at this point. |
JStatement |
_return(JExpr expr)
Insert a
return statement at this point. |
JSwitch |
_switch(JExpr expr)
Insert a
switch statement at this point. |
JBlock |
_synchronized(JExpr synchExpr)
Insert a
synchronized block at this point. |
JStatement |
_throw(JExpr expr)
Insert a
throw statement at this point. |
JTry |
_try()
Insert a
try block at this point. |
JBlock |
_while(JExpr cond)
Insert a
while statement at this point. |
JStatement |
add(JExpr expr)
Insert an expression statement at this point.
|
private <T extends AbstractJCall> |
add(T item) |
private <T extends AbstractJExpr> |
add(T item) |
private <T extends BlockContent> |
add(T s) |
JStatement |
addAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
+= ) expression at this point. |
JStatement |
andAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
&= ) expression at this point. |
JLabel |
anonLabel()
Add a label at this point whose unique name is automatically generated.
|
JLabel |
anonLabel(JLabel label)
Name and attach a forward label as anonymous.
|
JStatement |
assign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
= ) expression at this point. |
JBlock |
blankLine()
Insert a blank line at this point.
|
JBlock |
block(JBlock.Braces braces)
Create a nested sub-block at this point.
|
JCall |
call(javax.lang.model.element.ExecutableElement element)
Insert a method invocation at this point.
|
JCall |
call(JExpr obj,
javax.lang.model.element.ExecutableElement element)
Insert a method invocation at this point.
|
JCall |
call(JExpr obj,
java.lang.String name)
Insert a method invocation at this point.
|
JCall |
call(java.lang.String name)
Insert a method invocation at this point.
|
JCall |
callStatic(java.lang.Class<?> type,
java.lang.String name)
Insert a type-qualified static method invocation at this point.
|
JCall |
callStatic(javax.lang.model.element.ExecutableElement element)
Insert a type-qualified static method invocation at this point.
|
JCall |
callStatic(JType type,
java.lang.String name)
Insert a type-qualified static method invocation at this point.
|
JCall |
callStatic(java.lang.String type,
java.lang.String name)
Insert a type-qualified static method invocation at this point.
|
JCall |
callSuper()
Insert a
super() call at this point. |
JCall |
callThis()
Insert a
this() call at this point. |
JStatement |
divAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
/= ) expression at this point. |
JStatement |
empty()
Insert an empty statement at this point (just a semicolon).
|
JBlock |
forEach(int mods,
java.lang.Class<?> type,
java.lang.String name,
JExpr iterable)
Insert a "for-each" style
for loop at this point. |
JBlock |
forEach(int mods,
JType type,
java.lang.String name,
JExpr iterable)
Insert a "for-each" style
for loop at this point. |
JBlock |
forEach(int mods,
java.lang.String type,
java.lang.String name,
JExpr iterable)
Insert a "for-each" style
for loop at this point. |
JLabel |
forwardLabel()
Create a forward label that can be named and attached later.
|
(package private) BlockContent |
get(int idx) |
(package private) BasicJBlock |
getParent() |
(package private) boolean |
hasSingleItemOfType(java.lang.Class<? extends BlockContent> type) |
JLabel |
label(JLabel label,
java.lang.String name)
Name and attach a forward label.
|
JLabel |
label(java.lang.String name)
Add a label at this point, which may be used for future branch instructions.
|
JStatement |
lshrAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
>>>= ) expression at this point. |
JStatement |
modAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
%= ) expression at this point. |
JStatement |
mulAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
*= ) expression at this point. |
JStatement |
orAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
|= ) expression at this point. |
JStatement |
postDec(JAssignableExpr target)
Insert a postfix
-- expression at this point. |
JStatement |
postInc(JAssignableExpr target)
Insert a postfix
++ expression at this point. |
JStatement |
preDec(JAssignableExpr target)
Insert a prefix
-- expression at this point. |
JStatement |
preInc(JAssignableExpr target)
Insert a prefix
++ expression at this point. |
JStatement |
shlAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
<<= ) expression at this point. |
JStatement |
shrAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
>>= ) expression at this point. |
(package private) int |
size() |
JStatement |
subAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
-= ) expression at this point. |
java.lang.String |
tempName()
Generate a temporary variable name.
|
JExpr |
tempVar(java.lang.Class<?> type,
JExpr value)
Insert a local variable declaration at this point with a generated name.
|
JExpr |
tempVar(JType type,
JExpr value)
Insert a local variable declaration at this point with a generated name.
|
JExpr |
tempVar(java.lang.String type,
JExpr value)
Insert a local variable declaration at this point with a generated name.
|
JVarDeclaration |
var(int mods,
java.lang.Class<?> type,
java.lang.String name)
Insert a local variable declaration at this point.
|
JVarDeclaration |
var(int mods,
java.lang.Class<?> type,
java.lang.String name,
JExpr value)
Insert a local variable declaration at this point.
|
JVarDeclaration |
var(int mods,
JType type,
java.lang.String name)
Insert a local variable declaration at this point.
|
JVarDeclaration |
var(int mods,
JType type,
java.lang.String name,
JExpr value)
Insert a local variable declaration at this point.
|
JVarDeclaration |
var(int mods,
java.lang.String type,
java.lang.String name)
Insert a local variable declaration at this point.
|
JVarDeclaration |
var(int mods,
java.lang.String type,
java.lang.String name,
JExpr value)
Insert a local variable declaration at this point.
|
void |
write(SourceFileWriter writer) |
(package private) void |
write(SourceFileWriter writer,
FormatPreferences.Space beforeBrace) |
(package private) void |
write(SourceFileWriter writer,
FormatPreferences.Space beforeBrace,
JBlock.Braces braces) |
JStatement |
xorAssign(JAssignableExpr target,
JExpr e1)
Insert an assignment (
^= ) expression at this point. |
blockComment, lineComment, writeComments
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
blockComment, lineComment
private final BasicJBlock parent
private final java.util.ArrayList<BlockContent> content
private final JBlock.Braces braces
private int tmpId
BasicJBlock(BasicJBlock parent, JBlock.Braces braces)
private <T extends BlockContent> T add(T s)
private <T extends AbstractJExpr> ExpressionJStatement add(T item)
private <T extends AbstractJCall> T add(T item)
public JBlock blankLine()
JBlock
public JBlock block(JBlock.Braces braces)
JBlock
public JIf _if(JExpr cond)
JBlock
if
statement at this point.public JBlock _while(JExpr cond)
JBlock
while
statement at this point.public JBlock _do(JExpr cond)
JBlock
do
/while
statement at this point.public JLabel label(java.lang.String name)
JBlock
public JLabel anonLabel()
JBlock
public JLabel forwardLabel()
JBlock
forwardLabel
in interface JBlock
public JLabel label(JLabel label, java.lang.String name)
JBlock
public JLabel anonLabel(JLabel label)
JBlock
public JStatement _continue()
JBlock
continue
statement at this point.public JStatement _continue(JLabel label)
JBlock
continue
statement at this point.public JStatement _break()
JBlock
break
statement at this point.public JStatement _break(JLabel label)
JBlock
break
statement at this point.public JBlock forEach(int mods, java.lang.String type, java.lang.String name, JExpr iterable)
JBlock
for
loop at this point.public JBlock forEach(int mods, JType type, java.lang.String name, JExpr iterable)
JBlock
for
loop at this point.public JBlock forEach(int mods, java.lang.Class<?> type, java.lang.String name, JExpr iterable)
JBlock
for
loop at this point.public JSwitch _switch(JExpr expr)
JBlock
switch
statement at this point.public JStatement _return(JExpr expr)
JBlock
return
statement at this point.public JStatement _return()
JBlock
void
return
statement at this point.public JStatement _assert(JExpr expr)
JBlock
assert
statement at this point.public JStatement _assert(JExpr expr, JExpr message)
JBlock
assert
statement at this point with a message.public JCall callThis()
JBlock
this()
call at this point.public JCall callSuper()
JBlock
super()
call at this point.public JStatement add(JExpr expr)
JBlock
public JCall call(javax.lang.model.element.ExecutableElement element)
JBlock
block.call(element);
block.add(JExprs.call(element));
public JCall call(JExpr obj, javax.lang.model.element.ExecutableElement element)
JBlock
public JCall call(java.lang.String name)
JBlock
block.call(methodName);
block.add(JExprs.call(methodName));
public JCall call(JExpr obj, java.lang.String name)
JBlock
public JCall callStatic(javax.lang.model.element.ExecutableElement element)
JBlock
callStatic
in interface JBlock
element
- the program element whose name and type to usepublic JCall callStatic(java.lang.String type, java.lang.String name)
JBlock
callStatic
in interface JBlock
type
- the type upon which to invokename
- the method namepublic JCall callStatic(JType type, java.lang.String name)
JBlock
callStatic
in interface JBlock
type
- the type upon which to invokename
- the method namepublic JCall callStatic(java.lang.Class<?> type, java.lang.String name)
JBlock
callStatic
in interface JBlock
type
- the type upon which to invokename
- the method namepublic JCall _new(java.lang.String type)
JBlock
public JCall _new(JType type)
JBlock
public JCall _new(java.lang.Class<?> type)
JBlock
public JAnonymousClassDef _newAnon(java.lang.String type)
JBlock
public JAnonymousClassDef _newAnon(JType type)
JBlock
public JAnonymousClassDef _newAnon(java.lang.Class<?> type)
JBlock
public JClassDef _class(int mods, java.lang.String name)
JBlock
public JBlock _synchronized(JExpr synchExpr)
JBlock
synchronized
block at this point._synchronized
in interface JBlock
synchExpr
- the lock expressionsynchronized
blockpublic JStatement assign(JAssignableExpr target, JExpr e1)
JBlock
=
) expression at this point.public JStatement addAssign(JAssignableExpr target, JExpr e1)
JBlock
+=
) expression at this point.public JStatement subAssign(JAssignableExpr target, JExpr e1)
JBlock
-=
) expression at this point.public JStatement mulAssign(JAssignableExpr target, JExpr e1)
JBlock
*=
) expression at this point.public JStatement divAssign(JAssignableExpr target, JExpr e1)
JBlock
/=
) expression at this point.public JStatement modAssign(JAssignableExpr target, JExpr e1)
JBlock
%=
) expression at this point.public JStatement andAssign(JAssignableExpr target, JExpr e1)
JBlock
&=
) expression at this point.public JStatement orAssign(JAssignableExpr target, JExpr e1)
JBlock
|=
) expression at this point.public JStatement xorAssign(JAssignableExpr target, JExpr e1)
JBlock
^=
) expression at this point.public JStatement shrAssign(JAssignableExpr target, JExpr e1)
JBlock
>>=
) expression at this point.public JStatement lshrAssign(JAssignableExpr target, JExpr e1)
JBlock
>>>=
) expression at this point.lshrAssign
in interface JBlock
target
- the assignment targete1
- the expression to applypublic JStatement shlAssign(JAssignableExpr target, JExpr e1)
JBlock
<<=
) expression at this point.public JStatement postInc(JAssignableExpr target)
JBlock
++
expression at this point.public JStatement postDec(JAssignableExpr target)
JBlock
--
expression at this point.public JStatement preInc(JAssignableExpr target)
JBlock
++
expression at this point.public JStatement preDec(JAssignableExpr target)
JBlock
--
expression at this point.public JStatement empty()
JBlock
public JStatement _throw(JExpr expr)
JBlock
throw
statement at this point.public JVarDeclaration var(int mods, java.lang.String type, java.lang.String name, JExpr value)
JBlock
public JVarDeclaration var(int mods, JType type, java.lang.String name, JExpr value)
JBlock
public JVarDeclaration var(int mods, java.lang.Class<?> type, java.lang.String name, JExpr value)
JBlock
public JVarDeclaration var(int mods, java.lang.String type, java.lang.String name)
JBlock
public JVarDeclaration var(int mods, JType type, java.lang.String name)
JBlock
public JVarDeclaration var(int mods, java.lang.Class<?> type, java.lang.String name)
JBlock
public JExpr tempVar(java.lang.String type, JExpr value)
JBlock
public JExpr tempVar(JType type, JExpr value)
JBlock
public JExpr tempVar(java.lang.Class<?> type, JExpr value)
JBlock
public java.lang.String tempName()
JBlock
BasicJBlock getParent()
int size()
BlockContent get(int idx)
void write(SourceFileWriter writer, FormatPreferences.Space beforeBrace) throws java.io.IOException
java.io.IOException
void write(SourceFileWriter writer, FormatPreferences.Space beforeBrace, JBlock.Braces braces) throws java.io.IOException
java.io.IOException
public void write(SourceFileWriter writer) throws java.io.IOException
boolean hasSingleItemOfType(java.lang.Class<? extends BlockContent> type)