Java Code Examples for com.intellij.openapi.command.undo.UndoUtil#markPsiFileForUndo()

The following examples show how to use com.intellij.openapi.command.undo.UndoUtil#markPsiFileForUndo() . 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: SupressAddShebangInspectionQuickfix.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiFile file = descriptor.getPsiElement().getContainingFile();
    if (file == null) {
        return;
    }

    if (!FileModificationService.getInstance().preparePsiElementForWrite(file)) {
        return;
    }

    PsiComment suppressionComment = SupressionUtil.createSuppressionComment(project, inspectionId);

    PsiElement firstChild = file.getFirstChild();
    PsiElement inserted;
    if (firstChild != null) {
        inserted = file.addBefore(suppressionComment, firstChild);
    } else {
        inserted = file.add(suppressionComment);
    }

    if (inserted != null) {
        file.addAfter(BashPsiElementFactory.createNewline(project), inserted);
    }

    UndoUtil.markPsiFileForUndo(file);
}
 
Example 2
Source File: BaseLombokHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (file.isWritable()) {
    PsiClass psiClass = OverrideImplementUtil.getContextClass(project, editor, file, false);
    if (null != psiClass) {
      processClass(psiClass);

      UndoUtil.markPsiFileForUndo(file);
    }
  }
}
 
Example 3
Source File: QuickFixWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  //if (!CodeInsightUtil.prepareFileForWrite(file)) return;
  // consider all local quick fixes do it themselves

  final PsiElement element = myDescriptor.getPsiElement();
  final PsiFile fileForUndo = element == null ? null : element.getContainingFile();
  LocalQuickFix fix = getFix();
  fix.applyFix(project, myDescriptor);
  DaemonCodeAnalyzer.getInstance(project).restart();
  if (fileForUndo != null && !fileForUndo.equals(file)) {
    UndoUtil.markPsiFileForUndo(fileForUndo);
  }
}
 
Example 4
Source File: AbstractBatchSuppressByNoInspectionCommentFix.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void invoke(@Nonnull final Project project, @Nonnull final PsiElement element) throws IncorrectOperationException {
  if (!isAvailable(project, element)) return;
  PsiElement container = getContainer(element);
  if (container == null) return;

  if (!FileModificationService.getInstance().preparePsiElementForWrite(container)) return;

  if (replaceSuppressionComments(container)) return;

  createSuppression(project, element, container);
  UndoUtil.markPsiFileForUndo(element.getContainingFile());
}
 
Example 5
Source File: AbstractSuppressByNoInspectionCommentFix.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project, @Nullable Editor editor, @Nonnull final PsiElement element) throws IncorrectOperationException {
  PsiElement container = getContainer(element);
  if (container == null) return;

  if (!FileModificationService.getInstance().preparePsiElementForWrite(container)) return;

  final List<? extends PsiElement> comments = getCommentsFor(container);
  if (comments != null) {
    for (PsiElement comment : comments) {
      if (comment instanceof PsiComment && SuppressionUtil.isSuppressionComment(comment)) {
        replaceSuppressionComment(comment);
        return;
      }
    }
  }

  boolean caretWasBeforeStatement = editor != null && editor.getCaretModel().getOffset() == container.getTextRange().getStartOffset();
  try {
    createSuppression(project, element, container);
  }
  catch (IncorrectOperationException e) {
    if (!ApplicationManager.getApplication().isUnitTestMode() && editor != null) {
      Messages.showErrorDialog(editor.getComponent(),
                               InspectionsBundle.message("suppress.inspection.annotation.syntax.error", e.getMessage()));
    }
  }

  if (caretWasBeforeStatement) {
    editor.getCaretModel().moveToOffset(container.getTextRange().getStartOffset());
  }
  UndoUtil.markPsiFileForUndo(element.getContainingFile());
}
 
Example 6
Source File: DelombokHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void finish(Project project, PsiFile psiFile) {
  JavaCodeStyleManager.getInstance(project).optimizeImports(psiFile);
  UndoUtil.markPsiFileForUndo(psiFile);
}