Interface CodeBlock
- All Superinterfaces:
CodeItem, CodeItemWithVariables, CodeMutable, CodeMutableItem, CodeNode, CodeNodeItem, CodeWithContext
- All Known Subinterfaces:
CodeBlockBody, CodeBlockDoWhile, CodeBlockFor, CodeBlockIf, CodeBlockInitializer, CodeBlockStatement, CodeBlockWhileDo, CodeBlockWithCondition
CodeStatement for a block that groups multiple statements.- Since:
- 1.0.0
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
-
Field Summary
Fields inherited from interface CodeItem
DEFAULT_INDENT, DEFAULT_NEWLINE -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(CodeStatement... statements) voidcopy()default CodeVariablegetVariable(String name) getVariable(String name, int statementMaxIndex) default booleanisEmpty()Methods inherited from interface CodeItem
getLanguage, getSourceCode, write, write, write, write, write, writeMethods inherited from interface CodeMutable
isImmutable, isMutableMethods inherited from interface CodeMutableItem
getReflectiveObject, setImmutableMethods inherited from interface CodeNodeItem
copyMethods inherited from interface CodeWithContext
getContext, getSource
-
Method Details
-
getVariable
- Specified by:
getVariablein interfaceCodeItemWithVariables- Parameters:
name- thenameof the requestedCodeVariable.- Returns:
- the
CodeVariablewith the givennameornullif not found.
-
getVariable
- Parameters:
name- thenameof the requestedCodeVariable.statementMaxIndex- the maximum index in thestatementswhere to resolve theCodeVariable. Therefore aCodeLocalVariabledefined by astatementafter the given index will not be considered.- Returns:
- the
CodeVariablewith the givennameornullif not found.
-
getStatements
List<CodeStatement> getStatements()- Returns:
- the
ListofCodeStatementcontained inside the block (typically within curly braces). May beemptybut nevernull.
-
isEmpty
default boolean isEmpty()- Returns:
trueif empty,falseotherwise.
-
add
- Parameters:
statements- theCodeStatements to add.- Throws:
io.github.mmm.base.exception.ReadOnlyException- ifimmutable.
-
addText
- Parameters:
statements- the plain textual statements to add asCodeStatements.- Throws:
io.github.mmm.base.exception.ReadOnlyException- ifimmutable.
-
copy
CodeBlock copy()- Specified by:
copyin interfaceCodeMutableItem- Specified by:
copyin interfaceCodeNodeItem- Returns:
- a new
mutablecopy of thisCodeMutableItem. Will be a deep-copy with copies of all childCodeMutableItems.
-