Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.MultiTextEdit


      IFile file = getFile(info.getAtgEditor());
      TextFileChange textFileChange = new TextFileChange( file.getName(), file );
      rootChange.add(textFileChange);
     
      //a file change contains a tree of edits, first add the root of them
      final MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
      textFileChange.setEdit(fileChangeRootEdit);   
     
      AtgAstVisitor renameTokenAtgVisitor = new AtgAstVisitor() {
       
        @Override
        public boolean visit(AbstractAtgAstNode node) {
         
          if (node instanceof IdentNode) {
            IdentNode identNode = (IdentNode) node;
            if (identNode.getKind() == IdentNode.Kind.TOKEN &&
              identNode.getIdent().equals(info.getOldName())) {
              //found ident to change
              ReplaceEdit edit = new ReplaceEdit
                  identNode.getRegion().getOffset(),
                          identNode.getRegion().getLength(),
                          info.getNewName());     
              fileChangeRootEdit.addChild(edit);
              return false;
            }
          }
          return true;
        }
      };
     
      //visit atgAst
      info.getAtgEditor()
        .getAtgAstManager()
        .getAtgAst()
        .getRoot()
        .accept(renameTokenAtgVisitor);
     
      final String oldJavaName = "_" + info.getOldName();
      final String newJavaName = "_" + info.getNewName();
      ASTVisitor renameTokenJavaVisitor = new ASTVisitor() {
        @Override
        public boolean visit(SimpleName node) {
         
          if (node.resolveBinding() != null &&
            node.resolveBinding().getKind() == IBinding.VARIABLE &&
            ((IVariableBinding) node.resolveBinding()).isField() &&
            node.getIdentifier().equals(oldJavaName))
          {     
            //map to ATG Position
            int offset = info.getAtgEditor()
                    .getSyncer()
                    .mapToATG(node.getStartPosition(), node);
            if (offset >= 0) {
              //found token-ident to change
              ReplaceEdit edit = new ReplaceEdit
                  offset,
                  oldJavaName.length(),
                          newJavaName);     
              fileChangeRootEdit.addChild(edit);                         
            }
          }
          return super.visit(node);
        }
      };
View Full Code Here


      IFile file = getFile(info.getAtgEditor());
      TextFileChange textFileChange = new TextFileChange( file.getName(), file );
      rootChange.add(textFileChange);
     
      //a file change contains a tree of edits, first add the root of them
      final MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
      textFileChange.setEdit(fileChangeRootEdit);   
     
      AtgAstVisitor renameCharacterVisitor = new AtgAstVisitor() {
       
        @Override
        public boolean visit(AbstractAtgAstNode node) {
         
          if (node instanceof IdentNode) {
            IdentNode identNode = (IdentNode) node;
            if (identNode.getKind() == IdentNode.Kind.CHARACTER_SET &&
              identNode.getIdent().equals(info.getOldName())) {
              //found ident to change
              ReplaceEdit edit = new ReplaceEdit
                  identNode.getRegion().getOffset(),
                          identNode.getRegion().getLength(),
                          info.getNewName());     
              fileChangeRootEdit.addChild(edit);
              return false;
            }
          }
          return true;
        }
View Full Code Here

      IFile file = getFile(info.getAtgEditor());
      TextFileChange textFileChange = new TextFileChange( file.getName(), file );
      rootChange.add(textFileChange);
     
      //a file change contains a tree of edits, first add the root of them
      final MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
      textFileChange.setEdit(fileChangeRootEdit);   
     
      AtgAstVisitor renameTokenAtgVisitor = new AtgAstVisitor() {
       
        @Override
        public boolean visit(AbstractAtgAstNode node) {
         
          if (node instanceof IdentNode) {
            IdentNode identNode = (IdentNode) node;
            if (identNode.getKind() == IdentNode.Kind.PRAGMA &&
              identNode.getIdent().equals(info.getOldName())) {
              //found ident to change
              ReplaceEdit edit = new ReplaceEdit
                  identNode.getRegion().getOffset(),
                          identNode.getRegion().getLength(),
                          info.getNewName());     
              fileChangeRootEdit.addChild(edit);
              return false;
            }
          }
          return true;
        }
      };
     
      //visit atgAst
      info.getAtgEditor()
        .getAtgAstManager()
        .getAtgAst()
        .getRoot()
        .accept(renameTokenAtgVisitor);
     
      final String oldJavaName = "_" + info.getOldName();
      final String newJavaName = "_" + info.getNewName();
      ASTVisitor renameTokenJavaVisitor = new ASTVisitor() {
        @Override
        public boolean visit(SimpleName node) {
         
          if (node.resolveBinding() != null &&
            node.resolveBinding().getKind() == IBinding.VARIABLE &&
            ((IVariableBinding) node.resolveBinding()).isField() &&
            node.getIdentifier().equals(oldJavaName))
          {     
            //map to ATG Position
            int offset = info.getAtgEditor()
                    .getSyncer()
                    .mapToATG(node.getStartPosition(), node);
            if (offset >= 0) {
              //found token-ident to change
              ReplaceEdit edit = new ReplaceEdit
                  offset,
                  oldJavaName.length(),
                          newJavaName);     
              fileChangeRootEdit.addChild(edit);                         
            }
          }
          return super.visit(node);
        }
      };
