diff --git a/java/java-impl-refactorings/src/com/siyeh/ipp/functional/ExtractToMethodReferenceIntention.java b/java/java-impl-refactorings/src/com/siyeh/ipp/functional/ExtractToMethodReferenceIntention.java index 9de1d4183f22..d6370138a2f0 100644 --- a/java/java-impl-refactorings/src/com/siyeh/ipp/functional/ExtractToMethodReferenceIntention.java +++ b/java/java-impl-refactorings/src/com/siyeh/ipp/functional/ExtractToMethodReferenceIntention.java @@ -47,7 +47,7 @@ public class ExtractToMethodReferenceIntention extends BaseElementAtCaretIntenti } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class, false); if (lambdaExpression != null) { PsiElement body = lambdaExpression.getBody(); @@ -84,7 +84,7 @@ public class ExtractToMethodReferenceIntention extends BaseElementAtCaretIntenti } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class, false); if (lambdaExpression != null) { PsiCodeBlock body = CommonJavaRefactoringUtil.expandExpressionLambdaToCodeBlock(lambdaExpression); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/problems/pass/ProjectProblemUtils.java b/java/java-impl/src/com/intellij/codeInsight/daemon/problems/pass/ProjectProblemUtils.java index 2705c4416841..f450c04c394a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/problems/pass/ProjectProblemUtils.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/problems/pass/ProjectProblemUtils.java @@ -160,12 +160,12 @@ public final class ProjectProblemUtils { private static final class ShowRelatedProblemsAction extends BaseElementAtCaretIntentionAction { @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { return ProjectProblemCodeVisionProviderKt.isCodeVisionEnabled(project); } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class); if (member == null) return; showProblems(editor, member); diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddExplicitTypeArgumentsIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddExplicitTypeArgumentsIntention.java index 1120f78a42c2..d0281707a159 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddExplicitTypeArgumentsIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddExplicitTypeArgumentsIntention.java @@ -22,7 +22,7 @@ public class AddExplicitTypeArgumentsIntention extends BaseElementAtCaretIntenti } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { PsiIdentifier identifier = ObjectUtils.tryCast(element, PsiIdentifier.class); if (identifier == null) return false; PsiReferenceExpression methodExpression = ObjectUtils.tryCast(identifier.getParent(), PsiReferenceExpression.class); @@ -40,7 +40,7 @@ public class AddExplicitTypeArgumentsIntention extends BaseElementAtCaretIntenti } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class); assert callExpression != null; PsiExpression withArgs = AddTypeArgumentsFix.addTypeArguments(callExpression, null); diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java index b8e8c6b89253..dc29a6577b72 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java @@ -17,12 +17,12 @@ import org.jetbrains.annotations.NotNull; public class AddJavadocIntention extends BaseElementAtCaretIntentionAction implements LowPriorityAction { @Override - public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull final Project project, final @NotNull Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { FixDocCommentAction.generateOrFixComment(element, project, editor); } @Override - public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull final Project project, final @NotNull Editor editor, @NotNull PsiElement element) { if (element instanceof PsiIdentifier || element instanceof PsiJavaCodeReferenceElement || element instanceof PsiJavaModuleReferenceElement) { diff --git a/java/java-impl/src/com/siyeh/ipp/annotation/AnnotateOverriddenMethodsIntention.java b/java/java-impl/src/com/siyeh/ipp/annotation/AnnotateOverriddenMethodsIntention.java index 724ca8e5c431..222a5cd71f3d 100644 --- a/java/java-impl/src/com/siyeh/ipp/annotation/AnnotateOverriddenMethodsIntention.java +++ b/java/java-impl/src/com/siyeh/ipp/annotation/AnnotateOverriddenMethodsIntention.java @@ -62,7 +62,7 @@ public class AnnotateOverriddenMethodsIntention extends BaseElementAtCaretIntent } @Override - public final boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement node) { + public final boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement node) { final PsiAnnotation annotation = (PsiAnnotation)findMatchingElement(node); if (annotation == null) return false; final String annotationText = annotation.getText(); @@ -82,7 +82,7 @@ public class AnnotateOverriddenMethodsIntention extends BaseElementAtCaretIntent } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element){ + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element){ final PsiAnnotation annotation = (PsiAnnotation)findMatchingElement(element); if (annotation == null) return; final String annotationName = annotation.getQualifiedName(); diff --git a/java/java-impl/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java b/java/java-impl/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java index ae61c076d805..5418f20e11a1 100644 --- a/java/java-impl/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java +++ b/java/java-impl/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java @@ -84,7 +84,7 @@ public class ChangeModifierIntention extends BaseElementAtCaretIntentionAction { } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { if (!JavaLanguage.INSTANCE.equals(element.getLanguage())) return false; PsiMember member = findMember(element); if (!(member instanceof PsiNameIdentifierOwner)) return false; @@ -132,7 +132,7 @@ public class ChangeModifierIntention extends BaseElementAtCaretIntentionAction { } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { PsiMember member = findMember(element); if (member == null) return; PsiFile file = member.getContainingFile(); diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertAtomicToLongAdderIntention.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertAtomicToLongAdderIntention.java index d6d640446ca7..5160d56d6829 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertAtomicToLongAdderIntention.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertAtomicToLongAdderIntention.java @@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicLong; public class ConvertAtomicToLongAdderIntention extends BaseElementAtCaretIntentionAction { @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { final PsiVariable variable = getVariable(element); if (variable != null) { final PsiType longAdder = @@ -33,7 +33,7 @@ public class ConvertAtomicToLongAdderIntention extends BaseElementAtCaretIntenti } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { if (!element.isValid() || !PsiUtil.isLanguageLevel8OrHigher(element)) return false; final PsiVariable variable = getVariable(element); return variable != null; diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java index 7ba973452a80..f1f46da3b6a4 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java @@ -91,7 +91,7 @@ public class ConvertFieldToAtomicIntention extends BaseElementAtCaretIntentionAc } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { PsiVariable psiVariable = getVariable(element); if (psiVariable == null || psiVariable instanceof PsiResourceVariable) return false; if (psiVariable.getLanguage() != JavaLanguage.INSTANCE) return false; @@ -126,7 +126,7 @@ public class ConvertFieldToAtomicIntention extends BaseElementAtCaretIntentionAc } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { PsiVariable var = getVariable(element); LOG.assertTrue(var != null); @@ -238,7 +238,7 @@ public class ConvertFieldToAtomicIntention extends BaseElementAtCaretIntentionAc } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { return getVariable(element) != null; } diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToThreadLocalIntention.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToThreadLocalIntention.java index 15a7bcd0890e..16dc81c6ac35 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToThreadLocalIntention.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToThreadLocalIntention.java @@ -43,7 +43,7 @@ public class ConvertFieldToThreadLocalIntention extends BaseElementAtCaretIntent } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { if (!(element instanceof PsiIdentifier)) return false; PsiElement parent = element.getParent(); if (!(parent instanceof PsiField field)) return false; @@ -57,7 +57,7 @@ public class ConvertFieldToThreadLocalIntention extends BaseElementAtCaretIntent } @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { final PsiField psiField = PsiTreeUtil.getParentOfType(element, PsiField.class); LOG.assertTrue(psiField != null); diff --git a/json/src/com/intellij/json/intentions/JsonSortPropertiesIntention.kt b/json/src/com/intellij/json/intentions/JsonSortPropertiesIntention.kt index efc785fb1923..6b0f044162be 100644 --- a/json/src/com/intellij/json/intentions/JsonSortPropertiesIntention.kt +++ b/json/src/com/intellij/json/intentions/JsonSortPropertiesIntention.kt @@ -26,13 +26,12 @@ open class JsonSortPropertiesIntention : BaseElementAtCaretIntentionAction(), Lo override fun getFamilyName(): @Nls(capitalization = Nls.Capitalization.Sentence) String = JsonBundle.message("json.intention.sort.properties") - override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean { - return editor != null && Session(editor, element).hasUnsortedObjects() + override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean { + return Session(editor, element).hasUnsortedObjects() } @Throws(IncorrectOperationException::class) - override fun invoke(project: Project, editor: Editor?, element: PsiElement) { - editor ?: return + override fun invoke(project: Project, editor: Editor, element: PsiElement) { if (!CommonRefactoringUtil.checkReadOnlyStatus(project, element)) { CommonRefactoringUtil.showErrorHint(project, editor, JsonBundle.message("file.is.readonly"), JsonBundle.message("cannot.sort.properties"), null) diff --git a/platform/lang-api/src/com/intellij/codeInsight/intention/BaseElementAtCaretIntentionAction.java b/platform/lang-api/src/com/intellij/codeInsight/intention/BaseElementAtCaretIntentionAction.java index b569dcab3bae..4fe74551d79b 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/intention/BaseElementAtCaretIntentionAction.java +++ b/platform/lang-api/src/com/intellij/codeInsight/intention/BaseElementAtCaretIntentionAction.java @@ -15,7 +15,7 @@ public abstract class BaseElementAtCaretIntentionAction extends BaseIntentionAct @Override public final boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - if (!checkFile(file)) return false; + if (editor == null || file == null || !checkFile(file)) return false; useElementToTheLeft = false; int offset = editor.getCaretModel().getOffset(); @@ -46,14 +46,14 @@ public abstract class BaseElementAtCaretIntentionAction extends BaseIntentionAct * @param element the element under caret. * @return true if the intention is available, false otherwise. */ - public abstract boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element); + public abstract boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element); @Override public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + if (editor == null || file == null) return; + PsiElement element = getElement(editor, file); - if (element == null) { - return; - } + if (element == null) return; invoke(project, editor, element); } @@ -66,7 +66,7 @@ public abstract class BaseElementAtCaretIntentionAction extends BaseIntentionAct * @param element the element under cursor. * @throws IncorrectOperationException On errors. */ - public abstract void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException; + public abstract void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException; /** * Retrieves the element this intention was invoked on. diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/inspections/IntentionOnElementAtCaretWrapper.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/inspections/IntentionOnElementAtCaretWrapper.kt index bbffc953f634..ce9b51016cb3 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/inspections/IntentionOnElementAtCaretWrapper.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/inspections/IntentionOnElementAtCaretWrapper.kt @@ -15,7 +15,7 @@ internal open class IntentionOnElementAtCaretWrapper(intention: BaseElementAtCar val element = descriptor.psiElement ?: return val file = element.containingFile ?: return val fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file.virtualFile) - val editor = (fileEditor as? TextEditor)?.editor + val editor = (fileEditor as? TextEditor)?.editor ?: return val action = action as BaseElementAtCaretIntentionAction action.invoke(project, editor, element) } diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/FixCellAlignmentIntention.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/FixCellAlignmentIntention.kt index eea15fe7cbd5..96c41c7f8aac 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/FixCellAlignmentIntention.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/FixCellAlignmentIntention.kt @@ -19,16 +19,15 @@ internal class FixCellAlignmentIntention: BaseElementAtCaretIntentionAction() { return MarkdownBundle.message("markdown.fix.cell.alignment.intention.text") } - override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean { + override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean { val cell = TableUtils.findCell(element) - if (editor == null || cell == null || cell.parentTable == null) { + if (cell == null || cell.parentTable == null) { return false } return !cell.hasCorrectPadding() || !cell.hasValidAlignment() } - override fun invoke(project: Project, editor: Editor?, element: PsiElement) { - requireNotNull(editor) + override fun invoke(project: Project, editor: Editor, element: PsiElement) { val cell = TableUtils.findCell(element) ?: return val expectedAlignment = cell.parentTable?.getColumnAlignment(cell.columnIndex) ?: return cell.updateAlignment(editor.document, expectedAlignment) diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/ReformatTableIntention.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/ReformatTableIntention.kt index 9f8f6e02d53c..9df38700d62e 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/ReformatTableIntention.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/editor/tables/intentions/ReformatTableIntention.kt @@ -17,16 +17,15 @@ internal class ReformatTableIntention: BaseElementAtCaretIntentionAction() { return MarkdownBundle.message("markdown.reformat.table.intention.text") } - override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean { + override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean { val table = TableUtils.findTable(element) - if (editor == null || table == null) { + if (table == null) { return false } return !table.isCorrectlyFormatted() } - override fun invoke(project: Project, editor: Editor?, element: PsiElement) { - requireNotNull(editor) + override fun invoke(project: Project, editor: Editor, element: PsiElement) { val table = TableUtils.findTable(element)!! TableFormattingUtils.reformatAllColumns(table, editor.document, trimToMaxContent = true) }