Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.IfStatement


     *
     * @param expr conditional expression
     * @param ifblock block executed when condition <code>true</code>
     */
    public void addIfStatement(ExpressionBuilderBase expr, BlockBuilder ifblock) {
        IfStatement ifstmt = m_ast.newIfStatement();
        ifstmt.setExpression(expr.getExpression());
        ifstmt.setThenStatement(ifblock.m_block);
        m_block.statements().add(ifstmt);
    }
View Full Code Here


     * @param expr conditional expression
     * @param ifblock block executed when condition <code>true</code>
     * @param elseblock block executed when condition <code>false</code>
     */
    public void addIfElseStatement(ExpressionBuilderBase expr, BlockBuilder ifblock, BlockBuilder elseblock) {
        IfStatement ifstmt = m_ast.newIfStatement();
        ifstmt.setExpression(expr.getExpression());
        ifstmt.setThenStatement(ifblock.m_block);
        ifstmt.setElseStatement(elseblock.m_block);
        m_block.statements().add(ifstmt);
    }
View Full Code Here

     * @param ifblock block executed when condition <code>true</code>
     * @param elseblock block executed when condition <code>false</code>
     */
    public void addIfElseIfStatement(ExpressionBuilderBase ifexpr, ExpressionBuilderBase elsexpr, BlockBuilder ifblock,
        BlockBuilder elseblock) {
        IfStatement ifstmt = m_ast.newIfStatement();
        ifstmt.setExpression(ifexpr.getExpression());
        ifstmt.setThenStatement(ifblock.m_block);
        IfStatement elseifstmt = m_ast.newIfStatement();
        elseifstmt.setExpression(elsexpr.getExpression());
        elseifstmt.setThenStatement(elseblock.m_block);
        ifstmt.setElseStatement(elseifstmt);
        m_block.statements().add(ifstmt);
    }
View Full Code Here

    Block body = md.getBody();
    List statements = body.statements();
    if (!adapter.isRoot()&&!statements.isEmpty()) {
      Object firstStatement = statements.get(0);
      if (firstStatement instanceof IfStatement) {
        IfStatement ifstatement = (IfStatement) firstStatement;
        Statement thenstatement = ifstatement.getThenStatement();
        if (thenstatement instanceof Block) {
          statements = ((Block) thenstatement).statements();
        }
      }
    }
View Full Code Here

        Block body = getMethod.getBody();
        statements = body.statements();
        if (!statements.isEmpty()) {
          Object first = statements.get(0);
          if (first instanceof IfStatement) {
            IfStatement ifs = (IfStatement) statements.get(0);
            Statement thenstmt = ifs.getThenStatement();
            if (thenstmt instanceof Block) {
              Block block = (Block) thenstmt;
              statements = block.statements();
            }
          }
View Full Code Here

                            methodName,
                            new Class[] { int.class, boolean.class }))) {
                body.statements().add(superRestoreStatement);
            } else {
                // Restore the previous checkpoint, if necessary.
                IfStatement restoreCheckpoint = ast.newIfStatement();

                InfixExpression timestampTester = ast.newInfixExpression();
                timestampTester.setLeftOperand(ast.newSimpleName("timestamp"));
                timestampTester
                        .setOperator(InfixExpression.Operator.LESS_EQUALS);

                MethodInvocation topTimestamp = ast.newMethodInvocation();
                topTimestamp.setExpression(ast
                        .newSimpleName(CHECKPOINT_RECORD_NAME));
                topTimestamp.setName(ast.newSimpleName("getTopTimestamp"));
                timestampTester.setRightOperand(topTimestamp);
                restoreCheckpoint.setExpression(timestampTester);

                Block restoreBlock = ast.newBlock();
                restoreCheckpoint.setThenStatement(restoreBlock);

                // Assign the old checkpoint.
                Assignment assignCheckpoint = ast.newAssignment();
                assignCheckpoint.setLeftHandSide(ast
                        .newSimpleName(CHECKPOINT_NAME));
View Full Code Here

        test.setLeftOperand(condition1);
        test.setOperator(InfixExpression.Operator.CONDITIONAL_AND);
        test.setRightOperand(condition2);

        IfStatement ifStatement = ast.newIfStatement();
        ifStatement.setExpression(test);

        Block thenBranch = ast.newBlock();
        ifStatement.setThenStatement(thenBranch);

        MethodInvocation setCheckpoint = ast.newMethodInvocation();
        setCheckpoint.setExpression(ast.newSimpleName("newValue"));
        setCheckpoint.setName(ast.newSimpleName(SET_CHECKPOINT_NAME));
        setCheckpoint.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));
