Package org.jboss.jdeparser
Class BasicJBlock
- java.lang.Object
-
- org.jboss.jdeparser.BasicJCommentable
-
- org.jboss.jdeparser.BasicJBlock
-
- All Implemented Interfaces:
BlockContent
,JBlock
,JCommentable
,JStatement
,Writable
- Direct Known Subclasses:
CaseJBlock
,ConditionJBlock
,DefaultJBlock
,ElseJBlock
,FinallyJBlock
,ForEachJBlock
,ForJBlock
,ImplJCatch
,ImplJTry
,InitJBlock
,StaticInitJBlock
,SynchJBlock
class BasicJBlock extends BasicJCommentable implements JBlock, BlockContent
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.jdeparser.JBlock
JBlock.Braces
-
-
Field Summary
Fields Modifier and Type Field Description private JBlock.Braces
braces
private java.util.ArrayList<BlockContent>
content
private BasicJBlock
parent
private int
tmpId
-
Constructor Summary
Constructors Constructor Description BasicJBlock(BasicJBlock parent, JBlock.Braces braces)
-
Method Summary
All Methods Instance Methods Concrete 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.private <T extends BlockContent>
Tadd(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(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.(package private) BlockContent
get(int idx)
(package private) BasicJBlock
getParent()
(package private) boolean
hasSingleItemOfType(java.lang.Class<? extends BlockContent> type)
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.(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(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.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.-
Methods inherited from class org.jboss.jdeparser.BasicJCommentable
blockComment, lineComment, writeComments
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jboss.jdeparser.JCommentable
blockComment, lineComment
-
-
-
-
Field Detail
-
parent
private final BasicJBlock parent
-
content
private final java.util.ArrayList<BlockContent> content
-
braces
private final JBlock.Braces braces
-
tmpId
private int tmpId
-
-
Constructor Detail
-
BasicJBlock
BasicJBlock(BasicJBlock parent, JBlock.Braces braces)
-
-
Method Detail
-
add
private <T extends BlockContent> T add(T s)
-
add
private <T extends AbstractJExpr> ExpressionJStatement add(T item)
-
add
private <T extends AbstractJCall> T add(T item)
-
blankLine
public JBlock blankLine()
Description copied from interface:JBlock
Insert a blank line at this point.
-
block
public JBlock block(JBlock.Braces braces)
Description copied from interface:JBlock
Create a nested sub-block at this point.
-
_if
public JIf _if(JExpr cond)
Description copied from interface:JBlock
Insert anif
statement at this point.
-
_while
public JBlock _while(JExpr cond)
Description copied from interface:JBlock
Insert awhile
statement at this point.
-
_do
public JBlock _do(JExpr cond)
Description copied from interface:JBlock
Insert ado
/while
statement at this point.
-
label
public JLabel label(java.lang.String name)
Description copied from interface:JBlock
Add a label at this point, which may be used for future branch instructions.
-
anonLabel
public JLabel anonLabel()
Description copied from interface:JBlock
Add a label at this point whose unique name is automatically generated.
-
forwardLabel
public JLabel forwardLabel()
Description copied from interface:JBlock
Create a forward label that can be named and attached later.- Specified by:
forwardLabel
in interfaceJBlock
- Returns:
- the forward label
-
label
public JLabel label(JLabel label, java.lang.String name)
Description copied from interface:JBlock
Name and attach a forward label.
-
anonLabel
public JLabel anonLabel(JLabel label)
Description copied from interface:JBlock
Name and attach a forward label as anonymous.
-
_continue
public JStatement _continue()
Description copied from interface:JBlock
Insert acontinue
statement at this point.
-
_continue
public JStatement _continue(JLabel label)
Description copied from interface:JBlock
Insert a labelledcontinue
statement at this point.
-
_break
public JStatement _break()
Description copied from interface:JBlock
Insert abreak
statement at this point.
-
_break
public JStatement _break(JLabel label)
Description copied from interface:JBlock
Insert a labelledbreak
statement at this point.
-
forEach
public JBlock forEach(int mods, java.lang.String type, java.lang.String name, JExpr iterable)
Description copied from interface:JBlock
Insert a "for-each" stylefor
loop at this point.
-
forEach
public JBlock forEach(int mods, JType type, java.lang.String name, JExpr iterable)
Description copied from interface:JBlock
Insert a "for-each" stylefor
loop at this point.
-
forEach
public JBlock forEach(int mods, java.lang.Class<?> type, java.lang.String name, JExpr iterable)
Description copied from interface:JBlock
Insert a "for-each" stylefor
loop at this point.
-
_switch
public JSwitch _switch(JExpr expr)
Description copied from interface:JBlock
Insert aswitch
statement at this point.
-
_return
public JStatement _return(JExpr expr)
Description copied from interface:JBlock
Insert areturn
statement at this point.
-
_return
public JStatement _return()
Description copied from interface:JBlock
Insert avoid
return
statement at this point.
-
_assert
public JStatement _assert(JExpr expr)
Description copied from interface:JBlock
Insert anassert
statement at this point.
-
_assert
public JStatement _assert(JExpr expr, JExpr message)
Description copied from interface:JBlock
Insert anassert
statement at this point with a message.
-
callThis
public JCall callThis()
Description copied from interface:JBlock
Insert athis()
call at this point.
-
callSuper
public JCall callSuper()
Description copied from interface:JBlock
Insert asuper()
call at this point.
-
add
public JStatement add(JExpr expr)
Description copied from interface:JBlock
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.
-
call
public JCall call(javax.lang.model.element.ExecutableElement element)
Description copied from interface:JBlock
Insert a method invocation at this point. Note that these two invocations are identical:block.call(element); block.add(JExprs.call(element));
-
call
public JCall call(JExpr obj, javax.lang.model.element.ExecutableElement element)
Description copied from interface:JBlock
Insert a method invocation at this point.
-
call
public JCall call(java.lang.String name)
Description copied from interface:JBlock
Insert a method invocation at this point. Note that these two invocations are identical:block.call(methodName); block.add(JExprs.call(methodName));
-
call
public JCall call(JExpr obj, java.lang.String name)
Description copied from interface:JBlock
Insert a method invocation at this point.
-
callStatic
public JCall callStatic(javax.lang.model.element.ExecutableElement element)
Description copied from interface:JBlock
Insert a type-qualified static method invocation at this point.- Specified by:
callStatic
in interfaceJBlock
- Parameters:
element
- the program element whose name and type to use- Returns:
- the method call
-
callStatic
public JCall callStatic(java.lang.String type, java.lang.String name)
Description copied from interface:JBlock
Insert a type-qualified static method invocation at this point.- Specified by:
callStatic
in interfaceJBlock
- Parameters:
type
- the type upon which to invokename
- the method name- Returns:
- the method call
-
callStatic
public JCall callStatic(JType type, java.lang.String name)
Description copied from interface:JBlock
Insert a type-qualified static method invocation at this point.- Specified by:
callStatic
in interfaceJBlock
- Parameters:
type
- the type upon which to invokename
- the method name- Returns:
- the method call
-
callStatic
public JCall callStatic(java.lang.Class<?> type, java.lang.String name)
Description copied from interface:JBlock
Insert a type-qualified static method invocation at this point.- Specified by:
callStatic
in interfaceJBlock
- Parameters:
type
- the type upon which to invokename
- the method name- Returns:
- the method call
-
_new
public JCall _new(java.lang.String type)
Description copied from interface:JBlock
Insert an object construction statement at this point.
-
_new
public JCall _new(JType type)
Description copied from interface:JBlock
Insert an object construction statement at this point.
-
_new
public JCall _new(java.lang.Class<?> type)
Description copied from interface:JBlock
Insert an object construction statement at this point.
-
_newAnon
public JAnonymousClassDef _newAnon(java.lang.String type)
Description copied from interface:JBlock
Insert an object construction statement for an anonymous class at this point.
-
_newAnon
public JAnonymousClassDef _newAnon(JType type)
Description copied from interface:JBlock
Insert an object construction statement for an anonymous class at this point.
-
_newAnon
public JAnonymousClassDef _newAnon(java.lang.Class<?> type)
Description copied from interface:JBlock
Insert an object construction statement for an anonymous class at this point.
-
_class
public JClassDef _class(int mods, java.lang.String name)
Description copied from interface:JBlock
Insert a local class definition at this point.
-
_synchronized
public JBlock _synchronized(JExpr synchExpr)
Description copied from interface:JBlock
Insert asynchronized
block at this point.- Specified by:
_synchronized
in interfaceJBlock
- Parameters:
synchExpr
- the lock expression- Returns:
- the
synchronized
block
-
assign
public JStatement assign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (=
) expression at this point.
-
addAssign
public JStatement addAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (+=
) expression at this point.
-
subAssign
public JStatement subAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (-=
) expression at this point.
-
mulAssign
public JStatement mulAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (*=
) expression at this point.
-
divAssign
public JStatement divAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (/=
) expression at this point.
-
modAssign
public JStatement modAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (%=
) expression at this point.
-
andAssign
public JStatement andAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (&=
) expression at this point.
-
orAssign
public JStatement orAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (|=
) expression at this point.
-
xorAssign
public JStatement xorAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (^=
) expression at this point.
-
shrAssign
public JStatement shrAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (>>=
) expression at this point.
-
lshrAssign
public JStatement lshrAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (>>>=
) expression at this point.- Specified by:
lshrAssign
in interfaceJBlock
- Parameters:
target
- the assignment targete1
- the expression to apply- Returns:
- the statement
-
shlAssign
public JStatement shlAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlock
Insert an assignment (<<=
) expression at this point.
-
postInc
public JStatement postInc(JAssignableExpr target)
Description copied from interface:JBlock
Insert a postfix++
expression at this point.
-
postDec
public JStatement postDec(JAssignableExpr target)
Description copied from interface:JBlock
Insert a postfix--
expression at this point.
-
preInc
public JStatement preInc(JAssignableExpr target)
Description copied from interface:JBlock
Insert a prefix++
expression at this point.
-
preDec
public JStatement preDec(JAssignableExpr target)
Description copied from interface:JBlock
Insert a prefix--
expression at this point.
-
empty
public JStatement empty()
Description copied from interface:JBlock
Insert an empty statement at this point (just a semicolon).
-
_throw
public JStatement _throw(JExpr expr)
Description copied from interface:JBlock
Insert athrow
statement at this point.
-
var
public JVarDeclaration var(int mods, java.lang.String type, java.lang.String name, JExpr value)
Description copied from interface:JBlock
Insert a local variable declaration at this point.
-
var
public JVarDeclaration var(int mods, JType type, java.lang.String name, JExpr value)
Description copied from interface:JBlock
Insert a local variable declaration at this point.
-
var
public JVarDeclaration var(int mods, java.lang.Class<?> type, java.lang.String name, JExpr value)
Description copied from interface:JBlock
Insert a local variable declaration at this point.
-
var
public JVarDeclaration var(int mods, java.lang.String type, java.lang.String name)
Description copied from interface:JBlock
Insert a local variable declaration at this point.
-
var
public JVarDeclaration var(int mods, JType type, java.lang.String name)
Description copied from interface:JBlock
Insert a local variable declaration at this point.
-
var
public JVarDeclaration var(int mods, java.lang.Class<?> type, java.lang.String name)
Description copied from interface:JBlock
Insert a local variable declaration at this point.
-
tempVar
public JExpr tempVar(java.lang.String type, JExpr value)
Description copied from interface:JBlock
Insert a local variable declaration at this point with a generated name.
-
tempVar
public JExpr tempVar(JType type, JExpr value)
Description copied from interface:JBlock
Insert a local variable declaration at this point with a generated name.
-
tempVar
public JExpr tempVar(java.lang.Class<?> type, JExpr value)
Description copied from interface:JBlock
Insert a local variable declaration at this point with a generated name.
-
tempName
public java.lang.String tempName()
Description copied from interface:JBlock
Generate a temporary variable name.
-
getParent
BasicJBlock getParent()
-
size
int size()
-
get
BlockContent get(int idx)
-
write
void write(SourceFileWriter writer, FormatPreferences.Space beforeBrace) throws java.io.IOException
- Throws:
java.io.IOException
-
write
void write(SourceFileWriter writer, FormatPreferences.Space beforeBrace, JBlock.Braces braces) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(SourceFileWriter writer) throws java.io.IOException
-
hasSingleItemOfType
boolean hasSingleItemOfType(java.lang.Class<? extends BlockContent> type)
-
-