invert boolean inspection: do not provide fix when refactoring is not supported

EA-378560 (plugin) - T: InvertBooleanProcessor.<init>

GitOrigin-RevId: 97a0e147c2072f986591d44280daf2da5a3433fe
This commit is contained in:
Anna Kozlova
2021-10-04 06:20:53 +00:00
committed by intellij-monorepo-bot
parent e283050a3e
commit 196c7248db
3 changed files with 8 additions and 18 deletions
@@ -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);
@@ -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
@@ -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);
}