Package org.eclipse.jdt.core.dom

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


   */
  public final ASTNode createGroupNode(ASTNode[] targetNodes) {
    if (targetNodes == null || targetNodes.length == 0) {
      throw new IllegalArgumentException();
    }
    Block res= getNodeStore().createCollapsePlaceholder();
    ListRewrite listRewrite= getListRewrite(res, Block.STATEMENTS_PROPERTY);
    for (int i= 0; i < targetNodes.length; i++) {
      listRewrite.insertLast(targetNodes[i], null);
    }
    return res;
View Full Code Here


    ASTNode placeholder= nodeStore.newPlaceholderNode(first.getNodeType()); // revisit: could use list type
    if (placeholder == null) {
      throw new IllegalArgumentException("Creating a target node is not supported for nodes of type" + first.getClass().getName()); //$NON-NLS-1$
    }

    Block internalPlaceHolder= nodeStore.createCollapsePlaceholder();
    CopySourceInfo info= getRewriteStore().createRangeCopy(this.parent, this.childProperty, first, last, isMove, internalPlaceHolder, replacingNode, editGroup);
    nodeStore.markAsCopyTarget(placeholder, info);

    return placeholder;
  }
View Full Code Here

      ASTNode node= (ASTNode) event.getOriginalValue();
      // check for ranges and add a placeholder for them
      while (nextInfo != null && node == nextInfo.getStartNode()) { // is this child the beginning of a range?
        nextInfo.updatePlaceholderSourceRanges(sourceRangeComputer);

        Block internalPlaceholder= nextInfo.getInternalPlaceholder();
        RewriteEvent newEvent;
        if (nextInfo.isMove()) {
          newEvent= new NodeRewriteEvent(internalPlaceholder, nextInfo.replacingNode); // remove or replace
        } else {
          newEvent= new NodeRewriteEvent(internalPlaceholder, internalPlaceholder); // unchanged
        }
        newChildEvents.add(newEvent);
        if (nextInfo.editGroup != null) {
          setEventEditGroup(newEvent, nextInfo.editGroup);
        }

        newChildrenStack.push(newChildEvents);
        topInfoStack.push(topInfo);

        newChildEvents= new ArrayList(childEvents.length);
        topInfo= nextInfo;

        nextInfo= rangeInfoIterator.hasNext() ? (NodeRangeInfo) rangeInfoIterator.next() : null;
      }

      newChildEvents.add(event);

      while (topInfo != null && node == topInfo.getEndNode()) {
        RewriteEvent[] placeholderChildEvents= (RewriteEvent[]) newChildEvents.toArray(new RewriteEvent[newChildEvents.size()]);
        Block internalPlaceholder= topInfo.getInternalPlaceholder();
        addEvent(internalPlaceholder, Block.STATEMENTS_PROPERTY, new ListRewriteEvent(placeholderChildEvents));

        newChildEvents= (List) newChildrenStack.pop();
        topInfo= (NodeRangeInfo) topInfoStack.pop();
      }
View Full Code Here

      TargetSourceRangeComputer.SourceRange startRange= sourceRangeComputer.computeSourceRange(getStartNode());
      TargetSourceRangeComputer.SourceRange endRange= sourceRangeComputer.computeSourceRange(getEndNode());
      int startPos= startRange.getStartPosition();
      int endPos= endRange.getStartPosition() + endRange.getLength();

      Block internalPlaceholder= getInternalPlaceholder();
      internalPlaceholder.setSourceRange(startPos, endPos - startPos);
    }
View Full Code Here

        AST ast = rewrite.getAST();

        SuperMethodInvocation superCall = createSuperMethodInvocation(rewrite, method);
        ExpressionStatement statement = ast.newExpressionStatement(superCall);
        Block methodBody = method.getBody();
        ListRewrite listRewrite = rewrite.getListRewrite(methodBody, Block.STATEMENTS_PROPERTY);
        if (isInsertFirst()) {
            listRewrite.insertFirst(statement, null);
        } else {
            listRewrite.insertLast(statement, null);
View Full Code Here

            modifiers.add(ast
                    .newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
        }

        // Create the method body.
        Block body = _createAssignmentBlock(ast, state, fieldName, fieldType,
                indices, special);
        method.setBody(body);

        return method;
    }
