示例#1
0
 @Override
 public <T extends CtStatementList> T addStatement(CtStatement statement) {
   ensureModifiableStatementsList();
   statement.setParent(this);
   this.statements.add(statement);
   return (T) this;
 }
示例#2
0
 @Override
 public <T extends CtContinue> T setLabelledStatement(CtStatement labelledStatement) {
   if (labelledStatement != null) {
     labelledStatement.setParent(this);
   }
   this.labelledStatement = labelledStatement;
   return (T) this;
 }
  @Override
  public void visitCtIf(CtIf ifElement) {
    // super.visitCtIf(ifElement);

    CtStatement ctThen = ifElement.getThenStatement();
    CtStatement ctElse = ifElement.getElseStatement();

    Mutability condMut = mutability(ifElement.getCondition());
    if (ctThen != null) ifElement.getThenStatement().accept(this);
    if (ctElse != null) ifElement.getElseStatement().accept(this);

    if (condMut == Mutability.ERASABLE && isEmpty(ctThen)) {
      // if ( - ) {  } else {  } <- Remove the whole if
      if (ctElse == null || isEmpty(ctElse)) remove(ifElement);
      // else if case: if ( - ) {  } else if { doSomething() } <-- pull the else if element up
      else if (ctElse instanceof CtIf) ctElse.setParent(ifElement.getParent());
    }
  }