From 196c7248dbae8f3bc18fc394e1cea28cdae0d3b3 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 1 Oct 2021 10:36:45 +0200 Subject: [PATCH] invert boolean inspection: do not provide fix when refactoring is not supported EA-378560 (plugin) - T: InvertBooleanProcessor. GitOrigin-RevId: 97a0e147c2072f986591d44280daf2da5a3433fe --- .../invertBoolean/InvertBooleanHandler.java | 15 +++------------ .../invertBoolean/InvertBooleanProcessor.java | 4 ++-- .../BooleanMethodIsAlwaysInvertedInspection.java | 7 +++---- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanHandler.java b/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanHandler.java index 2e3fbf8aee70..8aa93117fbc4 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.invertBoolean; import com.intellij.openapi.actionSystem.CommonDataKeys; @@ -30,7 +30,7 @@ public class InvertBooleanHandler implements RefactoringActionHandler { if (element == null) { element = file.findElementAt(editor.getCaretModel().getOffset()); } - final InvertBooleanDelegate delegate = findDelegate(element, project, editor); + final InvertBooleanDelegate delegate = InvertBooleanDelegate.findInvertBooleanDelegate(element); if (delegate == null) { CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage( RefactoringBundle.message("error.wrong.caret.position.method.or.variable.name")), getRefactoringName(), INVERT_BOOLEAN_HELP_ID); @@ -42,19 +42,10 @@ public class InvertBooleanHandler implements RefactoringActionHandler { } } - public static InvertBooleanDelegate findDelegate(PsiElement element, Project project, Editor editor) { - for (InvertBooleanDelegate delegate : InvertBooleanDelegate.EP_NAME.getExtensionList()) { - if (delegate.isVisibleOnElement(element)) { - return delegate; - } - } - return null; - } - @Override public void invoke(@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) { LOG.assertTrue(elements.length == 1); - final InvertBooleanDelegate delegate = findDelegate(elements[0], project, null); + final InvertBooleanDelegate delegate = InvertBooleanDelegate.findInvertBooleanDelegate(elements[0]); if (delegate == null) { CommonRefactoringUtil.showErrorHint(project, null, RefactoringBundle.getCannotRefactorMessage( RefactoringBundle.message("error.wrong.caret.position.method.or.variable.name")), getRefactoringName(), INVERT_BOOLEAN_HELP_ID); diff --git a/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java index f8071c7bc79d..5a48d413a7d8 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.invertBoolean; import com.intellij.openapi.diagnostic.Logger; @@ -56,7 +56,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor { } : null; mySmartPointerManager = SmartPointerManager.getInstance(project); myDelegate = InvertBooleanDelegate.findInvertBooleanDelegate(myElement); - LOG.assertTrue(myDelegate != null); + LOG.assertTrue(myDelegate != null, myElement); } @Override diff --git a/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java b/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java index abf3cb4e222e..3e076356619e 100644 --- a/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java +++ b/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java @@ -1,6 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. -// Use of this source code is governed by the Apache 2.0 license that can be -// found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInspection.booleanIsAlwaysInverted; import com.intellij.analysis.AnalysisScope; @@ -11,6 +9,7 @@ import com.intellij.openapi.util.Key; import com.intellij.psi.*; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.refactoring.invertBoolean.InvertBooleanDelegate; import com.intellij.refactoring.invertBoolean.InvertBooleanProcessor; import com.intellij.util.CommonProcessors; import com.intellij.util.ObjectUtils; @@ -96,7 +95,7 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaBatchInsp boolean onTheFly) { return manager.createProblemDescriptor(psiIdentifier, JavaBundle.message("boolean.method.is.always.inverted.problem.descriptor"), - getInvertBooleanFix(onTheFly), + InvertBooleanDelegate.findInvertBooleanDelegate(psiIdentifier.getParent()) != null ? getInvertBooleanFix(onTheFly) : null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly); }