Class CtIfImpl

All Implemented Interfaces:
Serializable, Cloneable, FactoryAccessor, CtCodeElement, CtIf, CtStatement, SourcePositionHolder, CtElement, CtQueryable, CtVisitable, TemplateParameter<Void>

public class CtIfImpl extends CtStatementImpl implements CtIf
See Also:
Serialized Form
  • Constructor Details

    • CtIfImpl

      public CtIfImpl()
  • Method Details

    • accept

      public void accept(CtVisitor visitor)
      Description copied from interface: CtVisitable
      Accepts a visitor
      Specified by:
      accept in interface CtVisitable
    • getCondition

      public CtExpression<Boolean> getCondition()
      Description copied from interface: CtIf
      Gets the boolean expression that represents the if's condition.
      Specified by:
      getCondition in interface CtIf
    • getElseStatement

      public <S extends CtStatement> S getElseStatement()
      Description copied from interface: CtIf
      Gets the statement executed when the condition is false.

      An else if like

           if (a) {
               doA();
           } else if (b) {
               doB();
           } else {
               doC();
           }
       
      will be represented as
           if (a) {
               doA();
           } else {
               if (b) {
                   doB();
               } else {
                   doC();
               }
           }
       
      To differentiate between an else Block with an if and an else if, CtElement.isImplicit() is set to true.
      Specified by:
      getElseStatement in interface CtIf
      Returns:
      the statement of the else or null if no else is specified.
    • getThenStatement

      public <S extends CtStatement> S getThenStatement()
      Description copied from interface: CtIf
      Gets the statement executed when the condition is true.

      This method will return null for if (condition);.

      Specified by:
      getThenStatement in interface CtIf
      Returns:
      the statement of the if, in most cases this is a CtBlock.
    • setCondition

      public <T extends CtIf> T setCondition(CtExpression<Boolean> condition)
      Description copied from interface: CtIf
      Sets the boolean expression that represents the if's condition.
      Specified by:
      setCondition in interface CtIf
    • setElseStatement

      public <T extends CtIf> T setElseStatement(CtStatement elseStatement)
      Description copied from interface: CtIf
      Sets the statement executed when the condition is false.
      Specified by:
      setElseStatement in interface CtIf
    • setThenStatement

      public <T extends CtIf> T setThenStatement(CtStatement thenStatement)
      Description copied from interface: CtIf
      Sets the statement executed when the condition is true.
      Specified by:
      setThenStatement in interface CtIf
    • clone

      public CtIf clone()
      Description copied from interface: CtElement
      Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtCodeElement
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtIf
      Specified by:
      clone in interface CtStatement
      Overrides:
      clone in class CtStatementImpl
    • S

      public Void S()
      Description copied from interface: TemplateParameter
      Gets the type of the template parameter. This methods has no runtime meaning (should return a null reference) but is used as a marker in a template code.
      Specified by:
      S in interface TemplateParameter<Void>
    • getSubstitution

      public CtCodeElement getSubstitution(CtType<?> targetType)