View Full Code Here

        method.setReturnType2(createType(ast, getClassName(Object.class, state,
                root)));

        if (!isInterface) {
            // The test.
            IfStatement test = ast.newIfStatement();
            InfixExpression testExpression = ast.newInfixExpression();
            testExpression.setLeftOperand(ast.newSimpleName(CHECKPOINT_NAME));
            testExpression.setOperator(InfixExpression.Operator.NOT_EQUALS);
            testExpression.setRightOperand(ast.newSimpleName("checkpoint"));
            test.setExpression(testExpression);

            // The "then" branch of the test.
            Block thenBranch = ast.newBlock();
            test.setThenStatement(thenBranch);

            Block body = ast.newBlock();
            body.statements().add(test);
            method.setBody(body);

            // Backup the old checkpoint.
            VariableDeclarationFragment fragment = ast
                    .newVariableDeclarationFragment();
            fragment.setName(ast.newSimpleName("oldCheckpoint"));
            fragment.setInitializer(ast.newSimpleName(CHECKPOINT_NAME));

            VariableDeclarationStatement tempDeclaration = ast
                    .newVariableDeclarationStatement(fragment);
            tempDeclaration.setType(createType(ast, checkpointType));
            thenBranch.statements().add(tempDeclaration);

            // Record the old checkpoint if the new checkpoint is not null.
            // If it is null, it is impossible to roll back to the previous
            // checkpoint.
            IfStatement testNewCheckpoint = ast.newIfStatement();
            InfixExpression testNull = ast.newInfixExpression();
            testNull.setLeftOperand(ast.newSimpleName("checkpoint"));
            testNull.setOperator(InfixExpression.Operator.NOT_EQUALS);
            testNull.setRightOperand(ast.newNullLiteral());
            testNewCheckpoint.setExpression(testNull);

            Block testNewCheckpointBody = ast.newBlock();
            testNewCheckpoint.setThenStatement(testNewCheckpointBody);

            MethodInvocation record = ast.newMethodInvocation();
            record.setExpression(ast.newSimpleName(CHECKPOINT_RECORD_NAME));
            record.setName(ast.newSimpleName("add"));
            record.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));
View Full Code Here

    private Block _createAssignmentBlock(AST ast, TypeAnalyzerState state,
            String fieldName, Type fieldType, int indices, boolean special) {
        Block block = ast.newBlock();

        // Test if the checkpoint object is not null.
        IfStatement ifStatement = ast.newIfStatement();
        InfixExpression testExpression = ast.newInfixExpression();

        InfixExpression condition1 = ast.newInfixExpression();
        condition1.setLeftOperand(ast.newSimpleName(CHECKPOINT_NAME));
        condition1.setOperator(InfixExpression.Operator.NOT_EQUALS);
        condition1.setRightOperand(ast.newNullLiteral());

        InfixExpression condition2 = ast.newInfixExpression();
        MethodInvocation getTimestamp = ast.newMethodInvocation();
        getTimestamp.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
        getTimestamp.setName(ast.newSimpleName("getTimestamp"));
        condition2.setLeftOperand(getTimestamp);
        condition2.setOperator(InfixExpression.Operator.GREATER);
        condition2.setRightOperand(ast.newNumberLiteral("0"));

        testExpression.setLeftOperand(condition1);
        testExpression.setOperator(InfixExpression.Operator.CONDITIONAL_AND);
        testExpression.setRightOperand(condition2);
        ifStatement.setExpression(testExpression);

        // The "then" branch.
        Block thenBranch = ast.newBlock();

        // Method call to store old value.
        MethodInvocation recordInvocation = ast.newMethodInvocation();
        recordInvocation.setExpression(ast
                .newSimpleName(_getRecordName(fieldName)));
        recordInvocation.setName(ast.newSimpleName("add"));

        // If there are indices, create an integer array of those indices,
        // and add it as an argument.
        if (indices == 0) {
            recordInvocation.arguments().add(ast.newNullLiteral());
        } else {
            ArrayCreation arrayCreation = ast.newArrayCreation();
            ArrayType arrayType = ast.newArrayType(ast
                    .newPrimitiveType(PrimitiveType.INT));
            ArrayInitializer initializer = ast.newArrayInitializer();

            for (int i = 0; i < indices; i++) {
                initializer.expressions().add(ast.newSimpleName("index" + i));
            }

            arrayCreation.setType(arrayType);
            arrayCreation.setInitializer(initializer);
            recordInvocation.arguments().add(arrayCreation);
        }

        // If there are indices, add them ("index0", "index1", ...) after the
        // field.
        Expression field = ast.newSimpleName(fieldName);

        if (indices > 0) {
            for (int i = 0; i < indices; i++) {
                ArrayAccess arrayAccess = ast.newArrayAccess();
                arrayAccess.setArray(field);
                arrayAccess.setIndex(ast.newSimpleName("index" + i));
                field = arrayAccess;
            }
        }

        // Set the field as the next argument.
        recordInvocation.arguments().add(field);

        // Get current timestamp from the checkpoint object.
        MethodInvocation timestampGetter = ast.newMethodInvocation();
        timestampGetter.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
        timestampGetter.setName(ast.newSimpleName("getTimestamp"));

        // Set the timestamp as the next argument.
        recordInvocation.arguments().add(timestampGetter);

        // The statement of the method call.
        ExpressionStatement recordStatement = ast
                .newExpressionStatement(recordInvocation);
        thenBranch.statements().add(recordStatement);

        ifStatement.setThenStatement(thenBranch);
        block.statements().add(ifStatement);

        // Finally, assign the new value to the field.
        Assignment assignment = ast.newAssignment();
        assignment
View Full Code Here

        }
      });
    }

    private void openEx() throws Exception {
      IfStatement ifStatement = getThisStatement();
      JavaInfoUtils.scheduleOpenNode(DialogInfo.this, ifStatement);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.IfStatement

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.