Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.MultiTextEdit


   * @return
   */
  private TextEdit createMultiTextEdit(TextEdit[] edits) {

    if (edits.length == 0)
      return new MultiTextEdit();

    /* should not specify a limited region because other edits outside
     * these original edits might be added later.
     */
    MultiTextEdit multiEdit = new MultiTextEdit();
    for (int i = 0; i < edits.length; i++) {
      addToMultiEdit(edits[i], multiEdit);
    }
    return multiEdit;
  }
View Full Code Here


  private void addJavaEdit(String searchDocPath, ReplaceEdit javaEdit) {
   
    Object o = this.fSearchDocPath2JavaEditMap.get(searchDocPath);
    if(o != null) {

      MultiTextEdit multi = (MultiTextEdit)o;
      multi.addChild(javaEdit);
    }
    else {
      // use a multi edit so doc position offsets get updated automatically
      // when adding multiple child edits
      MultiTextEdit multi = new MultiTextEdit();
      multi.addChild(javaEdit);
      this.fSearchDocPath2JavaEditMap.put(searchDocPath, multi);
    }
  }
View Full Code Here

    SearchDocument delegate = null;
   
    while(keys.hasNext()) {
      // create on the fly
      searchDocPath = (String)keys.next();
      MultiTextEdit javaEdit = (MultiTextEdit)fSearchDocPath2JavaEditMap.get(searchDocPath);
      delegate = support.getSearchDocument(searchDocPath);
     
      if(delegate != null && delegate instanceof JavaSearchDocumentDelegate) {
        JavaSearchDocumentDelegate javaDelegate = (JavaSearchDocumentDelegate)delegate;
        changes.add(createChange(javaDelegate, javaDelegate.getJspTranslation().getJspEdit(javaEdit)));
View Full Code Here

    SearchDocument delegate = null;
   
    while(keys.hasNext()) {
      // create on the fly
      searchDocPath = (String)keys.next();
      MultiTextEdit javaEdit = (MultiTextEdit)fSearchDocPath2JavaEditMap.get(searchDocPath);
      delegate = support.getSearchDocument(searchDocPath);
     
      if(delegate != null && delegate instanceof JavaSearchDocumentDelegate) {
        JavaSearchDocumentDelegate javaDelegate = (JavaSearchDocumentDelegate)delegate;
        Change change = createChange(javaDelegate, javaDelegate.getJspTranslation().getJspEdit(javaEdit), participant);
View Full Code Here

  }

  public TextEdit format(IStructuredModel model, int start, int length, XMLFormattingPreferences preferences) {
    setFormattingPreferences(preferences);

    TextEdit edit = new MultiTextEdit();
    IStructuredDocument document = model.getStructuredDocument();
    // get initial document region
    IStructuredDocumentRegion currentRegion = document.getRegionAtCharacterOffset(start);
    if (currentRegion != null) {
      int startOffset = currentRegion.getStartOffset();
View Full Code Here

            lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
          } else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
            index = index - 2;
            lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
          }
          MultiTextEdit multiTextEdit = new MultiTextEdit();
          try {
            for (int i = insertAttrs.size() - 1; i >= 0; i--) {
              CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) insertAttrs.get(i);
              String requiredAttributeName = attrDecl.getAttrName();
              String defaultValue = attrDecl.getDefaultValue();
              if (defaultValue == null)
                defaultValue = ""; //$NON-NLS-1$
              String nameAndDefaultValue = " "; //$NON-NLS-1$
              if (i == 0 && lastRegion.getLength() > lastRegion.getTextLength())
                nameAndDefaultValue = ""; //$NON-NLS-1$
              nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
              multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));
              // BUG3381: MultiTextEdit applies all child
              // TextEdit's basing on offsets
              //          in the document before the first TextEdit, not
              // after each
              //          child TextEdit. Therefore, do not need to
              // advance the index.
              //index += nameAndDefaultValue.length();
            }
            multiTextEdit.apply(newNode.getStructuredDocument());
          } catch (BadLocationException e) {
            // log for now, unless we find reason not to
            Logger.log(Logger.INFO, e.getMessage());
          }
        }
View Full Code Here

        startTagOffset = cursorNode.getStartOffset();
        endTagOffset = cursorNode.getEndOffset();
      }

      // insert new element
      MultiTextEdit multiTextEdit = new MultiTextEdit();
      // element tag name cannot be DBCS, do not translate "<element>"
      // and "</element>"
      final String startElement = "<" + ELEMENT_NAME + ">"; //$NON-NLS-1$ //$NON-NLS-2$
      multiTextEdit.addChild(new InsertEdit(startTagOffset, startElement));
      multiTextEdit.addChild(new InsertEdit(endTagOffset, "</"+ELEMENT_NAME +">")); //$NON-NLS-1$ //$NON-NLS-2$
      multiTextEdit.apply(viewer.getDocument());
      Position start = new Position(startTagOffset);
      Position end = new Position(endTagOffset + startElement.length());

      try {
        viewer.getDocument().addPosition(start);
View Full Code Here

    int startTagOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[0]).intValue();
    int startTagLength = ((Integer) ((Object[]) fAdditionalFixInfo)[1]).intValue();
    int endTagOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[2]).intValue();
    int endTagLength = ((Integer) ((Object[]) fAdditionalFixInfo)[3]).intValue();

    MultiTextEdit multiTextEdit = new MultiTextEdit();
    if (endTagOffset != -1) {
      multiTextEdit.addChild(new DeleteEdit(endTagOffset, endTagLength));
      fSelection = new Point(endTagOffset, 0);
    }
    if (startTagOffset != -1) {
      multiTextEdit.addChild(new DeleteEdit(startTagOffset, startTagLength));
      fSelection = new Point(startTagOffset, 0);
    }

    try {
      multiTextEdit.apply(viewer.getDocument());
    }
    catch (MalformedTreeException e) {
      // log for now, unless find reasons not to.
      Logger.log(Logger.INFO, e.getMessage());
    }
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 ProductionNode &&     // production node
            (globalReformat() || localSelection(node) || localCursorPos(node)))
          {             
            ProductionNode productionNode = (ProductionNode) node;
            IEditorInput editorInput = info.getAtgEditor().getEditorInput();
            IDocumentProvider documentProvider = info.getAtgEditor().getDocumentProvider();
            IDocument document = documentProvider.getDocument(editorInput);

            String production = null;
            try {
              production = document.get
                  productionNode.getRegion().getOffset(),
                  productionNode.getRegion().getLength());
              try {
                ATGProductionReformatter atgProductionReformatter = new ATGProductionReformatter(document, productionNode, info);
                production = atgProductionReformatter.reformat();
                ReplaceEdit edit = new ReplaceEdit
                    productionNode.getRegion().getOffset(),
                    productionNode.getRegion().getLength(),
                    production);     
                fileChangeRootEdit.addChild(edit);
              } catch (Exception e) {
                e.printStackTrace();
              }
            } catch (BadLocationException e) {
              e.printStackTrace();
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.PRODUCTION ||
               identNode.getKind() == IdentNode.Kind.COMPILER) &&
              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);
     
      ASTVisitor renameTokenJavaVisitor = new ASTVisitor() {
        @Override
        public boolean visit(SimpleName node) {
         
          if (node.resolveBinding() != null &&
            node.resolveBinding().getKind() == IBinding.METHOD &&
            node.getIdentifier().equals(info.getOldName()))
          {     
            //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,
                  info.getOldName().length(),
                          info.getNewName());     
              fileChangeRootEdit.addChild(edit);                         
            }
          }
          return super.visit(node);
        }
      };
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.