Interface IJavaIf

All Superinterfaces:
IJavaCompound, IJavaElement, IJavaExpression, IJavaStatement

@Ser public interface IJavaIf extends IJavaCompound
Java AST interface to represent a conditional "if" statement.

An if-statement consists of one or more branches (if, else-if) followed by an optional default branch (else) block.

Example:

 if(p)
   b
 else if(p1)
   b1
 else
   b2
 
  • Method Details

    • size

      int size()
      Get the number of branches, including the default (else) branch, if any.
      Returns:
      the number of branches
    • sizeWithoutDefault

      int sizeWithoutDefault()
      Return the number of blocks (if, else-ifs), NOT counting the else block if there is one.
      Returns:
    • getBranchPredicate

      IJavaPredicate getBranchPredicate(int index)
      Get a branch (if, else-if) predicate.
      Parameters:
      index - 0-based branch index (0 for 'if', 1... for subsequent else-ifs)
      Returns:
      the predicate
    • getBranchPredicates

      List<IJavaPredicate> getBranchPredicates()
      Get the predicates. Warning, this is the actual list of predicates, not a copy. Caution should be exercised when modifying it
      Returns:
      the original list of predicates
    • getBranchBody

      IJavaBlock getBranchBody(int index)
      Get a branch (if, else-if) body.
      Parameters:
      index - 0-based branch index (0 for 'if', 1... for subsequent else-ifs)
      Returns:
      the body
    • getDefaultBlock

      IJavaBlock getDefaultBlock()
      Get the default branch (else) body, if any.
      Returns:
      the default branch body, null if there is none
    • hasDefaultBlock

      boolean hasDefaultBlock()
      Determine whether that if-statement has a default block.
      Returns:
      true if the if-statement has an else block
    • setBranchPredicate

      void setBranchPredicate(int index, IJavaPredicate p)
      Set a branch (if, else-if) predicate.
      Parameters:
      index - 0-based branch index
      p - mandatory predicate
    • setBranchBody

      void setBranchBody(int index, IJavaBlock b)
      Set a branch (if, else-if) body.
      Parameters:
      index - 0-based branch index
      b - mandatory body
    • setDefaultBlock

      IJavaBlock setDefaultBlock(IJavaBlock b)
      Set the default 'else' block.
      Parameters:
      b - new default block, null for none
      Returns:
      the previous default block
    • addBranch

      void addBranch(IJavaPredicate p, IJavaBlock b)
      Add an alternative block (if or else-if) to this element.
      Parameters:
      p - mandatory predicate
      b - mandatory statement
    • insertBranch

      void insertBranch(int index, IJavaPredicate p, IJavaBlock b)
      Insert a branch (if, else-if) to this statement.
      Parameters:
      index - 0-based branch index
      p - mandatory predicate
      b - mandatory body
    • removeBranch

      void removeBranch(int index)
      Remove a branch from this statement.
      Parameters:
      index - 0-based branch index
    • duplicate

      IJavaIf 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