Examples of ListRewrite


Examples of org.aspectj.org.eclipse.jdt.core.dom.rewrite.ListRewrite

   */
  protected void insertASTNode(ASTRewrite rewriter, ASTNode parent, ASTNode child) throws JavaModelException {
    StructuralPropertyDescriptor propertyDescriptor = getChildPropertyDescriptor(parent);
    if (propertyDescriptor instanceof ChildListPropertyDescriptor) {
      ChildListPropertyDescriptor childListPropertyDescriptor = (ChildListPropertyDescriptor) propertyDescriptor;
       ListRewrite rewrite = rewriter.getListRewrite(parent, childListPropertyDescriptor);
       switch (this.insertionPolicy) {
         case INSERT_BEFORE:
           ASTNode element = ((JavaElement) this.anchorElement).findNode(this.cuAST);
           if (childListPropertyDescriptor.getElementType().isAssignableFrom(element.getClass()))
             rewrite.insertBefore(child, element, null);
           else
             // case of an empty import list: the anchor element is the top level type and cannot be used in insertBefore as it is not the same type
             rewrite.insertLast(child, null);
           break;
         case INSERT_AFTER:
           element = ((JavaElement) this.anchorElement).findNode(this.cuAST);
           if (childListPropertyDescriptor.getElementType().isAssignableFrom(element.getClass()))
             rewrite.insertAfter(child, element, null);
           else
             // case of an empty import list: the anchor element is the top level type and cannot be used in insertAfter as it is not the same type
             rewrite.insertLast(child, null);
           break;
         case INSERT_LAST:
           rewrite.insertLast(child, null);
           break;
       }
    } else {
      rewriter.set(parent, propertyDescriptor, child, null);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

  private String generateMethodDeclaration(final IDocument document, final Document recoveredDocument,
      final ASTNode node, final ASTRewrite rewrite, final CodeGenerationSettings settings,
      final MethodDeclaration stub) throws BadLocationException
  {
    ChildListPropertyDescriptor descriptor = getPropDescriptor(node);
    ListRewrite rewriter = rewrite.getListRewrite(node, descriptor);
    rewriter.insertFirst(stub, null);

    ITrackedNodePosition position = rewrite.track(stub);

    rewrite.rewriteAST(recoveredDocument, fJavaProject.getOptions(true)).apply(recoveredDocument);
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        FieldDeclaration field = getFieldDeclaration(type, bug.getPrimaryField());

        Modifier finalModifier = workingUnit.getAST().newModifier(getModifierToAdd());

        ListRewrite modRewrite = rewrite.getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY);
        modRewrite.insertLast(finalModifier, null);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        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

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        assert params != null;

        for (Object paramObj : params) {
            SingleVariableDeclaration param = (SingleVariableDeclaration) paramObj;
            if (variables.contains(param.getName().getFullyQualifiedName())) {
                ListRewrite listRewrite = rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
                listRewrite.insertLast(rewrite.getAST().newModifier(ModifierKeyword.FINAL_KEYWORD), null);
            }
        }
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

            @Override
            public boolean visit(VariableDeclarationFragment fragment) {
                if (variables.contains(fragment.getName().getFullyQualifiedName())) {
                    ASTNode parent = fragment.getParent();
                    if (parent instanceof VariableDeclarationStatement) {
                        ListRewrite listRewrite = rewrite
                                .getListRewrite(parent, VariableDeclarationStatement.MODIFIERS2_PROPERTY);
                        listRewrite.insertLast(ast.newModifier(ModifierKeyword.FINAL_KEYWORD), null);
                    }
                }
                return true;
            }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        .getVariableDeclarationFragment();
    VariableDeclarationStatement statement = (VariableDeclarationStatement) fragment
        .getParent();
    // add a remove command to the protocol
    rewrite.remove(fragment, null);
    ListRewrite fragmentsListRewrite = rewrite.getListRewrite(statement,
        VariableDeclarationStatement.FRAGMENTS_PROPERTY);
    if (fragmentsListRewrite.getRewrittenList().size() == 0) {
      // add a remove command to the protocol
      rewrite.remove(statement, null);
    }
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

    VariableDeclarationStatement statement = createNewVariableDeclarationStatement(
        manager, ast);
    int firstReferenceIndex = getFirstReferenceListIndex(manager);
    Block block = Helper.getParentBlock(manager.getFirstReference());
    // get the list rewriter for the statments list
    ListRewrite statementsListRewrite = rewrite.getListRewrite(block,
        Block.STATEMENTS_PROPERTY);
    // add insert-at command to the protocol
    statementsListRewrite.insertAt(statement, firstReferenceIndex, null);
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        MethodDeclaration method = getMethodDeclaration(type, bug.getPrimaryMethod());
        Modifier originalModifier = getPublicModifier(method);

        ListRewrite listRewrite = rewrite.getListRewrite(method, MethodDeclaration.MODIFIERS2_PROPERTY);
        Modifier protectedModifier = workingUnit.getAST().newModifier(PROTECTED_KEYWORD);
        listRewrite.replace(originalModifier, protectedModifier, null);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        assert bug != null;

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        Modifier finalMod = workingUnit.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);

        ListRewrite modRewrite = rewrite.getListRewrite(type, TypeDeclaration.MODIFIERS2_PROPERTY);
        modRewrite.insertLast(finalMod, null);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.