com.intellij.codeInsight.FileModificationService Java Examples

The following examples show how to use com.intellij.codeInsight.FileModificationService. 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: AbstractFileProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void process(final PsiFile file) {
  if (!FileModificationService.getInstance().preparePsiElementForWrite(file)) return;
  final Runnable[] resultRunnable = new Runnable[1];

  execute(new Runnable() {
            public void run() {
              try {
                resultRunnable[0] = preprocessFile(file);
              }
              catch (IncorrectOperationException incorrectoperationexception) {
                logger.error(incorrectoperationexception);
              }
            }
          }, new Runnable() {
            public void run() {
              if (resultRunnable[0] != null) {
                resultRunnable[0].run();
              }
            }
          }
  );
}
 
Example #2
Source File: PasteReferenceProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void insert(final String fqn, final PsiElement element, final Editor editor, final QualifiedNameProvider provider) {
  final Project project = editor.getProject();
  if (project == null) return;

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  documentManager.commitDocument(editor.getDocument());

  final PsiFile file = documentManager.getPsiFile(editor.getDocument());
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> {
    Document document = editor.getDocument();
    documentManager.doPostponedOperationsAndUnblockDocument(document);
    documentManager.commitDocument(document);
    EditorModificationUtil.deleteSelectedText(editor);
    provider.insertQualifiedName(fqn, element, editor, project);
  }), IdeBundle.message("command.pasting.reference"), null);
}
 
Example #3
Source File: CleanupInspectionIntention.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {

  final List<ProblemDescriptor> descriptions =
          ProgressManager.getInstance().runProcess(() -> {
            InspectionManager inspectionManager = InspectionManager.getInstance(project);
            return InspectionEngine.runInspectionOnFile(file, myToolWrapper, inspectionManager.createNewGlobalContext(false));
          }, new EmptyProgressIndicator());

  if (!descriptions.isEmpty() && !FileModificationService.getInstance().preparePsiElementForWrite(file)) return;

  final AbstractPerformFixesTask fixesTask = applyFixes(project, "Apply Fixes", descriptions, myQuickfixClass);

  if (!fixesTask.isApplicableFixFound()) {
    HintManager.getInstance().showErrorHint(editor, "Unfortunately '" + myText + "' is currently not available for batch mode\n User interaction is required for each problem found");
  }
}
 
Example #4
Source File: CodeInsightAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
public void actionPerformedImpl(@Nonnull final Project project, final Editor editor) {
  if (editor == null) return;
  //final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) return;
  final CodeInsightActionHandler handler = getHandler();
  PsiElement elementToMakeWritable = handler.getElementToMakeWritable(psiFile);
  if (elementToMakeWritable != null && !(EditorModificationUtil.checkModificationAllowed(editor) && FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable))) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, () -> {
    final Runnable action = () -> {
      if (!ApplicationManager.getApplication().isHeadlessEnvironment() && !editor.getContentComponent().isShowing()) return;
      handler.invoke(project, editor, psiFile);
    };
    if (handler.startInWriteAction()) {
      ApplicationManager.getApplication().runWriteAction(action);
    }
    else {
      action.run();
    }
  }, getCommandName(), DocCommandGroupId.noneGroupId(editor.getDocument()), editor.getDocument());
}
 
Example #5
Source File: PropertySuppressableInspectionBase.java    From eslint-plugin with MIT License 6 votes vote down vote up
public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
            final PsiFile file = element.getContainingFile();
            if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

//            InspectionManager inspectionManager = InspectionManager.getInstance(project);
//            ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(element, element, "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);

            final JSElement property = PsiTreeUtil.getParentOfType(element, JSElement.class);
            LOG.assertTrue(property != null);
            final int start = property.getTextRange().getStartOffset();

            @NonNls final Document doc = PsiDocumentManager.getInstance(project).getDocument(file);
            LOG.assertTrue(doc != null);
            final int line = doc.getLineNumber(start);
            final int lineEnd = doc.getLineEndOffset(line);
            doc.insertString(lineEnd, " //eslint-disable-line " + rule);
        }
 
Example #6
Source File: SuppressLineActionFix.java    From eslint-plugin with MIT License 6 votes vote down vote up
@Override
    public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
//        final PsiFile file = element.getContainingFile();
        if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

