Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.Statement


      this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.UNMODIFIABLE_TRAILING_COMMENT);
  }
  private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) {
    int statementsLength = statements.length;
    for (int i = 0; i < statementsLength; i++) {
      final Statement statement = statements[i];
      if (i > 0 && (statements[i - 1] instanceof EmptyStatement) && !(statement instanceof EmptyStatement)) {
        this.scribe.printNewLine();
      }
      statement.traverse(this, scope);
      if (statement instanceof Expression) {
        this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        if (i != statementsLength - 1) {
          if (!(statement instanceof EmptyStatement) && !(statements[i + 1] instanceof EmptyStatement)) {
View Full Code Here


  public boolean visit(DoStatement doStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNamedo);
    final int line = this.scribe.line;

    final Statement action = doStatement.action;
    if (action != null) {
      if (action instanceof Block) {
        formatLeftCurlyBrace(line, this.preferences.brace_position_for_block);
        action.traverse(this, scope);
      } else if (action instanceof EmptyStatement) {
        /*
         * This is an empty statement
         */
        formatNecessaryEmptyStatement();
      } else {
        this.scribe.printNewLine();
        this.scribe.indent();
        action.traverse(this, scope);
        if (action instanceof Expression) {
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        }
        this.scribe.printNewLine();
View Full Code Here

    }
    forStatement.collection.traverse(this, scope);

    this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_for);

    final Statement action = forStatement.action;
    if (action != null) {
      if (action instanceof Block) {
        formatLeftCurlyBrace(line, this.preferences.brace_position_for_block);
        action.traverse(this, scope);
      } else if (action instanceof EmptyStatement) {
        /*
         * This is an empty statement
         */
        formatNecessaryEmptyStatement();
      } else {
        this.scribe.indent();
        this.scribe.printNewLine();
        action.traverse(this, scope);
        this.scribe.unIndent();
      }
      if (action instanceof Expression) {
        this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
View Full Code Here

        }
      }
    }
    this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_for);

    final Statement action = forStatement.action;
    if (action != null) {
      if (action instanceof Block) {
        formatLeftCurlyBrace(line, this.preferences.brace_position_for_block);
        action.traverse(this, scope);
      } else if (action instanceof EmptyStatement) {
        /*
         * This is an empty statement
         */
        formatNecessaryEmptyStatement();
      } else {
        this.scribe.indent();
        this.scribe.printNewLine();
        action.traverse(this, scope);
        this.scribe.unIndent();
      }
      if (action instanceof Expression) {
        this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
View Full Code Here

      this.scribe.space();
    }
    ifStatement.condition.traverse(this, scope);
    this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_if);

    final Statement thenStatement = ifStatement.thenStatement;
    final Statement elseStatement = ifStatement.elseStatement;

    boolean thenStatementIsBlock = false;
    if (thenStatement != null) {
      if (thenStatement instanceof Block) {
        thenStatementIsBlock = true;
        if (isGuardClause((Block)thenStatement) && elseStatement == null && this.preferences.keep_guardian_clause_on_one_line) {
          /*
           * Need a specific formatting for guard clauses
           * guard clauses are block with a single return or throw
           * statement
           */
           formatGuardClauseBlock((Block) thenStatement, scope);
        } else {
          formatLeftCurlyBrace(line, this.preferences.brace_position_for_block);
          thenStatement.traverse(this, scope);
          if (elseStatement != null && (this.preferences.insert_new_line_before_else_in_if_statement)) {
            this.scribe.printNewLine();
          }
        }
      } else if (elseStatement == null && this.preferences.keep_simple_if_on_one_line) {
        Alignment compactIfAlignment = this.scribe.createAlignment(
            Alignment.COMPACT_IF,
            this.preferences.alignment_for_compact_if,
            Alignment.R_OUTERMOST,
            1,
            this.scribe.scanner.currentPosition,
            1,
            false);
        this.scribe.enterAlignment(compactIfAlignment);
        boolean ok = false;
        do {
          try {
            this.scribe.alignFragment(compactIfAlignment, 0);
            this.scribe.space();
            thenStatement.traverse(this, scope);
            if (thenStatement instanceof Expression) {
              this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
              this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
            }
            ok = true;
          } catch (AlignmentException e) {
            this.scribe.redoAlignment(e);
          }
        } while (!ok);
        this.scribe.exitAlignment(compactIfAlignment, true);
      } else if (this.preferences.keep_then_statement_on_same_line) {
        this.scribe.space();
        thenStatement.traverse(this, scope);
        if (thenStatement instanceof Expression) {
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        }
        if (elseStatement != null) {
          this.scribe.printNewLine();
        }
      } else {
        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        this.scribe.printNewLine();
        this.scribe.indent();
        thenStatement.traverse(this, scope);
        if (thenStatement instanceof Expression) {
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        }
        if (elseStatement != null) {
          this.scribe.printNewLine();
        }
        this.scribe.unIndent();
      }
    }

    if (elseStatement != null) {
      if (thenStatementIsBlock) {
        this.scribe.printNextToken(TerminalTokens.TokenNameelse, this.preferences.insert_space_after_closing_brace_in_block, Scribe.PRESERVE_EMPTY_LINES_BEFORE_ELSE);
      } else {
        this.scribe.printNextToken(TerminalTokens.TokenNameelse, true, Scribe.PRESERVE_EMPTY_LINES_BEFORE_ELSE);
      }
      if (elseStatement instanceof Block) {
        elseStatement.traverse(this, scope);
      } else if (elseStatement instanceof IfStatement) {
        if (!this.preferences.compact_else_if) {
          this.scribe.printNewLine();
          this.scribe.indent();
        }
        this.scribe.space();
        elseStatement.traverse(this, scope);
        if (!this.preferences.compact_else_if) {
          this.scribe.unIndent();
        }
      } else if (this.preferences.keep_else_statement_on_same_line) {
        this.scribe.space();
        elseStatement.traverse(this, scope);
        if (elseStatement instanceof Expression) {
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        }
      } else {
        this.scribe.printNewLine();
        this.scribe.indent();
        elseStatement.traverse(this, scope);
        if (elseStatement instanceof Expression) {
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        }
        this.scribe.unIndent();
View Full Code Here

      this.scribe.space();
    }
    if (this.preferences.insert_new_line_after_label) {
      this.scribe.printNewLine();
    }
    final Statement statement = labeledStatement.statement;
    statement.traverse(this, scope);
    if (statement instanceof Expression) {
      this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
      this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
    }
    return false;
View Full Code Here

    boolean wasACase = false;
    boolean wasABreak = false;
    if (statements != null) {
      int statementsLength = statements.length;
      for (int i = 0; i < statementsLength; i++) {
        final Statement statement = statements[i];
        if (statement instanceof CaseStatement) {
          if (wasABreak) {
            this.scribe.setIndentation(switchIndentationLevel, caseIndentation);
            this.scribe.printComment();
          } else {
            if (wasACase) {
              this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_SWITCH_CASE);
            } else {
              this.scribe.printComment();
            }
            this.scribe.setIndentation(switchIndentationLevel, caseIndentation);
          }
          if (wasACase) {
            this.scribe.printNewLine();
          }
          statement.traverse(this, scope);
          // Print following trailing (if any) comment at statement indentation
          this.scribe.setIndentation(switchIndentationLevel, statementIndentation);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.COMPLEX_TRAILING_COMMENT);
          wasACase = true;
          wasABreak = false;
        } else if (statement instanceof BreakStatement) {
          this.scribe.setIndentation(switchIndentationLevel, breakIndentation);
          if (wasACase) {
            this.scribe.printNewLine();
          }
          this.scribe.printComment();
          statement.traverse(this, scope);
          wasACase = false;
          wasABreak = true;
        } else if (statement instanceof Block) {
          this.scribe.setIndentation(switchIndentationLevel, wasACase ? caseIndentation : statementIndentation);
          this.scribe.printComment();
          String bracePosition = wasACase ? this.preferences.brace_position_for_block_in_case : this.preferences.brace_position_for_block;
          formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_before_opening_brace_in_block);
          wasACase = false;
          wasABreak = false;
        } else {
          this.scribe.setIndentation(switchIndentationLevel, statementIndentation);
          this.scribe.printNewLine();
          this.scribe.printComment();
          statement.traverse(this, scope);
          wasACase = false;
          wasABreak = false;
        }
        if (statement instanceof Expression) {
          /*
 
View Full Code Here

    }
    whileStatement.condition.traverse(this, scope);

    this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_while);

    final Statement action = whileStatement.action;
    if (action != null) {
      if (action instanceof Block) {
        formatLeftCurlyBrace(line, this.preferences.brace_position_for_block);
        action.traverse(this, scope);
      } else if (action instanceof EmptyStatement) {
        /*
         * This is an empty statement
         */
        formatNecessaryEmptyStatement();
      } else {
        this.scribe.printNewLine();
        this.scribe.indent();
        action.traverse(this, scope);
        if (action instanceof Expression) {
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
        }
        this.scribe.unIndent();
View Full Code Here

        }

        // user code (finally!)
        if (x.statements != null) {
          for (int i = 0, n = x.statements.length; i < n; ++i) {
            Statement origStmt = x.statements[i];
            JStatement jstmt = dispProcessStatement(origStmt);
            if (jstmt != null) {
              ctor.body.statements.add(jstmt);
            }
          }
View Full Code Here

        currentMethod = method;
        currentMethodScope = x.scope;

        if (x.statements != null) {
          for (int i = 0, n = x.statements.length; i < n; ++i) {
            Statement origStmt = x.statements[i];
            JStatement jstmt = dispProcessStatement(origStmt);
            if (jstmt != null) {
              method.body.statements.add(jstmt);
            }
          }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.