Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


  }


  private final void doTextReplace(int offset, int len, String insertString, TextEditGroup editGroup) {
    if (len > 0 || insertString.length() > 0) {
      TextEdit edit= new ReplaceEdit(offset, len, insertString);
      addEdit(edit);
      if (editGroup != null) {
        addEditGroup(editGroup, edit);
      }
    }
View Full Code Here


      }
    }
  }

  private final TextEdit doTextCopy(TextEdit sourceEdit, int destOffset, int sourceIndentLevel, String destIndentString, TextEditGroup editGroup) {
    TextEdit targetEdit;
    SourceModifier modifier= new SourceModifier(sourceIndentLevel, destIndentString, this.formatter.getTabWidth(), this.formatter.getIndentWidth());

    if (sourceEdit instanceof MoveSourceEdit) {
      MoveSourceEdit moveEdit= (MoveSourceEdit) sourceEdit;
      moveEdit.setSourceModifier(modifier);
View Full Code Here

      }

      Object data= curr.data;
      if (data instanceof TextEditGroup) { // tracking a node
        // need to split and create 2 edits as tracking node can surround replaced node.
        TextEdit edit= new RangeMarker(insertOffset, 0);
        addEditGroup((TextEditGroup) data, edit);
        addEdit(edit);
        if (curr.length != 0) {
          int end= offset + curr.length;
          int k= i + 1;
          while (k < markers.size() && ((NodeMarker) markers.get(k)).offset < end) {
            k++;
          }
          curr.offset= end;
          curr.length= 0;
          markers.add(k, curr); // add again for end position
        }
        currPos= offset;
      } else {
        String destIndentString=  this.formatter.getIndentString(getCurrentLine(formatted, offset));
        if (data instanceof CopyPlaceholderData) { // replace with a copy/move target
          CopySourceInfo copySource= ((CopyPlaceholderData) data).copySource;
          int srcIndentLevel= getIndent(copySource.getNode().getStartPosition());
          TextEdit sourceEdit= getCopySourceEdit(copySource);
          doTextCopy(sourceEdit, insertOffset, srcIndentLevel, destIndentString, editGroup);
          currPos= offset + curr.length; // continue to insert after the replaced string
          if (needsNewLineForLineComment(copySource.getNode(), formatted, currPos)) {
            doTextInsert(insertOffset, getLineDelimiter(), editGroup);
          }
View Full Code Here

    TextEditGroup editGroup= this.eventStore.getTrackedNodeData(node);
    if (editGroup != null) {
      SourceRange range= getExtendedRange(node);
      int offset= range.getStartPosition();
      int length= range.getLength();
      TextEdit edit= new RangeMarker(offset, length);
      addEditGroup(editGroup, edit);
      addEdit(edit);
      this.currentEdit= edit;
    }
   
View Full Code Here

   * complete
   */
  private void processCompilationUnitResource(ICompilationUnit source, PackageFragment dest) throws JavaModelException {
    String newCUName = getNewNameFor(source);
    String destName = (newCUName != null) ? newCUName : source.getElementName();
    TextEdit edit = updateContent(source, dest, newCUName); // null if unchanged

    // TODO (frederic) remove when bug 67606 will be fixed (bug 67823)
    // store encoding (fix bug 66898)
    IFile sourceResource = (IFile)source.getResource();
    String sourceEncoding = null;
View Full Code Here

            this.parser.setSource(cu);
            CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
            AST ast = astCU.getAST();
            ASTRewrite rewrite = ASTRewrite.create(ast);
            updatePackageStatement(astCU, newFragName, rewrite, cu);
            TextEdit edits = rewrite.rewriteAST();
            applyTextEdit(cu, edits);
            cu.save(null, false);
          }
        }
      }
View Full Code Here

    }
    return codeFormatter;
  }

  public static String formatCode(String source) {
    TextEdit edit = getCodeFormatter().format(CodeFormatter.K_UNKNOWN, source, 0, source.length(), 0, System.getProperty("line.separator")); //$NON-NLS-1$
    if (edit != null) {
      IDocument document = new Document(source);
      try {
        edit.apply(document);
        return document.get();
      } catch (Exception e) {
        VisualSwingPlugin.getLogger().error(e);
      }
    }
View Full Code Here

    }
    return null;
  }

  private TextEdit doCreateSaveAction(IDocument document, IRegion[] changedRegions) throws BadLocationException {
    TextEdit rootEdit = null;
    for (IRegion region : changedRegions) {
      int lastLine = document.getLineOfOffset(region.getOffset() + region.getLength());
      for (int line = firstLine(region, document); line <= lastLine; line++) {
        IRegion lineRegion = document.getLineInformation(line);
        if (lineRegion.getLength() == 0) {
          continue;
        }
        int lineStart = lineRegion.getOffset();
        int lineEnd = lineStart + lineRegion.getLength();
        int charPos = rightMostNonWhitespaceChar(document, lineStart, lineEnd);
        if (charPos >= lineEnd) {
          continue;
        }
        // check partition - don't remove whitespace inside strings
        ITypedRegion partition = getPartition(document, DEFAULT_PARTITIONING, charPos, false);
        if ("__string".equals(partition.getType())) {
          continue;
        }
        if (rootEdit == null) {
          rootEdit = new MultiTextEdit();
        }
        rootEdit.addChild(new DeleteEdit(charPos, lineEnd - charPos));
      }
    }
    return rootEdit;
  }
View Full Code Here

  }

  private void performSaveActions(IProgressMonitor monitor,
      IFileEditorInput editorInput, IDocument document) throws CoreException {
    IRegion[] changedRegions = changedRegions(monitor, editorInput, document);
    TextEdit edit = saveActions.createSaveAction(document, changedRegions);
    if (edit == null) {
      return;
    }
    try {
      IDocumentUndoManager manager = getDocumentUndoManager(document);
      manager.beginCompoundChange();
      edit.apply(document);
      manager.endCompoundChange();
    } catch (Throwable t) {
      throw new CoreException(error(t));
    }
  }
View Full Code Here

        }

        bodyDeclarations.removeAll(declarationsToDelete);

        // computation of the text edits
        TextEdit edits = astRoot.rewrite(document, asyncContents.getJavaProject().getOptions(true));

        // computation of the new source code
        edits.apply(document);
        String newSource = document.get();

        // update of the compilation unit
        clientPackage.createCompilationUnit(remoteServiceAsyncName + ".java", newSource, true, monitor); //$NON-NLS-1$
View Full Code Here

TOP

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

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.