//  InspectionManager inspectionManager = InspectionManager.getInstance(project);
//  ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(element, element, "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);

        final JSElement property = PsiTreeUtil.getParentOfType(element, JSElement.class);
        LOG.assertTrue(property != null);
        final int start = property.getTextRange().getStartOffset();

        @NonNls final Document doc = PsiDocumentManager.getInstance(project).getDocument(file);
        LOG.assertTrue(doc != null);
        final int line = doc.getLineNumber(start);
        final int lineEnd = doc.getLineEndOffset(line);
        doc.insertString(lineEnd, " //eslint-disable-line " + rule);
        DaemonCodeAnalyzer.getInstance(project).restart(file);
    }
 
Example #7
Source File: SuppressActionFix.java    From eslint-plugin with MIT License 6 votes vote down vote up
@Override
    public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
//        final PsiFile file = element.getContainingFile();
        if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

//  InspectionManager inspectionManager = InspectionManager.getInstance(project);
//  ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(element, element, "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);

        final JSElement property = PsiTreeUtil.getParentOfType(element, JSElement.class);
        LOG.assertTrue(property != null);
        final int start = property.getTextRange().getStartOffset();

        @NonNls final Document doc = PsiDocumentManager.getInstance(project).getDocument(file);
        LOG.assertTrue(doc != null);
        final int line = doc.getLineNumber(start);
        final int lineStart = doc.getLineStartOffset(line);

        doc.insertString(lineStart, "/*eslint " + rule + ":0*/\n");
        DaemonCodeAnalyzer.getInstance(project).restart(file);
    }
 
Example #8
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 #9
Source File: ShowIntentionActionsHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void invokeIntention(@Nonnull IntentionAction action, @Nullable Editor editor, @Nonnull PsiFile file) {
  //IntentionsCollector.getInstance().record(file.getProject(), action, file.getLanguage());
  PsiElement elementToMakeWritable = action.getElementToMakeWritable(file);
  if (elementToMakeWritable != null && !FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable)) {
    return;
  }

  Runnable r = () -> action.invoke(file.getProject(), editor, file);
  if (action.startInWriteAction()) {
    WriteAction.run(r::run);
  }
  else {
    r.run();
  }
}
 
Example #10
Source File: LookupImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void finishLookup(char completionChar, @Nullable final LookupElement item) {
  LOG.assertTrue(!ApplicationManager.getApplication().isWriteAccessAllowed(), "finishLookup should be called without a write action");
  final PsiFile file = getPsiFile();
  boolean writableOk = file == null || FileModificationService.getInstance().prepareFileForWrite(file);
  if (myDisposed) { // ensureFilesWritable could close us by showing a dialog
    return;
  }

  if (!writableOk) {
    hideWithItemSelected(null, completionChar);
    return;
  }
  CommandProcessor.getInstance().executeCommand(myProject, () -> finishLookupInWritableFile(completionChar, item), null, null);
}
 
Example #11
Source File: SurroundWithTemplateHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static DefaultActionGroup createActionGroup(Project project, Editor editor, PsiFile file) {
  if (!editor.getSelectionModel().hasSelection()) {
    editor.getSelectionModel().selectLineAtCaret();
    if (!editor.getSelectionModel().hasSelection()) return null;
  }
  PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
  List<CustomLiveTemplate> customTemplates = TemplateManagerImpl.listApplicableCustomTemplates(editor, file, true);
  List<TemplateImpl> templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, true);
  if (templates.isEmpty() && customTemplates.isEmpty()) {
    HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("templates.surround.no.defined"));
    return null;
  }

  if (!FileModificationService.getInstance().preparePsiElementForWrite(file)) return null;

  Set<Character> usedMnemonicsSet = new HashSet<>();
  DefaultActionGroup group = new DefaultActionGroup();

  for (TemplateImpl template : templates) {
    group.add(new InvokeTemplateAction(template, editor, project, usedMnemonicsSet));
  }

  for (CustomLiveTemplate customTemplate : customTemplates) {
    group.add(new WrapWithCustomTemplateAction(customTemplate, editor, file, usedMnemonicsSet));
  }
  return group;
}
 
Example #12
Source File: FixDocCommentAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void process(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final Project project, int offset) {
  PsiElement elementAtOffset = file.findElementAt(offset);
  if (elementAtOffset == null || !FileModificationService.getInstance().preparePsiElementForWrite(elementAtOffset)) {
    return;
  }
  generateOrFixComment(elementAtOffset, project, editor);
}
 