View Full Code Here

  }

  private void rewriteAST(ICompilationUnit unit, ASTRewrite astRewrite,
      ImportRewrite importRewrite) {
    try {
      final MultiTextEdit edit = new MultiTextEdit();
      final TextEdit astEdit = astRewrite.rewriteAST();

      if (!this.isEmptyEdit(astEdit))
        edit.addChild(astEdit);
      final TextEdit importEdit = importRewrite
          .rewriteImports(new NullProgressMonitor());
      if (!this.isEmptyEdit(importEdit))
        edit.addChild(importEdit);
      if (this.isEmptyEdit(edit))
        return;

      TextFileChange change = (TextFileChange) this.changes.get(unit);
      if (change == null) {
View Full Code Here

  /**
   * Removes {@link InsertEdit}'s with text containing given substring.
   */
  private static void removeInsertEdits_forSubString(TextEdit edit, String subString) {
    if (edit instanceof MultiTextEdit) {
      MultiTextEdit multiTextEdit = (MultiTextEdit) edit;
      for (TextEdit child : multiTextEdit.getChildren()) {
        if (child instanceof InsertEdit) {
          InsertEdit insertEdit = (InsertEdit) child;
          if (insertEdit.getText().indexOf(subString) != -1) {
            multiTextEdit.removeChild(insertEdit);
          }
        } else {
          removeInsertEdits_forSubString(child, subString);
        }
      }
View Full Code Here

  /**
   * Removes {@link InsertEdit}'s with "new line only" text.
   */
  private static void removeInsertEdits_forNewLine(TextEdit edit) {
    if (edit instanceof MultiTextEdit) {
      MultiTextEdit multiTextEdit = (MultiTextEdit) edit;
      for (TextEdit child : multiTextEdit.getChildren()) {
        if (child instanceof InsertEdit) {
          InsertEdit insertEdit = (InsertEdit) child;
          if (insertEdit.getText().equals("\n")) {
            multiTextEdit.removeChild(insertEdit);
          }
        } else {
          removeInsertEdits_forNewLine(child);
        }
      }
View Full Code Here

    String newSource;
    {
      String source = serviceUnit.getBuffer().getContents();
      Document document = new Document(source);
      // prepare text edits
      MultiTextEdit edits =
          (MultiTextEdit) serviceRoot.rewrite(document, javaProject.getOptions(true));
      removeAnnotations(serviceType, source, edits);
      // prepare new source code
      edits.apply(document);
      newSource = document.get();
    }
    // update compilation unit
    {
      ICompilationUnit unit =
View Full Code Here

    if ( content == null ) {
        return null;
    }
   
    TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
    MultiTextEdit mte = new MultiTextEdit();
    change.setEdit(mte);
   
    boolean isImported = false;
    for (ImportDescr importDescr : drlInfo.getPackageDescr().getImports()) {
      isImported |= importDescr.getTarget().equals(className) || importDescr.getTarget().equals(packageName + ".*");
 
View Full Code Here

            }

            matcher = pattern.matcher(content);

            TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
            MultiTextEdit mte = new MultiTextEdit();
            change.setEdit(mte);
            while (matcher.find()) {
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
                mte.addChild(replace);
            }
            if (change.getEdit().getChildrenSize() > 0)
                changes.add(change);
        }
        if (changes.getChildren().length==0)
View Full Code Here

   * Adds {@link TextEdit}s into existing Java file {@link Change}.
   */
  private void addHandlerMethodChanges(CompositeChange compositeChange, IProgressMonitor pm)
      throws Exception {
    TextChange change = new CompilationUnitChange("(No matter)", m_field.getCompilationUnit());
    change.setEdit(new MultiTextEdit());
    // update handler methods
    String oldMethodPrefix = "on" + StringUtils.capitalize(m_oldName);
    String newMethodPrefix = "on" + StringUtils.capitalize(m_newName);
    IType type = (IType) m_field.getParent();
    for (IMethod method : type.getMethods()) {
View Full Code Here

TOP

Related Classes of org.eclipse.text.edits.MultiTextEdit

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.