Java Code Examples for com.intellij.openapi.command.CommandProcessor#isUndoTransparentActionInProgress()

The following examples show how to use com.intellij.openapi.command.CommandProcessor#isUndoTransparentActionInProgress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PomModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void startTransaction(@Nonnull PomTransaction transaction) {
  final PsiDocumentManagerBase manager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(myProject);
  final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer();
  final PsiElement changeScope = transaction.getChangeScope();

  final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
  if (containingFileByTree != null && !(containingFileByTree instanceof DummyHolder) && !manager.isCommitInProgress()) {
    PsiUtilCore.ensureValid(containingFileByTree);
  }

  boolean physical = changeScope.isPhysical();
  if (synchronizer.toProcessPsiEvent()) {
    // fail-fast to prevent any psi modifications that would cause psi/document text mismatch
    // PsiToDocumentSynchronizer assertions happen inside event processing and are logged by PsiManagerImpl.fireEvent instead of being rethrown
    // so it's important to throw something outside event processing
    if (isDocumentUncommitted(containingFileByTree)) {
      throw new IllegalStateException("Attempt to modify PSI for non-committed Document!");
    }
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    if (physical && !commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null) {
      throw new IncorrectOperationException(
              "Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor");
    }
  }

  if (containingFileByTree != null) {
    ((SmartPointerManagerImpl)SmartPointerManager.getInstance(myProject)).fastenBelts(containingFileByTree.getViewProvider().getVirtualFile());
    if (containingFileByTree instanceof PsiFileImpl) {
      ((PsiFileImpl)containingFileByTree).beforeAstChange();
    }
  }

  BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl)PsiManager.getInstance(myProject), changeScope, true);
  Document document = containingFileByTree == null ? null : physical ? manager.getDocument(containingFileByTree) : manager.getCachedDocument(containingFileByTree);
  if (document != null) {
    synchronizer.startTransaction(myProject, document, changeScope);
  }
}
 
Example 2
Source File: DocumentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void assertInsideCommand() {
  if (!myAssertThreading) return;
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  if (!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null) {
    throw new IncorrectOperationException(
            "Must not change document outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor");
  }
}