Example #13
Source File: UnwrapHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final PsiFile file = myElement.getContainingFile();
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          try {
            UnwrapDescriptor d = getUnwrapDescription(file);
            if (d.shouldTryToRestoreCaretPosition()) saveCaretPosition(file);
            int scrollOffset = myEditor.getScrollingModel().getVerticalScrollOffset();

            List<PsiElement> extractedElements = myUnwrapper.unwrap(myEditor, myElement);

            if (d.shouldTryToRestoreCaretPosition()) restoreCaretPosition(file);
            myEditor.getScrollingModel().scrollVertically(scrollOffset);

            highlightExtractedElements(extractedElements);
          }
          catch (IncorrectOperationException ex) {
            throw new RuntimeException(ex);
          }
        }
      });
    }
  }, null, myEditor.getDocument());
}
 
Example #14
Source File: RenameElementFix.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project,
                   @Nonnull final PsiFile file,
                   @Nullable Editor editor,
                   @Nonnull final PsiElement startElement,
                   @Nonnull PsiElement endElement) {
  if (isAvailable(project, null, file)) {
    LOG.assertTrue(file == startElement.getContainingFile());
    if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
    RenameProcessor processor = new RenameProcessor(project, startElement, myNewName, false, false);
    processor.run();
  }
}
 
Example #15
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 #16
Source File: HippieWordCompletionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void invoke(@Nonnull Project project, @Nonnull final Editor editor, @Nonnull PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  LookupManager.getInstance(project).hideActiveLookup();

  final CharSequence charsSequence = editor.getDocument().getCharsSequence();

  final CompletionData data = computeData(editor, charsSequence);
  String currentPrefix = data.myPrefix;

  final CompletionState completionState = getCompletionState(editor);

  String oldPrefix = completionState.oldPrefix;
  CompletionVariant lastProposedVariant = completionState.lastProposedVariant;

  if (lastProposedVariant == null || oldPrefix == null || !new CamelHumpMatcher(oldPrefix).isStartMatch(currentPrefix) ||
      !currentPrefix.equals(lastProposedVariant.variant)) {
    //we are starting over
    oldPrefix = currentPrefix;
    completionState.oldPrefix = oldPrefix;
    lastProposedVariant = null;
  }

  CompletionVariant nextVariant = computeNextVariant(editor, oldPrefix, lastProposedVariant, data, file);
  if (nextVariant == null) return;

  int replacementEnd = data.startOffset + data.myWordUnderCursor.length();
  editor.getDocument().replaceString(data.startOffset, replacementEnd, nextVariant.variant);
  editor.getCaretModel().moveToOffset(data.startOffset + nextVariant.variant.length());
  completionState.lastProposedVariant = nextVariant;
  highlightWord(nextVariant, project, data);
}
 
Example #17
Source File: Browser.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void invokeFix(final RefEntity element, final CommonProblemDescriptor descriptor, final int idx) {
  final QuickFix[] fixes = descriptor.getFixes();
  if (fixes != null && fixes.length > idx && fixes[idx] != null) {
    if (element instanceof RefElement) {
      PsiElement psiElement = ((RefElement)element).getElement();
      if (psiElement != null && psiElement.isValid()) {
        if (!FileModificationService.getInstance().preparePsiElementForWrite(psiElement)) return;
        performFix(element, descriptor, idx, fixes[idx]);
      }
    }
    else {
      performFix(element, descriptor, idx, fixes[idx]);
    }
  }
}
 
Example #18
Source File: AbstractBaseIntention.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) throws IncorrectOperationException {
    if (!FileModificationService.getInstance().prepareFileForWrite(file)) {
        return;
    }

    PsiDocumentManager.getInstance(project).commitAllDocuments();
    T parentAtCaret = getParentAtCaret(editor, file);
    if (parentAtCaret != null) {
        ApplicationManager.getApplication().runWriteAction(() -> runInvoke(project, parentAtCaret));
    }
}
 
Example #19
Source File: WriteCommandAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void performWriteCommandAction(@Nonnull RunResult<T> result) {
  if (!FileModificationService.getInstance().preparePsiElementsForWrite(Arrays.asList(myPsiFiles))) return;

  // this is needed to prevent memory leak, since the command is put into undo queue
  final RunResult[] results = {result};

  doExecuteCommand(() -> {
    //noinspection deprecation
    ApplicationManager.getApplication().runWriteAction(() -> {
      results[0].run();
      results[0] = null;
    });
  });
}
 
