Package org.jboss.jdeparser
Interface JBlock
-
- All Superinterfaces:
JCommentable
,JStatement
public interface JBlock extends JStatement, JCommentable
A block of code, to which statements may be added.- Author:
- David M. Lloyd
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
JBlock.Braces
Braces mode.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description JStatement
_assert(JExpr expr)
Insert anassert
statement at this point.JStatement
_assert(JExpr expr, JExpr message)
Insert anassert
statement at this point with a message.JStatement
_break()
Insert abreak
statement at this point.JStatement
_break(JLabel label)
Insert a labelledbreak
statement at this point.JClassDef
_class(int mods, java.lang.String name)
Insert a local class definition at this point.JStatement
_continue()
Insert acontinue
statement at this point.JStatement
_continue(JLabel label)
Insert a labelledcontinue
statement at this point.JBlock
_do(JExpr cond)
Insert ado
/while
statement at this point.JFor
_for()
Insert afor
loop at this point.JIf
_if(JExpr cond)
Insert anif
statement at this point.JCall
_new(java.lang.Class<?> type)
Insert an object construction statement at this point.JCall
_new(java.lang.String type)
Insert an object construction statement at this point.JCall
_new(JType 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(java.lang.String 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.JStatement
_return()
Insert avoid
return
statement at this point.JStatement
_return(JExpr expr)
Insert areturn
statement at this point.JSwitch
_switch(JExpr expr)
Insert aswitch
statement at this point.JBlock
_synchronized(JExpr synchExpr)
Insert asynchronized
block at this point.JStatement
_throw(JExpr expr)
Insert athrow
statement at this point.JTry
_try()
Insert atry
block at this point.JBlock
_while(JExpr cond)
Insert awhile
statement at this point.JStatement
add(JExpr expr)
Insert an expression statement at this point.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(java.lang.String name)
Insert a method invocation at this point.JCall
call(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(JExpr obj, javax.lang.model.element.ExecutableElement element)
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(java.lang.String 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
callSuper()
Insert asuper()
call at this point.JCall
callThis()
Insert athis()
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" stylefor
loop at this point.JBlock
forEach(int mods, java.lang.String type, java.lang.String name, JExpr iterable)
Insert a "for-each" stylefor
loop at this point.JBlock
forEach(int mods, JType type, java.lang.String name, JExpr iterable)
Insert a "for-each" stylefor
loop at this point.JLabel
forwardLabel()
Create a forward label that can be named and attached later.JLabel
label(java.lang.String name)
Add a label at this point, which may be used for future branch instructions.JLabel
label(JLabel label, java.lang.String name)
Name and attach a forward label.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.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(java.lang.String 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.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, 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.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.JStatement
xorAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (^=
) expression at this point.-
Methods inherited from interface org.jboss.jdeparser.JCommentable
blockComment, lineComment
-
-
-
-
Method Detail
-
blankLine
JBlock blankLine()
Insert a blank line at this point.- Returns:
- this block
-
block
JBlock block(JBlock.Braces braces)
Create a nested sub-block at this point.- Parameters:
braces
- the rule for adding braces- Returns:
- the nested block
-
_if
JIf _if(JExpr cond)
Insert anif
statement at this point.- Parameters:
cond
- theif
condition- Returns:
- the
if
statement
-
_while
JBlock _while(JExpr cond)
Insert awhile
statement at this point.- Parameters:
cond
- thewhile
condition- Returns:
- the
while
statement
-
_do
JBlock _do(JExpr cond)
Insert ado
/while
statement at this point.- Parameters:
cond
- thewhile
condition- Returns:
- the
while
statement
-
label
JLabel label(java.lang.String name)
Add a label at this point, which may be used for future branch instructions.- Parameters:
name
- the label name- Returns:
- the label
-
anonLabel
JLabel anonLabel()
Add a label at this point whose unique name is automatically generated.- Returns:
- the label
-
forwardLabel
JLabel forwardLabel()
Create a forward label that can be named and attached later.- Returns:
- the forward label
-
label
JLabel label(JLabel label, java.lang.String name)
Name and attach a forward label.- Parameters:
label
- the label to name and attachname
- the label name- Returns:
- the attached label
-
anonLabel
JLabel anonLabel(JLabel label)
Name and attach a forward label as anonymous.- Parameters:
label
- the label to name and attach- Returns:
- the attached label
-
_continue
JStatement _continue()
Insert acontinue
statement at this point.- Returns:
- the statement
-
_continue
JStatement _continue(JLabel label)
Insert a labelledcontinue
statement at this point.- Parameters:
label
- the label- Returns:
- the statement
-
_break
JStatement _break()
Insert abreak
statement at this point.- Returns:
- the statement
-
_break
JStatement _break(JLabel label)
Insert a labelledbreak
statement at this point.- Parameters:
label
- the label- Returns:
- the statement
-
forEach
JBlock forEach(int mods, java.lang.String type, java.lang.String name, JExpr iterable)
Insert a "for-each" stylefor
loop at this point.- Parameters:
mods
- the item variable modifierstype
- the item variable typename
- the item variable nameiterable
- the iterable or array expression- Returns:
- the body of the
for
loop
-
forEach
JBlock forEach(int mods, JType type, java.lang.String name, JExpr iterable)
Insert a "for-each" stylefor
loop at this point.- Parameters:
mods
- the item variable modifierstype
- the item variable typename
- the item variable nameiterable
- the iterable or array expression- Returns:
- the body of the
for
loop
-
forEach
JBlock forEach(int mods, java.lang.Class<?> type, java.lang.String name, JExpr iterable)
Insert a "for-each" stylefor
loop at this point.- Parameters:
mods
- the item variable modifierstype
- the item variable typename
- the item variable nameiterable
- the iterable or array expression- Returns:
- the body of the
for
loop
-
_for
JFor _for()
Insert afor
loop at this point.- Returns:
- the
for
loop
-
_switch
JSwitch _switch(JExpr expr)
Insert aswitch
statement at this point.- Parameters:
expr
- theswitch
expression- Returns:
- the
switch
statement
-
_return
JStatement _return(JExpr expr)
Insert areturn
statement at this point.- Parameters:
expr
- the expression to return- Returns:
- the statement
-
_return
JStatement _return()
Insert avoid
return
statement at this point.- Returns:
- the statement
-
_assert
JStatement _assert(JExpr expr)
Insert anassert
statement at this point.- Parameters:
expr
- the expression to assert- Returns:
- the statement
-
_assert
JStatement _assert(JExpr expr, JExpr message)
Insert anassert
statement at this point with a message.- Parameters:
expr
- the expression to assertmessage
- the assertion message- Returns:
- the statement
-
callThis
JCall callThis()
Insert athis()
call at this point.- Returns:
- the call
-
callSuper
JCall callSuper()
Insert asuper()
call at this point.- Returns:
- the call
-
add
JStatement add(JExpr expr)
Insert an expression statement at this point. Expressions which are invalid statements may generate an error at the time this method is called, or at compile time.- Parameters:
expr
- the expression to add- Returns:
- the statement
-
call
JCall call(javax.lang.model.element.ExecutableElement element)
Insert a method invocation at this point. Note that these two invocations are identical:block.call(element); block.add(JExprs.call(element));
- Parameters:
element
- the program element whose name to use- Returns:
- the method call
-
call
JCall call(JExpr obj, javax.lang.model.element.ExecutableElement element)
Insert a method invocation at this point.- Parameters:
obj
- the expression upon which to invokeelement
- the program element whose name to use- Returns:
- the method call
-
call
JCall call(java.lang.String name)
Insert a method invocation at this point. Note that these two invocations are identical:block.call(methodName); block.add(JExprs.call(methodName));
- Parameters:
name
- the method name- Returns:
- the method call
-
call
JCall call(JExpr obj, java.lang.String name)
Insert a method invocation at this point.- Parameters:
obj
- the expression upon which to invokename
- the method name- Returns:
- the method call
-
callStatic
JCall callStatic(javax.lang.model.element.ExecutableElement element)
Insert a type-qualified static method invocation at this point.- Parameters:
element
- the program element whose name and type to use- Returns:
- the method call
-
callStatic
JCall callStatic(java.lang.String type, java.lang.String name)
Insert a type-qualified static method invocation at this point.- Parameters:
type
- the type upon which to invokename
- the method name- Returns:
- the method call
-
callStatic
JCall callStatic(JType type, java.lang.String name)
Insert a type-qualified static method invocation at this point.- Parameters:
type
- the type upon which to invokename
- the method name- Returns:
- the method call
-
callStatic
JCall callStatic(java.lang.Class<?> type, java.lang.String name)
Insert a type-qualified static method invocation at this point.- Parameters:
type
- the type upon which to invokename
- the method name- Returns:
- the method call
-
_new
JCall _new(java.lang.String type)
Insert an object construction statement at this point.- Parameters:
type
- the type to instantiate- Returns:
- the constructor call
-
_new
JCall _new(JType type)
Insert an object construction statement at this point.- Parameters:
type
- the type to instantiate- Returns:
- the constructor call
-
_new
JCall _new(java.lang.Class<?> type)
Insert an object construction statement at this point.- Parameters:
type
- the type to instantiate- Returns:
- the constructor call
-
_newAnon
JAnonymousClassDef _newAnon(java.lang.String type)
Insert an object construction statement for an anonymous class at this point.- Parameters:
type
- the type to instantiate- Returns:
- the anonymous class definition
-
_newAnon
JAnonymousClassDef _newAnon(JType type)
Insert an object construction statement for an anonymous class at this point.- Parameters:
type
- the type to instantiate- Returns:
- the anonymous class definition
-
_newAnon
JAnonymousClassDef _newAnon(java.lang.Class<?> type)
Insert an object construction statement for an anonymous class at this point.- Parameters:
type
- the type to instantiate- Returns:
- the anonymous class definition
-
_class
JClassDef _class(int mods, java.lang.String name)
Insert a local class definition at this point.- Parameters:
mods
- the class modifiersname
- the local class name- Returns:
- the local class definition
-
_synchronized
JBlock _synchronized(JExpr synchExpr)
Insert asynchronized
block at this point.- Parameters:
synchExpr
- the lock expression- Returns:
- the
synchronized
block
-
assign
JStatement assign(JAssignableExpr target, JExpr e1)
Insert an assignment (=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
addAssign
JStatement addAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (+=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
subAssign
JStatement subAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (-=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
mulAssign
JStatement mulAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (*=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
divAssign
JStatement divAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (/=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
modAssign
JStatement modAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (%=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
andAssign
JStatement andAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (&=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
orAssign
JStatement orAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (|=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
xorAssign
JStatement xorAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (^=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
shrAssign
JStatement shrAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (>>=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
lshrAssign
JStatement lshrAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (>>>=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
shlAssign
JStatement shlAssign(JAssignableExpr target, JExpr e1)
Insert an assignment (<<=
) expression at this point.- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
postInc
JStatement postInc(JAssignableExpr target)
Insert a postfix++
expression at this point.- Parameters:
target
- the target expression- Returns:
- the statement
-
postDec
JStatement postDec(JAssignableExpr target)
Insert a postfix--
expression at this point.- Parameters:
target
- the target expression- Returns:
- the statement
-
preInc
JStatement preInc(JAssignableExpr target)
Insert a prefix++
expression at this point.- Parameters:
target
- the target expression- Returns:
- the statement
-
preDec
JStatement preDec(JAssignableExpr target)
Insert a prefix--
expression at this point.- Parameters:
target
- the target expression- Returns:
- the statement
-
empty
JStatement empty()
Insert an empty statement at this point (just a semicolon).- Returns:
- the statement
-
_throw
JStatement _throw(JExpr expr)
Insert athrow
statement at this point.- Parameters:
expr
- the expression to throw- Returns:
- the statement
-
_try
JTry _try()
Insert atry
block at this point.- Returns:
- the
try
block
-
var
JVarDeclaration var(int mods, java.lang.String type, java.lang.String name, JExpr value)
Insert a local variable declaration at this point.- Parameters:
mods
- the variable modifierstype
- the local variable typename
- the local variable namevalue
- the local variable's initializer expression- Returns:
- the local variable declaration
-
var
JVarDeclaration var(int mods, JType type, java.lang.String name, JExpr value)
Insert a local variable declaration at this point.- Parameters:
mods
- the variable modifierstype
- the local variable typename
- the local variable namevalue
- the local variable's initializer expression- Returns:
- the local variable declaration
-
var
JVarDeclaration var(int mods, java.lang.Class<?> type, java.lang.String name, JExpr value)
Insert a local variable declaration at this point.- Parameters:
mods
- the variable modifierstype
- the local variable typename
- the local variable namevalue
- the local variable's initializer expression- Returns:
- the local variable declaration
-
var
JVarDeclaration var(int mods, java.lang.String type, java.lang.String name)
Insert a local variable declaration at this point.- Parameters:
mods
- the variable modifierstype
- the local variable typename
- the local variable name- Returns:
- the local variable declaration
-
var
JVarDeclaration var(int mods, JType type, java.lang.String name)
Insert a local variable declaration at this point.- Parameters:
mods
- the variable modifierstype
- the local variable typename
- the local variable name- Returns:
- the local variable declaration
-
var
JVarDeclaration var(int mods, java.lang.Class<?> type, java.lang.String name)
Insert a local variable declaration at this point.- Parameters:
mods
- the variable modifierstype
- the local variable typename
- the local variable name- Returns:
- the local variable declaration
-
tempVar
JExpr tempVar(java.lang.String type, JExpr value)
Insert a local variable declaration at this point with a generated name.- Parameters:
type
- the local variable typevalue
- the local variable's initializer expression- Returns:
- the local variable expression
-
tempVar
JExpr tempVar(JType type, JExpr value)
Insert a local variable declaration at this point with a generated name.- Parameters:
type
- the local variable typevalue
- the local variable's initializer expression- Returns:
- the local variable expression
-
tempVar
JExpr tempVar(java.lang.Class<?> type, JExpr value)
Insert a local variable declaration at this point with a generated name.- Parameters:
type
- the local variable typevalue
- the local variable's initializer expression- Returns:
- the local variable expression
-
tempName
java.lang.String tempName()
Generate a temporary variable name.- Returns:
- the generated name
-
-