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()
    • get

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

      IJavaStatement getLast()
      Returns:
    • 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()
      Returns:
    • removeMultiple

      void removeMultiple(int index, int cnt)
      Parameters:
      index -
      cnt -
    • removeRange

      void removeRange(int from, int to)
      Parameters:
      from -
      to -
    • 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)
    • insertMultiple

      void insertMultiple(int index, IJavaBlock src, int start, int end, boolean removeSourceStatements)
    • addMultiple

      void addMultiple(IJavaBlock src, int start, int end, boolean removeSourceStatements)
    • clear

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

      void generateBody(JavaOutputSink out)
    • generateBody

      void generateBody(JavaOutputSink out, boolean expectLambdaExpression)
      Raw body generation, the caller is responsible for calling generateEnter/generateExit
      Parameters:
      out -
      expectLambdaExpression -
    • generateHeader

      void generateHeader(JavaOutputSink out)
    • generateFooter

      void generateFooter(JavaOutputSink out)
    • 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