Interface IJavaBlock

All Superinterfaces:
IJavaCompound, IJavaElement, IJavaExpression, IJavaStatement, Iterable<IJavaStatement>

@Ser public interface IJavaBlock extends IJavaCompound, Iterable<IJavaStatement>
Java AST interface to represent a sequence of statements.

Example:

 {
     stm0;
     stm1;
     stm2;
 }
 

Statements cannot be null. An exception will be raised if an attempt to insert a null statement is made.

  • Method Details

    • size

      int size()
      Get the number of statements in this block.

      Note: Compound statements count for a single statement.

      Returns:
      the number of statements
    • isEmpty

      boolean isEmpty()
      Determine whether this block contains no statements.
      Returns:
      true if this block is empty
    • get

      IJavaStatement get(int index)
      Get the statement at a given index.
      Parameters:
      index - 0-based statement index
      Returns:
      the statement
    • getLast

      IJavaStatement getLast()
      Get the last statement from the block.
      Returns:
      the non-null statement
    • set

      void set(int index, IJavaStatement stm)
      Replace a statement by another statement.
      Parameters:
      index - 0-based statement index
      stm - mandatory statement
    • remove

      IJavaStatement remove(int index)
      Pull a statement from the block.
      Parameters:
      index - 0-based statement index
      Returns:
      the removed statement
    • removeLast

      IJavaStatement removeLast()
      Pull the last statement from the block.
      Returns:
      the removed statement
    • removeMultiple

      void removeMultiple(int index, int cnt)
      Remove multiple statements from the block.
      Parameters:
      index - 0-based index of the first statement to remove
      cnt - number of statements to remove
    • removeRange

      void removeRange(int from, int to)
      Remove a range of statements from the block.
      Parameters:
      from - 0-based index of the first statement to remove
      to - 0-based exclusive end index
    • remove

      boolean remove(IJavaStatement stm)
      Remove a statement from the block. Does not throw if the statement is not found.
      Parameters:
      stm - mandatory statement
      Returns:
      success indicator
    • add

      void add(IJavaStatement stm)
      Append a statement to this block.
      Parameters:
      stm - mandatory statement to be appended
    • insert

      void insert(int index, IJavaStatement stm)
      Insert a statement at the given index.
      Parameters:
      index - 0-based statement index
      stm - mandatory statement to be inserted
    • insertAll

      void insertAll(int index, IJavaBlock b)
      Insert all statements of another block in this block.
      Parameters:
      index - 0-based index
      b - mandatory block
    • addAll

      void addAll(IJavaBlock b)
      Append all statements of another block to this block.
      Parameters:
      b - mandatory source block
    • insertMultiple

      void insertMultiple(int index, IJavaBlock src, int start, int end, boolean removeSourceStatements)
      Insert a range of statements from another block.
      Parameters:
      index - insertion index
      src - source block
      start - source start index, inclusive
      end - source end index, exclusive
      removeSourceStatements - true to remove transferred statements from the source block
    • addMultiple

      void addMultiple(IJavaBlock src, int start, int end, boolean removeSourceStatements)
      Append a range of statements from another block.
      Parameters:
      src - source block
      start - source start index, inclusive
      end - source end index, exclusive
      removeSourceStatements - true to remove transferred statements from the source block
    • clear

      void clear()
      Remove all statements of the block, making the block effectively empty: {}
    • generateBody

      void generateBody(JavaOutputSink out)
      Generate this block body.
      Parameters:
      out - output sink
    • generateBody

      void generateBody(JavaOutputSink out, boolean expectLambdaExpression)
      Raw body generation, the caller is responsible for calling generateEnter/generateExit
      Parameters:
      out - output sink
      expectLambdaExpression - true if a lambda expression is expected
    • generateHeader

      void generateHeader(JavaOutputSink out)
      Generate this block header.
      Parameters:
      out - output sink
    • generateFooter

      void generateFooter(JavaOutputSink out)
      Generate this block footer.
      Parameters:
      out - output sink
    • duplicate

      IJavaBlock duplicate()
      Description copied from interface: IJavaElement
      Duplicate this element.
      Specified by:
      duplicate in interface IJavaCompound
      Specified by:
      duplicate in interface IJavaElement
      Specified by:
      duplicate in interface IJavaExpression
      Specified by:
      duplicate in interface IJavaStatement
      Returns:
      a (possibly) duplicated object of the same type