Example #20
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 #21
Source File: CleanupIntention.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().preparePsiElementForWrite(file)) return;
  final InspectionManager managerEx = InspectionManager.getInstance(project);
  final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)managerEx.createNewGlobalContext(false);
  final AnalysisScope scope = getScope(project, file);
  if (scope != null) {
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
    globalContext.codeCleanup(project, scope, profile, getText(), null, false);
  }
}
 
Example #22
Source File: BaseHaxeGenerateHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
  final HaxeClass haxeClass =
    PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), HaxeClassDeclaration.class);
  if (haxeClass == null) return;

  final List<HaxeNamedComponent> candidates = new ArrayList<HaxeNamedComponent>();
  collectCandidates(haxeClass, candidates);

  List<HaxeNamedElementNode> selectedElements = Collections.emptyList();
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    selectedElements = ContainerUtil.map(candidates, new Function<HaxeNamedComponent, HaxeNamedElementNode>() {
      @Override
      public HaxeNamedElementNode fun(HaxeNamedComponent namedComponent) {
        return new HaxeNamedElementNode(namedComponent);
      }
    });
  }
  else if (!candidates.isEmpty()) {
    final MemberChooser<HaxeNamedElementNode> chooser =
      createMemberChooserDialog(project, haxeClass, candidates, getTitle());
    chooser.show();
    selectedElements = chooser.getSelectedElements();
  }

  final BaseCreateMethodsFix createMethodsFix = createFix(haxeClass);
  doInvoke(project, editor, file, selectedElements, createMethodsFix);
}
 
Example #23
Source File: PropertySuppressableInspectionBase.java    From eslint-plugin with MIT License 5 votes vote down vote up
public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
            final PsiFile file = element.getContainingFile();
            if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

            @NonNls final Document doc = PsiDocumentManager.getInstance(project).getDocument(file);
            LOG.assertTrue(doc != null, file);

//            doc.insertString(0, "// eslint suppress inspection \"" + rule + "\" for whole file\n");
            doc.insertString(0, "/* eslint-disable */\n");
        }
 
Example #24
Source File: QuickFixAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void doApplyFix(@Nonnull final Project project,
                        @Nonnull final CommonProblemDescriptor[] descriptors,
                        @Nonnull final GlobalInspectionContextImpl context) {
  final Set<VirtualFile> readOnlyFiles = new THashSet<VirtualFile>();
  for (CommonProblemDescriptor descriptor : descriptors) {
    final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getPsiElement() : null;
    if (psiElement != null && !psiElement.isWritable()) {
      readOnlyFiles.add(psiElement.getContainingFile().getVirtualFile());
    }
  }

  if (!FileModificationService.getInstance().prepareVirtualFilesForWrite(project, readOnlyFiles)) return;

  final RefManagerImpl refManager = (RefManagerImpl)context.getRefManager();

  final boolean initial = refManager.isInProcess();

  refManager.inspectionReadActionFinished();

  try {
    final Set<PsiElement> ignoredElements = new HashSet<PsiElement>();

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
      @Override
      public void run() {
        CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            final SequentialModalProgressTask progressTask =
              new SequentialModalProgressTask(project, getTemplatePresentation().getText(), false);
            progressTask.setMinIterationTime(200);
            progressTask.setTask(new PerformFixesTask(project, descriptors, ignoredElements, progressTask, context));
            ProgressManager.getInstance().run(progressTask);
          }
        });
      }
    }, getTemplatePresentation().getText(), null);

    refreshViews(project, ignoredElements, myToolWrapper);
  }
  finally { //to make offline view lazy
    if (initial) refManager.inspectionReadActionStarted();
  }
}
 
Example #25
Source File: WriteCommandAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
/** @deprecated use {@link FileModificationService#preparePsiElementsForWrite(Collection)} (to be removed in IDEA 2018) */
@SuppressWarnings("unused")
public static boolean ensureFilesWritable(@Nonnull Project project, @Nonnull Collection<PsiFile> psiFiles) {
  return FileModificationService.getInstance().preparePsiElementsForWrite(psiFiles);
}
 
Example #26
Source File: RenameFileReferenceIntentionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
  myFileReference.handleElementRename(myExistingElementName);
}
 
Example #27
Source File: AnalysisScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * scope elements should be checked only when needed
 */
@Deprecated
public boolean checkScopeWritable(@Nonnull Project project) {
  if (myFilesSet == null) initFilesSet();
  return !FileModificationService.getInstance().prepareVirtualFilesForWrite(project, myFilesSet);
}
 
Example #28
Source File: BaseCreateMethodsFix.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
  evalAnchor(editor, file);
  processElements(project, getElementsToProcess());
}