public interface

IJavaIf

implements IJavaCompound
com.pnfsoftware.jeb.core.units.code.java.IJavaIf

Class Overview

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
 

Summary

[Expand]
Inherited Constants
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
Public Methods
abstract void addBranch(IJavaPredicate p, IJavaBlock b)
Add an alternative block (if or else-if) to this element.
abstract IJavaIf duplicate()
Duplicate this element.
abstract IJavaBlock getBranchBody(int index)
Get a branch (if, else-if) body.
abstract IJavaPredicate getBranchPredicate(int index)
Get a branch (if, else-if) predicate.
abstract List<IJavaPredicate> getBranchPredicates()
Get the predicates.
abstract IJavaBlock getDefaultBlock()
Get the default branch (else) body, if any.
abstract boolean hasDefaultBlock()
Determine whether that if-statement has a default block.
abstract void insertBranch(int index, IJavaPredicate p, IJavaBlock b)
Insert a branch (if, else-if) to this statement.
abstract void removeBranch(int index)
Remove a branch from this statement.
abstract void setBranchBody(int index, IJavaBlock b)
Set a branch (if, else-if) body.
abstract void setBranchPredicate(int index, IJavaPredicate p)
Set a branch (if, else-if) predicate.
abstract IJavaBlock setDefaultBlock(IJavaBlock b)
Set the default 'else' block.
abstract int size()
Get the number of branches, including the default (else) branch, if any.
abstract int sizeWithoutDefault()
Return the number of blocks (if, else-ifs), NOT counting the else block if there is one.
[Expand]
Inherited Methods
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaCompound
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaExpression
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaStatement

Public Methods

public abstract void addBranch (IJavaPredicate p, IJavaBlock b)

Add an alternative block (if or else-if) to this element.

Parameters
p mandatory predicate
b mandatory statement

public abstract IJavaIf duplicate ()

Duplicate this element.

Returns
  • a (possibly) duplicated object of the same type

public abstract 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

public abstract 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

public abstract 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

public abstract IJavaBlock getDefaultBlock ()

Get the default branch (else) body, if any.

Returns
  • the default branch body, null if there is none

public abstract boolean hasDefaultBlock ()

Determine whether that if-statement has a default block.

Returns
  • true if the if-statement has an else block

public abstract 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

public abstract void removeBranch (int index)

Remove a branch from this statement.

Parameters
index 0-based branch index

public abstract void setBranchBody (int index, IJavaBlock b)

Set a branch (if, else-if) body.

Parameters
index 0-based branch index
b mandatory body

public abstract void setBranchPredicate (int index, IJavaPredicate p)

Set a branch (if, else-if) predicate.

Parameters
index 0-based branch index
p mandatory predicate

public abstract IJavaBlock setDefaultBlock (IJavaBlock b)

Set the default 'else' block.

Parameters
b new default block, null for none
Returns
  • the previous default block

public abstract int size ()

Get the number of branches, including the default (else) branch, if any.

Returns
  • the number of branches

public abstract int sizeWithoutDefault ()

Return the number of blocks (if, else-ifs), NOT counting the else block if there is one.