Commit edee1589 authored by Anna.Kozlova's avatar Anna.Kozlova
Browse files

invert boolean: don't suggest to rename in batch mode

EA-105820 - assert: RefactoringDialog.show
parent c27d35fd
Branches unavailable Tags unavailable
Showing with 28 additions and 9 deletions
+28 -9
......@@ -133,17 +133,19 @@ class BooleanMethodIsAlwaysInvertedInspectionBase extends GlobalJavaBatchInspect
}
})) return null;
}
return new ProblemDescriptor[]{createProblemDescriptor(manager, psiIdentifier)};
return new ProblemDescriptor[]{createProblemDescriptor(manager, psiIdentifier, false)};
}
}
return null;
}
protected ProblemDescriptor createProblemDescriptor(@NotNull InspectionManager manager, PsiIdentifier psiIdentifier) {
protected ProblemDescriptor createProblemDescriptor(@NotNull InspectionManager manager,
PsiIdentifier psiIdentifier,
boolean onTheFly) {
return manager.createProblemDescriptor(psiIdentifier,
InspectionsBundle.message("boolean.method.is.always.inverted.problem.descriptor"),
getInvertBooleanFix(),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
getInvertBooleanFix(onTheFly),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly);
}
@Override
......@@ -176,10 +178,10 @@ class BooleanMethodIsAlwaysInvertedInspectionBase extends GlobalJavaBatchInspect
@Override
public QuickFix getQuickFix(final String hint) {
return getInvertBooleanFix();
return getInvertBooleanFix(false);
}
protected LocalQuickFix getInvertBooleanFix() {
protected LocalQuickFix getInvertBooleanFix(boolean onTheFly) {
return null;
}
......
......@@ -63,6 +63,6 @@ public class BooleanMethodIsAlwaysInvertedLocalInspection extends AbstractBaseJa
return null;
}
if (usageCount[0] < 2) return null;
return new ProblemDescriptor[] { myGlobalTool.createProblemDescriptor(manager, method.getNameIdentifier()) };
return new ProblemDescriptor[] { myGlobalTool.createProblemDescriptor(manager, method.getNameIdentifier(), isOnTheFly) };
}
}
......@@ -3,6 +3,10 @@
// found in the LICENSE file.
package com.intellij.codeInspection.booleanIsAlwaysInverted;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.refactoring.invertBoolean.InvertBooleanProcessor;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.fixes.InvertBooleanFix;
import org.jetbrains.annotations.NotNull;
......@@ -10,7 +14,20 @@ import org.jetbrains.annotations.NotNull;
public class BooleanMethodIsAlwaysInvertedInspection extends BooleanMethodIsAlwaysInvertedInspectionBase {
@NotNull
@Override
protected InvertBooleanFix getInvertBooleanFix() {
return new InvertBooleanFix(InspectionGadgetsBundle.message("invert.method.quickfix"));
protected LocalQuickFix getInvertBooleanFix(boolean onTheFly) {
return new InvertBooleanFix(InspectionGadgetsBundle.message("invert.method.quickfix")) {
@Override
public void doFix(@NotNull PsiElement element) {
if (onTheFly) {
//show the dialog, suggest to rename
super.doFix(element);
}
else {
PsiElement elementToRefactor = getElementToRefactor(element);
new InvertBooleanProcessor(elementToRefactor, ((PsiNamedElement)elementToRefactor).getName())
.run();
}
}
};
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment