Examples of ASTRewrite


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

      // ensure cu is consistent (noop if already consistent)
      cu.makeConsistent(this.progressMonitor);
      this.parser.setSource(cu);
      CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
      AST ast = astCU.getAST();
      ASTRewrite rewrite = ASTRewrite.create(ast);
      updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite);
      updatePackageStatement(astCU, destPackageName, rewrite, cu);
      return rewrite.rewriteAST();
    }
  }
View Full Code Here

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

    CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
    ASTNode node = ((JavaElement) elementToRemove).findNode(astCU);
    if (node == null)
      Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$
    AST ast = astCU.getAST();
    ASTRewrite rewriter = ASTRewrite.create(ast);
    rewriter.remove(node, null);
     TextEdit edits = rewriter.rewriteAST();
     applyTextEdit(cu, edits);
  }
View Full Code Here

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

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(source.toCharArray()); // set source
    parser.setResolveBindings(true); // we need bindings later on
    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
//    List types = cu.structuralPropertiesForType();
    ASTRewrite rewriter = ASTRewrite.create(cu.getAST());
    for(Object o:cu.types()){
      AbstractTypeDeclaration dec = (AbstractTypeDeclaration) o;
      List bodyDeclarations = dec.bodyDeclarations();
      for(Object body:bodyDeclarations){
        MethodDeclaration methodDec = (MethodDeclaration) body;
        ListRewrite listRewrite = rewriter.getListRewrite(methodDec.getJavadoc(), Javadoc.TAGS_PROPERTY);
        List originalList = listRewrite.getOriginalList();
        ASTNode node = createNode(cu.getAST());
        listRewrite.insertLast(node, null);
        System.out.println(originalList);
        System.out.println(listRewrite.getRewrittenList());
      }
    }
    TextEdit rewriteAst = rewriter.rewriteAST(doc, null);
    rewriteAst.apply(doc);
    System.out.println(doc.get());
  }
View Full Code Here

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

       
        String source = compilationUnit.getBuffer().getContents();
        Document document= new Document(source);
       
        ASTNode firstOriginal = originals.get(0);
        ASTRewrite rewrite = ASTRewrite.create(firstOriginal.getAST());
       
        TextEditGroup editGroup = new TextEditGroup("Replacing nodes");
        for(ASTNode original: originals) {
            if (original == firstOriginal) {
                rewrite.replace(original, replacement, editGroup);
            } else {
                rewrite.replace(original, null, editGroup);
            }
        }
       
        TextEdit edits = rewrite.rewriteAST(document, compilationUnit.getJavaProject().getOptions(true));
       
        // computation of the new source code
        edits.apply(document);
        String newSource = document.get();
       
View Full Code Here

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

    Document document= new Document(source);
   
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);
 
    ASTRewrite rewrite = ASTRewrite.create(declaration.getAST());

    ChildListPropertyDescriptor modifiersProperty = declaration.getModifiersProperty();

    ListRewrite listRewrite = rewrite.getListRewrite(declaration, modifiersProperty);
    listRewrite.insertFirst(annotation, null);
   
    TextEdit importEdits = null;
    if (importDeclaration != null) {
      ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
      importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
      importEdits = importRewrite.rewriteImports(null);
    }
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
    edits.apply(document);
    if (importEdits != null) {
      importEdits.apply(document);
View Full Code Here

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

    Document document= new Document(source);
   
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);
 
    ASTRewrite rewrite = ASTRewrite.create(declaration.getAST());

    ListRewrite listRewrite = rewrite.getListRewrite(declaration, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    listRewrite.insertFirst(annotation, null);
   
    TextEdit importEdits = null;
    if (importDeclaration != null) {
      ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
      importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
      importEdits = importRewrite.rewriteImports(null);
    }
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
    edits.apply(document);
    if (importEdits != null) {
      importEdits.apply(document);
View Full Code Here

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

    Document document= new Document(source);
   
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);
   
    ASTRewrite rewrite = ASTRewrite.create(declaration.getAST());
   
    ChildListPropertyDescriptor modifiersProperty = declaration.getModifiersProperty();
   
    ListRewrite listRewrite = rewrite.getListRewrite(declaration, modifiersProperty);
    listRewrite.insertFirst(normalAnnotation, null);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);

    TextEdit importEdits = null;
    ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
    importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
    importEdits = importRewrite.rewriteImports(null);
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
    edits.apply(document);
    if (importEdits != null) {
      importEdits.apply(document);
View Full Code Here

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

    Document document= new Document(source);
   
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);
   
    ASTRewrite rewrite = ASTRewrite.create(declaration.getAST());
   
    ListRewrite listRewrite = rewrite.getListRewrite(declaration, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    listRewrite.insertFirst(normalAnnotation, null);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);

    TextEdit importEdits = null;
    ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
    importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
    importEdits = importRewrite.rewriteImports(null);
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
    edits.apply(document);
    if (importEdits != null) {
      importEdits.apply(document);
View Full Code Here

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

    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);

    AST ast = normalAnnotation.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
    edits.apply(document);
    String newSource = document.get();
   
View Full Code Here

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

    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);

    AST ast = normalAnnotation.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
    edits.apply(document);
    String newSource = document.get();
   
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.