@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, @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) { PsiElement newStatementContainer = descriptor.getPsiElement(); if (!FileModificationService.getInstance().prepareFileForWrite(newStatementContainer.getContainingFile())) { return;