BaseInspection#buildFix: reverted to InspectionGadgetsFix

JavaDoc written
EmptyStatementBodyInspection: DelegateFix used
Review ID: IDEA-CR-24705
This commit is contained in:
Tagir Valeev
2017-09-27 10:08:14 +07:00
parent 21efef3417
commit 97bede443c
3 changed files with 35 additions and 15 deletions
@@ -18,7 +18,6 @@ package com.siyeh.ig;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.BaseJavaBatchLocalInspectionTool;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
@@ -81,13 +80,33 @@ public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool {
return false;
}
/**
* Build a fix for this inspection based on infos passed to {@link BaseInspectionVisitor#registerError(PsiElement, Object...)}
* or similar methods. Override this method in concrete inspection to provide a fix.
* Use {@link DelegatingFix} if your fix does not extend {@link InspectionGadgetsFix}.
*
* <p>
* This method is ignored is {@link #buildFixes(Object...)} is overridden as well and returns a non-empty result.
* Normally one should not override both this method and {@link #buildFixes(Object...)}.
*
* @param infos additional information which was supplied by {@link BaseInspectionVisitor} during error registration.
* @return a new fix or null if no fix is available
*/
@Nullable
protected LocalQuickFix buildFix(Object... infos) {
protected InspectionGadgetsFix buildFix(Object... infos) {
return null;
}
/**
* Build fixes based on infos passed to {@link BaseInspectionVisitor#registerError(PsiElement, Object...)} or similar methods.
* Override this method in concrete inspection to provide fixes. Use {@link DelegatingFix} if your fix does not extend
* {@link InspectionGadgetsFix}.
*
* @param infos additional information which was supplied by {@link BaseInspectionVisitor} during error registration.
* @return an array of fixes (empty array if no fix is available).
*/
@NotNull
protected LocalQuickFix[] buildFixes(Object... infos) {
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
return InspectionGadgetsFix.EMPTY_ARRAY;
}
@@ -134,7 +153,7 @@ public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool {
/**
* To check precondition(s) on the entire file, to prevent doing the check on every PsiElement visited.
* Useful for e.g. a {@link com.intellij.psi.util.PsiUtil#isLanguageLevel5OrHigher(com.intellij.psi.PsiElement)} check
* Useful for e.g. a {@link com.intellij.psi.util.PsiUtil#isLanguageLevel5OrHigher(PsiElement)} check
* which will be the same for all elements in the specified file.
* When this method returns false, {@link #buildVisitor()} will not be called.
*/
@@ -191,29 +191,27 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
@NotNull
private LocalQuickFix[] createAndInitFixes(Object[] infos) {
final LocalQuickFix[] fixes = createFixes(infos);
for (LocalQuickFix fix : fixes) {
if(fix instanceof InspectionGadgetsFix) {
((InspectionGadgetsFix)fix).setOnTheFly(onTheFly);
}
final InspectionGadgetsFix[] fixes = createFixes(infos);
for (InspectionGadgetsFix fix : fixes) {
fix.setOnTheFly(onTheFly);
}
return fixes;
}
@NotNull
private LocalQuickFix[] createFixes(Object... infos) {
private InspectionGadgetsFix[] createFixes(Object... infos) {
if (!onTheFly && inspection.buildQuickFixesOnlyForOnTheFlyErrors()) {
return InspectionGadgetsFix.EMPTY_ARRAY;
}
final LocalQuickFix[] fixes = inspection.buildFixes(infos);
final InspectionGadgetsFix[] fixes = inspection.buildFixes(infos);
if (fixes.length > 0) {
return fixes;
}
final LocalQuickFix fix = inspection.buildFix(infos);
final InspectionGadgetsFix fix = inspection.buildFix(infos);
if (fix == null) {
return InspectionGadgetsFix.EMPTY_ARRAY;
}
return new LocalQuickFix[]{fix};
return new InspectionGadgetsFix[]{fix};
}
@Override
@@ -28,6 +28,8 @@ import com.intellij.util.ObjectUtils;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.DelegatingFix;
import com.siyeh.ig.InspectionGadgetsFix;
import org.intellij.lang.annotations.Pattern;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
@@ -90,8 +92,9 @@ public class EmptyStatementBodyInspection extends BaseInspection {
@Nullable
@Override
protected LocalQuickFix buildFix(Object... infos) {
return ObjectUtils.tryCast(ArrayUtil.getFirstElement(infos), LocalQuickFix.class);
protected InspectionGadgetsFix buildFix(Object... infos) {
LocalQuickFix fix = ObjectUtils.tryCast(ArrayUtil.getFirstElement(infos), LocalQuickFix.class);
return fix == null ? null : new DelegatingFix(fix);
}
@Override