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.Bracesbracesprivate java.util.ArrayList<BlockContent>contentprivate BasicJBlockparentprivate inttmpId
-
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 anassertstatement at this point.JStatement_assert(JExpr expr, JExpr message)Insert anassertstatement at this point with a message.JStatement_break()Insert abreakstatement at this point.JStatement_break(JLabel label)Insert a labelledbreakstatement at this point.JClassDef_class(int mods, java.lang.String name)Insert a local class definition at this point.JStatement_continue()Insert acontinuestatement at this point.JStatement_continue(JLabel label)Insert a labelledcontinuestatement at this point.JBlock_do(JExpr cond)Insert ado/whilestatement at this point.JFor_for()Insert aforloop at this point.JIf_if(JExpr cond)Insert anifstatement 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 avoidreturnstatement at this point.JStatement_return(JExpr expr)Insert areturnstatement at this point.JSwitch_switch(JExpr expr)Insert aswitchstatement at this point.JBlock_synchronized(JExpr synchExpr)Insert asynchronizedblock at this point.JStatement_throw(JExpr expr)Insert athrowstatement at this point.JTry_try()Insert atryblock at this point.JBlock_while(JExpr cond)Insert awhilestatement at this point.JStatementadd(JExpr expr)Insert an expression statement at this point.private <T extends BlockContent>
Tadd(T s)JStatementaddAssign(JAssignableExpr target, JExpr e1)Insert an assignment (+=) expression at this point.JStatementandAssign(JAssignableExpr target, JExpr e1)Insert an assignment (&=) expression at this point.JLabelanonLabel()Add a label at this point whose unique name is automatically generated.JLabelanonLabel(JLabel label)Name and attach a forward label as anonymous.JStatementassign(JAssignableExpr target, JExpr e1)Insert an assignment (=) expression at this point.JBlockblankLine()Insert a blank line at this point.JBlockblock(JBlock.Braces braces)Create a nested sub-block at this point.JCallcall(java.lang.String name)Insert a method invocation at this point.JCallcall(javax.lang.model.element.ExecutableElement element)Insert a method invocation at this point.JCallcall(JExpr obj, java.lang.String name)Insert a method invocation at this point.JCallcall(JExpr obj, javax.lang.model.element.ExecutableElement element)Insert a method invocation at this point.JCallcallStatic(java.lang.Class<?> type, java.lang.String name)Insert a type-qualified static method invocation at this point.JCallcallStatic(java.lang.String type, java.lang.String name)Insert a type-qualified static method invocation at this point.JCallcallStatic(javax.lang.model.element.ExecutableElement element)Insert a type-qualified static method invocation at this point.JCallcallStatic(JType type, java.lang.String name)Insert a type-qualified static method invocation at this point.JCallcallSuper()Insert asuper()call at this point.JCallcallThis()Insert athis()call at this point.JStatementdivAssign(JAssignableExpr target, JExpr e1)Insert an assignment (/=) expression at this point.JStatementempty()Insert an empty statement at this point (just a semicolon).JBlockforEach(int mods, java.lang.Class<?> type, java.lang.String name, JExpr iterable)Insert a "for-each" styleforloop at this point.JBlockforEach(int mods, java.lang.String type, java.lang.String name, JExpr iterable)Insert a "for-each" styleforloop at this point.JBlockforEach(int mods, JType type, java.lang.String name, JExpr iterable)Insert a "for-each" styleforloop at this point.JLabelforwardLabel()Create a forward label that can be named and attached later.(package private) BlockContentget(int idx)(package private) BasicJBlockgetParent()(package private) booleanhasSingleItemOfType(java.lang.Class<? extends BlockContent> type)JLabellabel(java.lang.String name)Add a label at this point, which may be used for future branch instructions.JLabellabel(JLabel label, java.lang.String name)Name and attach a forward label.JStatementlshrAssign(JAssignableExpr target, JExpr e1)Insert an assignment (>>>=) expression at this point.JStatementmodAssign(JAssignableExpr target, JExpr e1)Insert an assignment (%=) expression at this point.JStatementmulAssign(JAssignableExpr target, JExpr e1)Insert an assignment (*=) expression at this point.JStatementorAssign(JAssignableExpr target, JExpr e1)Insert an assignment (|=) expression at this point.JStatementpostDec(JAssignableExpr target)Insert a postfix--expression at this point.JStatementpostInc(JAssignableExpr target)Insert a postfix++expression at this point.JStatementpreDec(JAssignableExpr target)Insert a prefix--expression at this point.JStatementpreInc(JAssignableExpr target)Insert a prefix++expression at this point.JStatementshlAssign(JAssignableExpr target, JExpr e1)Insert an assignment (<<=) expression at this point.JStatementshrAssign(JAssignableExpr target, JExpr e1)Insert an assignment (>>=) expression at this point.(package private) intsize()JStatementsubAssign(JAssignableExpr target, JExpr e1)Insert an assignment (-=) expression at this point.java.lang.StringtempName()Generate a temporary variable name.JExprtempVar(java.lang.Class<?> type, JExpr value)Insert a local variable declaration at this point with a generated name.JExprtempVar(java.lang.String type, JExpr value)Insert a local variable declaration at this point with a generated name.JExprtempVar(JType type, JExpr value)Insert a local variable declaration at this point with a generated name.JVarDeclarationvar(int mods, java.lang.Class<?> type, java.lang.String name)Insert a local variable declaration at this point.JVarDeclarationvar(int mods, java.lang.Class<?> type, java.lang.String name, JExpr value)Insert a local variable declaration at this point.JVarDeclarationvar(int mods, java.lang.String type, java.lang.String name)Insert a local variable declaration at this point.JVarDeclarationvar(int mods, java.lang.String type, java.lang.String name, JExpr value)Insert a local variable declaration at this point.JVarDeclarationvar(int mods, JType type, java.lang.String name)Insert a local variable declaration at this point.JVarDeclarationvar(int mods, JType type, java.lang.String name, JExpr value)Insert a local variable declaration at this point.voidwrite(SourceFileWriter writer)(package private) voidwrite(SourceFileWriter writer, FormatPreferences.Space beforeBrace)(package private) voidwrite(SourceFileWriter writer, FormatPreferences.Space beforeBrace, JBlock.Braces braces)JStatementxorAssign(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:JBlockInsert a blank line at this point.
-
block
public JBlock block(JBlock.Braces braces)
Description copied from interface:JBlockCreate a nested sub-block at this point.
-
_if
public JIf _if(JExpr cond)
Description copied from interface:JBlockInsert anifstatement at this point.
-
_while
public JBlock _while(JExpr cond)
Description copied from interface:JBlockInsert awhilestatement at this point.
-
_do
public JBlock _do(JExpr cond)
Description copied from interface:JBlockInsert ado/whilestatement at this point.
-
label
public JLabel label(java.lang.String name)
Description copied from interface:JBlockAdd a label at this point, which may be used for future branch instructions.
-
anonLabel
public JLabel anonLabel()
Description copied from interface:JBlockAdd a label at this point whose unique name is automatically generated.
-
forwardLabel
public JLabel forwardLabel()
Description copied from interface:JBlockCreate a forward label that can be named and attached later.- Specified by:
forwardLabelin interfaceJBlock- Returns:
- the forward label
-
label
public JLabel label(JLabel label, java.lang.String name)
Description copied from interface:JBlockName and attach a forward label.
-
anonLabel
public JLabel anonLabel(JLabel label)
Description copied from interface:JBlockName and attach a forward label as anonymous.
-
_continue
public JStatement _continue()
Description copied from interface:JBlockInsert acontinuestatement at this point.
-
_continue
public JStatement _continue(JLabel label)
Description copied from interface:JBlockInsert a labelledcontinuestatement at this point.
-
_break
public JStatement _break()
Description copied from interface:JBlockInsert abreakstatement at this point.
-
_break
public JStatement _break(JLabel label)
Description copied from interface:JBlockInsert a labelledbreakstatement at this point.
-
forEach
public JBlock forEach(int mods, java.lang.String type, java.lang.String name, JExpr iterable)
Description copied from interface:JBlockInsert a "for-each" styleforloop at this point.
-
forEach
public JBlock forEach(int mods, JType type, java.lang.String name, JExpr iterable)
Description copied from interface:JBlockInsert a "for-each" styleforloop at this point.
-
forEach
public JBlock forEach(int mods, java.lang.Class<?> type, java.lang.String name, JExpr iterable)
Description copied from interface:JBlockInsert a "for-each" styleforloop at this point.
-
_switch
public JSwitch _switch(JExpr expr)
Description copied from interface:JBlockInsert aswitchstatement at this point.
-
_return
public JStatement _return(JExpr expr)
Description copied from interface:JBlockInsert areturnstatement at this point.
-
_return
public JStatement _return()
Description copied from interface:JBlockInsert avoidreturnstatement at this point.
-
_assert
public JStatement _assert(JExpr expr)
Description copied from interface:JBlockInsert anassertstatement at this point.
-
_assert
public JStatement _assert(JExpr expr, JExpr message)
Description copied from interface:JBlockInsert anassertstatement at this point with a message.
-
callThis
public JCall callThis()
Description copied from interface:JBlockInsert athis()call at this point.
-
callSuper
public JCall callSuper()
Description copied from interface:JBlockInsert asuper()call at this point.
-
add
public JStatement add(JExpr expr)
Description copied from interface:JBlockInsert 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:JBlockInsert 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:JBlockInsert a method invocation at this point.
-
call
public JCall call(java.lang.String name)
Description copied from interface:JBlockInsert 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:JBlockInsert a method invocation at this point.
-
callStatic
public JCall callStatic(javax.lang.model.element.ExecutableElement element)
Description copied from interface:JBlockInsert a type-qualified static method invocation at this point.- Specified by:
callStaticin 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:JBlockInsert a type-qualified static method invocation at this point.- Specified by:
callStaticin 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:JBlockInsert a type-qualified static method invocation at this point.- Specified by:
callStaticin 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:JBlockInsert a type-qualified static method invocation at this point.- Specified by:
callStaticin 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:JBlockInsert an object construction statement at this point.
-
_new
public JCall _new(JType type)
Description copied from interface:JBlockInsert an object construction statement at this point.
-
_new
public JCall _new(java.lang.Class<?> type)
Description copied from interface:JBlockInsert an object construction statement at this point.
-
_newAnon
public JAnonymousClassDef _newAnon(java.lang.String type)
Description copied from interface:JBlockInsert an object construction statement for an anonymous class at this point.
-
_newAnon
public JAnonymousClassDef _newAnon(JType type)
Description copied from interface:JBlockInsert an object construction statement for an anonymous class at this point.
-
_newAnon
public JAnonymousClassDef _newAnon(java.lang.Class<?> type)
Description copied from interface:JBlockInsert 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:JBlockInsert a local class definition at this point.
-
_synchronized
public JBlock _synchronized(JExpr synchExpr)
Description copied from interface:JBlockInsert asynchronizedblock at this point.- Specified by:
_synchronizedin interfaceJBlock- Parameters:
synchExpr- the lock expression- Returns:
- the
synchronizedblock
-
assign
public JStatement assign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (=) expression at this point.
-
addAssign
public JStatement addAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (+=) expression at this point.
-
subAssign
public JStatement subAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (-=) expression at this point.
-
mulAssign
public JStatement mulAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (*=) expression at this point.
-
divAssign
public JStatement divAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (/=) expression at this point.
-
modAssign
public JStatement modAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (%=) expression at this point.
-
andAssign
public JStatement andAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (&=) expression at this point.
-
orAssign
public JStatement orAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (|=) expression at this point.
-
xorAssign
public JStatement xorAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (^=) expression at this point.
-
shrAssign
public JStatement shrAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (>>=) expression at this point.
-
lshrAssign
public JStatement lshrAssign(JAssignableExpr target, JExpr e1)
Description copied from interface:JBlockInsert an assignment (>>>=) expression at this point.- Specified by:
lshrAssignin 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:JBlockInsert an assignment (<<=) expression at this point.
-
postInc
public JStatement postInc(JAssignableExpr target)
Description copied from interface:JBlockInsert a postfix++expression at this point.
-
postDec
public JStatement postDec(JAssignableExpr target)
Description copied from interface:JBlockInsert a postfix--expression at this point.
-
preInc
public JStatement preInc(JAssignableExpr target)
Description copied from interface:JBlockInsert a prefix++expression at this point.
-
preDec
public JStatement preDec(JAssignableExpr target)
Description copied from interface:JBlockInsert a prefix--expression at this point.
-
empty
public JStatement empty()
Description copied from interface:JBlockInsert an empty statement at this point (just a semicolon).
-
_throw
public JStatement _throw(JExpr expr)
Description copied from interface:JBlockInsert athrowstatement at this point.
-
var
public JVarDeclaration var(int mods, java.lang.String type, java.lang.String name, JExpr value)
Description copied from interface:JBlockInsert 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:JBlockInsert 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:JBlockInsert 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:JBlockInsert a local variable declaration at this point.
-
var
public JVarDeclaration var(int mods, JType type, java.lang.String name)
Description copied from interface:JBlockInsert 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:JBlockInsert a local variable declaration at this point.
-
tempVar
public JExpr tempVar(java.lang.String type, JExpr value)
Description copied from interface:JBlockInsert a local variable declaration at this point with a generated name.
-
tempVar
public JExpr tempVar(JType type, JExpr value)
Description copied from interface:JBlockInsert 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:JBlockInsert a local variable declaration at this point with a generated name.
-
tempName
public java.lang.String tempName()
Description copied from interface:JBlockGenerate 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)
-
-