Java 类org.eclipse.jface.text.DocumentRewriteSession 实例源码

项目:n4js    文件:ChangeManager.java   
/**
 * Applies all given changes to the given document. This method assumes that 'changes' contains only changes
 * intended for the given document; the actual URI stored in the changes is ignored.
 */
public void applyAllInSameDocument(Collection<? extends IAtomicChange> changes, IDocument document)
        throws BadLocationException {
    DocumentRewriteSession rewriteSession = null;
    try {
        // prepare
        if (document instanceof IDocumentExtension4) {
            rewriteSession = ((IDocumentExtension4) document).startRewriteSession(
                    DocumentRewriteSessionType.UNRESTRICTED);
        }
        // perform replacements
        for (IAtomicChange currRepl : changes) {
            currRepl.apply(document);
        }
    } finally {
        // cleanup
        if (rewriteSession != null)
            ((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
    }
}
项目:tlaplus    文件:TLCModelLaunchDataProvider.java   
/**
    * Sets text to a document
    * @param document
    * @param message
    * @param append
    * @throws BadLocationException
    * Has to be run from non-UI thread
    */
public static synchronized void setDocumentText(final Document document, final String message,
        final boolean append) {

    UIHelper.runUIAsync(new Runnable() {
        public void run() {
            try {
                DocumentRewriteSession rewriteSession;
                if (append && !isDefaultLabel(document)) {
                    rewriteSession = document.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
                    // append to existing document (0 length is valid and means message is going to be appended)
                    document.replace(document.getLength(), 0, message + ((message.endsWith(CR)) ? EMPTY : CR));
                } else {
                    rewriteSession = document.startRewriteSession(DocumentRewriteSessionType.STRICTLY_SEQUENTIAL);
                    // replace of complete document
                    document.replace(0, document.getLength(), message + ((message.endsWith(CR)) ? EMPTY : CR));
                }
                document.stopRewriteSession(rewriteSession);
            } catch (BadLocationException ignored) {
            }
        }
    });
}
项目:che    文件:TextChange.java   
/**
 * Executes the text edits on the given document. Subclasses that override this method should call
 * <code>super.performEdits(document)</code>.
 *
 * @param document the document
 * @return an object representing the undo of the executed edits
 * @exception MalformedTreeException is thrown if the edit tree isn't in a valid state. This
 *     exception is thrown before any edit is executed. So the document is still in its original
 *     state.
 * @exception BadLocationException is thrown if one of the edits in the tree can't be executed.
 *     The state of the document is undefined if this exception is thrown.
 * @since 3.5
 */
protected UndoEdit performEdits(IDocument document)
    throws BadLocationException, MalformedTreeException {
  DocumentRewriteSession session = null;
  try {
    if (document instanceof IDocumentExtension4) {
      session =
          ((IDocumentExtension4) document)
              .startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
    }

    LinkedModeModel.closeAllModels(document);
    TextEditProcessor processor = createTextEditProcessor(document, TextEdit.CREATE_UNDO, false);
    return processor.performEdits();

  } finally {
    if (session != null) {
      ((IDocumentExtension4) document).stopRewriteSession(session);
    }
  }
}
项目:bts    文件:EditorDocumentUndoChange.java   
protected UndoEdit performEdits(IDocument document) throws BadLocationException, MalformedTreeException {
    DocumentRewriteSession session= null;
    try {
        if (document instanceof IDocumentExtension4) {
            session= ((IDocumentExtension4)document).startRewriteSession(
                DocumentRewriteSessionType.UNRESTRICTED);
        }
        return undoEdit.apply(document);
    } finally {
        if (session != null) {
            ((IDocumentExtension4)document).stopRewriteSession(session);
        }
    }
}
项目:che    文件:SynchronizableDocument.java   
public DocumentRewriteSession startRewriteSession(DocumentRewriteSessionType sessionType) {
  Object lockObject = getLockObject();
  if (lockObject == null) {
    return super.startRewriteSession(sessionType);
  }
  synchronized (lockObject) {
    return super.startRewriteSession(sessionType);
  }
}
项目:che    文件:SynchronizableDocument.java   
public void stopRewriteSession(DocumentRewriteSession session) {
  Object lockObject = getLockObject();
  if (lockObject == null) {
    super.stopRewriteSession(session);
    return;
  }
  synchronized (lockObject) {
    super.stopRewriteSession(session);
  }
}
项目:che    文件:MultiStateTextFileChange.java   
private void performChangesInSynchronizationContext(
    final IDocument document, final LinkedList undoList, final boolean preview)
    throws BadLocationException {
  DocumentRewriteSession session = null;
  try {
    if (document instanceof IDocumentExtension4)
      session =
          ((IDocumentExtension4) document)
              .startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);

    for (final Iterator iterator = fChanges.iterator(); iterator.hasNext(); ) {
      final ComposableBufferChange change = (ComposableBufferChange) iterator.next();

      final UndoEdit edit =
          createTextEditProcessor(
                  change,
                  document,
                  undoList != null ? TextEdit.CREATE_UNDO : TextEdit.NONE,
                  preview)
              .performEdits();
      if (undoList != null) undoList.addFirst(edit);
    }

  } finally {
    if (session != null) ((IDocumentExtension4) document).stopRewriteSession(session);
  }
}
项目:Pydev    文件:TextSelectionUtils.java   
/**
 * Stop a rewrite session
 */
public static void endWrite(IDocument doc, DocumentRewriteSession session) {
    if (doc instanceof IDocumentExtension4 && session != null) {
        IDocumentExtension4 d = (IDocumentExtension4) doc;
        d.stopRewriteSession(session);
    }
}
项目:Pydev    文件:TextSelectionUtils.java   
/**
 * Starts a rewrite session (keep things in a single undo/redo)
 */
public static DocumentRewriteSession startWrite(IDocument doc) {
    if (doc instanceof IDocumentExtension4) {
        IDocumentExtension4 d = (IDocumentExtension4) doc;
        return d.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
    }
    return null;
}
项目:Pydev    文件:PyOrganizeImports.java   
/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 */
@Override
public void run(IAction action) {
    try {
        if (!canModifyEditor()) {
            return;
        }

        PyEdit pyEdit = getPyEdit();

        PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(pyEdit);
        final IDocument doc = ps.getDoc();
        if (ps.getStartLineIndex() == ps.getEndLineIndex()) {
            organizeImports(pyEdit, doc, null, ps);
        } else {
            DocumentRewriteSession session = TextSelectionUtils.startWrite(doc);
            try {
                ps.performSimpleSort(doc, ps.getStartLineIndex(), ps.getEndLineIndex());
            } finally {
                TextSelectionUtils.endWrite(doc, session);
            }
        }
    } catch (Exception e) {
        Log.log(e);
        beep(e);
    }
}
项目:tlaplus    文件:TLAFastPartitioner.java   
public void startRewriteSession(DocumentRewriteSession session) throws IllegalStateException {
    if (fActiveRewriteSession != null)
        throw new IllegalStateException();
    fActiveRewriteSession= session;
}
项目:bts    文件:DocumentPartitioner.java   
/**
 * @since 2.2
 */
public void startRewriteSession(DocumentRewriteSession session) throws IllegalStateException {
    if (fActiveRewriteSession != null)
        throw new IllegalStateException();
    fActiveRewriteSession = session;
}
项目:che    文件:FastPartitioner.java   
public void startRewriteSession(DocumentRewriteSession session) throws IllegalStateException {
  if (fActiveRewriteSession != null) throw new IllegalStateException();
  fActiveRewriteSession = session;
}
项目:Pydev    文件:DocCopy.java   
@Override
public DocumentRewriteSession startRewriteSession(DocumentRewriteSessionType sessionType)
        throws IllegalStateException {
    throw new RuntimeException("not implemented");
}
项目:Pydev    文件:DocCopy.java   
@Override
public void stopRewriteSession(DocumentRewriteSession session) {
    throw new RuntimeException("not implemented");
}
项目:Pydev    文件:DocCopy.java   
@Override
public DocumentRewriteSession getActiveRewriteSession() {
    throw new RuntimeException("not implemented");
}
项目:tlaplus    文件:TLAFastPartitioner.java   
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 */
public void stopRewriteSession(DocumentRewriteSession session) {
    if (fActiveRewriteSession == session)
        flushRewriteSession();
}
项目:tlaplus    文件:TLAFastPartitioner.java   
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 */
public DocumentRewriteSession getActiveRewriteSession() {
    return fActiveRewriteSession;
}
项目:bts    文件:DocumentPartitioner.java   
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
public void stopRewriteSession(DocumentRewriteSession session) {
    if (fActiveRewriteSession == session)
        flushRewriteSession();
}
项目:bts    文件:DocumentPartitioner.java   
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
public DocumentRewriteSession getActiveRewriteSession() {
    return fActiveRewriteSession;
}
项目:che    文件:FastPartitioner.java   
/**
 * {@inheritDoc}
 *
 * <p>May be extended by subclasses.
 */
public void stopRewriteSession(DocumentRewriteSession session) {
  if (fActiveRewriteSession == session) flushRewriteSession();
}
项目:che    文件:FastPartitioner.java   
/**
 * {@inheritDoc}
 *
 * <p>May be extended by subclasses.
 */
public DocumentRewriteSession getActiveRewriteSession() {
  return fActiveRewriteSession;
}