Class BaseBlock

All Implemented Interfaces:
io.github.mmm.code.api.block.CodeBlock, io.github.mmm.code.api.CodeWithContext, io.github.mmm.code.api.item.CodeItem, io.github.mmm.code.api.item.CodeItemWithVariables, io.github.mmm.code.api.item.CodeMutableItem, io.github.mmm.code.api.node.CodeNode, io.github.mmm.code.api.node.CodeNodeItem, io.github.mmm.code.api.object.CodeMutable
Direct Known Subclasses:
BaseBlockBody, BaseBlockInitializer, BaseBlockStatement

public abstract class BaseBlock extends BaseNodeItem implements io.github.mmm.code.api.block.CodeBlock
Base implementation of CodeBlock.
Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
  • Constructor Details

    • BaseBlock

      public BaseBlock(io.github.mmm.code.api.statement.CodeStatement... statements)
      The constructor.
      Parameters:
      statements - the statements.
    • BaseBlock

      public BaseBlock(List<io.github.mmm.code.api.statement.CodeStatement> statements)
      The constructor.
      Parameters:
      statements - the statements.
    • BaseBlock

      public BaseBlock(BaseBlock template, io.github.mmm.code.api.copy.CodeCopyMapper mapper)
      The copy-constructor.
      Parameters:
      template - the BaseBlock to copy.
      mapper - the CodeCopyMapper.
  • Method Details

    • getVariable

      public io.github.mmm.code.api.expression.CodeVariable getVariable(String name)
      Specified by:
      getVariable in interface io.github.mmm.code.api.block.CodeBlock
      Specified by:
      getVariable in interface io.github.mmm.code.api.item.CodeItemWithVariables
    • getVariable

      public io.github.mmm.code.api.expression.CodeVariable getVariable(String name, int statementIndex)
      Specified by:
      getVariable in interface io.github.mmm.code.api.block.CodeBlock
    • getVariableFromParent

      protected abstract io.github.mmm.code.api.expression.CodeVariable getVariableFromParent(String name)
      Parameters:
      name - the name of the requested CodeVariable.
      Returns:
      the CodeVariable declared by the parent node with the given name or null if not found.
    • doSetImmutable

      protected void doSetImmutable()
      Description copied from class: BaseMutableItem
      Called on the first call of BaseMutableItem.setImmutable(). Has to be overridden to update Collections, make child items immutable, etc.
      Overrides:
      doSetImmutable in class BaseMutableItem
    • getStatements

      public List<io.github.mmm.code.api.statement.CodeStatement> getStatements()
      Specified by:
      getStatements in interface io.github.mmm.code.api.block.CodeBlock
    • add

      public void add(io.github.mmm.code.api.statement.CodeStatement... codeStatements)
      Specified by:
      add in interface io.github.mmm.code.api.block.CodeBlock
    • addText

      public void addText(String... textStatements)
      Specified by:
      addText in interface io.github.mmm.code.api.block.CodeBlock
    • doWrite

      protected void doWrite(Appendable sink, String newline, String defaultIndent, String currentIndent, io.github.mmm.code.api.language.CodeLanguage language) throws IOException
      Specified by:
      doWrite in class BaseItem
      Parameters:
      sink - the Appendable where to append the code from this CodeItem.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      language - the CodeLanguage to use.
      Throws:
      IOException - if thrown by Appendable.
      See Also:
      • CodeItem.write(Appendable, String, String)
    • writePrefix

      protected void writePrefix(Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes a prefix e.g. for loops.
      Parameters:
      sink - the Appendable where to append the code from this CodeItem.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the indent will be appended.
      Throws:
      IOException - if thrown by Appendable.
    • writeSuffix

      protected void writeSuffix(Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes a suffix e.g. for do-while loops.
      Parameters:
      sink - the Appendable where to append the code from this CodeItem.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the indent will be appended.
      Throws:
      IOException - if thrown by Appendable.