View Full Code Here

     @param special Whether to handle special assign operators.
     *  @return The body of the assignment method.
     */
    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.
View Full Code Here

            index.setType(ast.newPrimitiveType(PrimitiveType.INT));
            index.setName(ast.newSimpleName("index" + i));
            method.parameters().add(index);
        }

        Block body = ast.newBlock();
        method.setBody(body);

        // The first statement: backup the whole array.
        MethodInvocation backup = ast.newMethodInvocation();
        backup.setExpression(ast.newSimpleName(_getRecordName(fieldName)));
        backup.setName(ast.newSimpleName("backup"));

        if (indices == 0) {
            backup.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);
            backup.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.
        backup.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.
        backup.arguments().add(timestampGetter);

        body.statements().add(ast.newExpressionStatement(backup));

        // The second statement: return the array.
        ReturnStatement returnStatement = ast.newReturnStatement();
        returnStatement.setExpression((Expression) ASTNode.copySubtree(ast,
                field));
        body.statements().add(returnStatement);

        // If the field is static, the method is also static; the method
        // is also private.
        List modifiers = method.modifiers();
        modifiers
View Full Code Here

        method.parameters().add(timestamp);

        // Return type default to "void".
        if (!isInterface) {
            // The method body.
            Block body = ast.newBlock();
            method.setBody(body);

            // Add a call to the static commit method of FieldRecord.
            MethodInvocation commitFields = ast.newMethodInvocation();
            commitFields.setExpression(createName(ast, getClassName(
                    FieldRecord.class.getName(), state, root)));
            commitFields.setName(ast.newSimpleName("commit"));
            commitFields.arguments().add(ast.newSimpleName(RECORDS_NAME));
            commitFields.arguments().add(ast.newSimpleName("timestamp"));

            MethodInvocation topTimestamp = ast.newMethodInvocation();
            topTimestamp.setExpression(ast
                    .newSimpleName(CHECKPOINT_RECORD_NAME));
            topTimestamp.setName(ast.newSimpleName("getTopTimestamp"));
            commitFields.arguments().add(topTimestamp);
            body.statements().add(ast.newExpressionStatement(commitFields));

            // Add a call to the commit method in the superclass, if necessary.
            SuperMethodInvocation superRestore = ast.newSuperMethodInvocation();
            superRestore
                    .setName(ast.newSimpleName(_getCommitMethodName(false)));
            superRestore.arguments().add(ast.newSimpleName("timestamp"));

            if ((parent != null)
                    && (state.getCrossAnalyzedTypes()
                            .contains(parent.getName()) || hasMethod(parent,
                            methodName,
                            new Class[] { int.class, boolean.class }))) {
                body.statements().add(ast.newExpressionStatement(superRestore));
            } else {
                // Commit the checkpoint record.
                MethodInvocation commitCheckpoint = ast.newMethodInvocation();
                commitCheckpoint.setExpression(ast
                        .newSimpleName(CHECKPOINT_RECORD_NAME));
                commitCheckpoint.setName(ast.newSimpleName("commit"));
                commitCheckpoint.arguments()
                        .add(ast.newSimpleName("timestamp"));
                body.statements().add(
                        ast.newExpressionStatement(commitCheckpoint));

                if (parent != null) {
                    addToLists(_nodeSubstitution, parent.getName(),
                            new NodeReplace(commitCheckpoint, superRestore));
View Full Code Here

        String typeName = getClassName(Checkpoint.class, state, root);
        method.setReturnType2(createType(ast, typeName));

        if (!isInterface) {
            // The body, just to return the checkpoint object.
            Block body = ast.newBlock();
            method.setBody(body);

            ReturnStatement returnStatement = ast.newReturnStatement();
            returnStatement.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
            body.statements().add(returnStatement);
        }

        method.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
        if (!isInterface) {
View Full Code Here

TOP

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

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.