Class IfStmt

All Implemented Interfaces:
NodeWithCondition<IfStmt>, NodeWithRange<Node>, NodeWithTokenRange<Node>, Observable, Visitable, HasParentNode<Node>, Cloneable

public class IfStmt extends Statement implements NodeWithCondition<IfStmt>
An if-then-else statement. The else is optional.
In if(a==5) hurray() else boo(); the condition is a==5, hurray() is the thenStmt, and boo() is the elseStmt.
Author:
Julio Vilmar Gesser
  • Constructor Details

  • Method Details

    • accept

      public <R,​ A> R accept(GenericVisitor<R,​A> v, A arg)
      Description copied from interface: Visitable
      Accept method for visitor support.
      Specified by:
      accept in interface Visitable
      Type Parameters:
      R - the type of the return value of the visitor
      A - the type the user argument passed to the visitor
      Parameters:
      v - the visitor implementation
      arg - the argument passed to the visitor (of type A)
      Returns:
      the result of the visit (of type R)
    • accept

      public <A> void accept(VoidVisitor<A> v, A arg)
      Description copied from interface: Visitable
      Accept method for visitor support.
      Specified by:
      accept in interface Visitable
      Type Parameters:
      A - the type the argument passed for the visitor
      Parameters:
      v - the visitor implementation
      arg - any value relevant for the visitor (of type A)
    • getCondition

      public Expression getCondition()
      Specified by:
      getCondition in interface NodeWithCondition<IfStmt>
    • getElseStmt

      public Optional<Statement> getElseStmt()
    • getThenStmt

      public Statement getThenStmt()
    • setCondition

      public IfStmt setCondition(Expression condition)
      Specified by:
      setCondition in interface NodeWithCondition<IfStmt>
    • setElseStmt

      public IfStmt setElseStmt(Statement elseStmt)
      Sets the elseStmt
      Parameters:
      elseStmt - the elseStmt, can be null
      Returns:
      this, the IfStmt
    • setThenStmt

      public IfStmt setThenStmt(Statement thenStmt)
    • remove

      public boolean remove(Node node)
      Overrides:
      remove in class Node
    • removeElseStmt

      public IfStmt removeElseStmt()
    • hasThenBlock

      public boolean hasThenBlock()
      This method returns true if the then branch (which should be always present) is a block statement.
    • hasElseBlock

      public boolean hasElseBlock()
      This method returns true if the If Statement has an else branch and that branch is a block statement.
    • hasCascadingIfStmt

      public boolean hasCascadingIfStmt()
      This method returns true if the If Statement has an else branch and that branch is another If Statement.
    • hasElseBranch

      public boolean hasElseBranch()
      This method returns true if the If Statement has an else branch.
    • clone

      public IfStmt clone()
      Overrides:
      clone in class Statement
    • getMetaModel

      public IfStmtMetaModel getMetaModel()
      Overrides:
      getMetaModel in class Statement
      Returns:
      get JavaParser specific node introspection information.
    • replace

      public boolean replace(Node node, Node replacementNode)
      Overrides:
      replace in class Node
    • isIfStmt

      public boolean isIfStmt()
      Overrides:
      isIfStmt in class Statement
    • asIfStmt

      public IfStmt asIfStmt()
      Overrides:
      asIfStmt in class Statement
    • ifIfStmt

      public void ifIfStmt(Consumer<IfStmt> action)
      Overrides:
      ifIfStmt in class Statement
    • toIfStmt

      public Optional<IfStmt> toIfStmt()
      Overrides:
      toIfStmt in class Statement