@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; perform(getImportPathVariantsToImport(startElement), file, editor); }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!FileModificationService.getInstance().preparePsiElementsForWrite(startElement)) return; Runnable runnable = () -> { AsyncResult<DataContext> dataContextContainer = DataManager.getInstance().getDataContextFromFocus(); dataContextContainer.doWhenDone(new Consumer<DataContext>() { @Override public void consume(DataContext dataContext) { RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(dataContext); if (renameHandler != null) { renameHandler.invoke(project, new PsiElement[]{startElement}, dataContext); } else { RefactoringActionHandler renameRefactoringHandler = RefactoringActionHandlerFactory.getInstance().createRenameHandler(); renameRefactoringHandler.invoke(project, new PsiElement[]{startElement}, dataContext); } } }); }; if (ApplicationManager.getApplication().isUnitTestMode()) { runnable.run(); } else { ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed()); } }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!FileModificationService.getInstance().prepareFileForWrite(file)) { return; } if (!(file instanceof BallerinaFile)) { return; } BallerinaFile ballerinaFile = ((BallerinaFile) file); PsiReference reference = startElement.getReference(); if (reference != null && reference.resolve() != null) { return; } List<String> importPathVariantsToImport = getImportPathVariantsToImport(startElement); if (importPathVariantsToImport.size() == 1) { Runnable addImport = () -> BallerinaFile.addImport(ballerinaFile, importPathVariantsToImport.get(0), null); CommandProcessor.getInstance().runUndoTransparentAction( () -> ApplicationManager.getApplication().runWriteAction(addImport) ); } else { performImport(importPathVariantsToImport, ballerinaFile, editor); } }
@Override public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement elm = descriptor.getPsiElement(); if (!FileModificationService.getInstance().prepareFileForWrite(elm.getContainingFile())) return; final PsiDocumentManager manager = PsiDocumentManager.getInstance(project); final Document doc = manager.getDocument(elm.getContainingFile()); if (doc != null && doc.isWritable()) { doc.insertString(descriptor.getTextRangeInElement().getEndOffset(), ";"); } else { LOG.warn("Document was null or not writable!"); } } }
@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); } }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement newStatementContainer = descriptor.getPsiElement(); if (!FileModificationService.getInstance().prepareFileForWrite(newStatementContainer.getContainingFile())) { return;