Search in sources :

Example 1 with BatchQuickFix

use of com.intellij.codeInspection.BatchQuickFix in project intellij-community by JetBrains.

the class LocalQuickFixWrapper method applyFix.

@Override
protected void applyFix(@NotNull final Project project, @NotNull final GlobalInspectionContextImpl context, @NotNull final CommonProblemDescriptor[] descriptors, @NotNull final Set<PsiElement> ignoredElements) {
    if (myFix instanceof BatchQuickFix) {
        final List<PsiElement> collectedElementsToIgnore = new ArrayList<>();
        final Runnable refreshViews = () -> {
            DaemonCodeAnalyzer.getInstance(project).restart();
            for (CommonProblemDescriptor descriptor : descriptors) {
                ignore(ignoredElements, descriptor, getWorkingQuickFix(descriptor.getFixes()), context);
            }
            final RefManager refManager = context.getRefManager();
            final RefElement[] refElements = new RefElement[collectedElementsToIgnore.size()];
            for (int i = 0, collectedElementsToIgnoreSize = collectedElementsToIgnore.size(); i < collectedElementsToIgnoreSize; i++) {
                refElements[i] = refManager.getReference(collectedElementsToIgnore.get(i));
            }
            removeElements(refElements, project, myToolWrapper);
        };
        ((BatchQuickFix) myFix).applyFix(project, descriptors, collectedElementsToIgnore, refreshViews);
        return;
    }
    boolean restart = false;
    for (CommonProblemDescriptor descriptor : descriptors) {
        if (descriptor == null)
            continue;
        final QuickFix[] fixes = descriptor.getFixes();
        if (fixes != null) {
            final QuickFix fix = getWorkingQuickFix(fixes);
            if (fix != null) {
                //CCE here means QuickFix was incorrectly inherited, is there a way to signal (plugin) it is wrong?
                fix.applyFix(project, descriptor);
                restart = true;
                ignore(ignoredElements, descriptor, fix, context);
            }
        }
    }
    if (restart) {
        DaemonCodeAnalyzer.getInstance(project).restart();
    }
}
Also used : QuickFix(com.intellij.codeInspection.QuickFix) BatchQuickFix(com.intellij.codeInspection.BatchQuickFix) BatchQuickFix(com.intellij.codeInspection.BatchQuickFix) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefManager(com.intellij.codeInspection.reference.RefManager) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement)

Aggregations

BatchQuickFix (com.intellij.codeInspection.BatchQuickFix)1 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)1 QuickFix (com.intellij.codeInspection.QuickFix)1 RefManager (com.intellij.codeInspection.reference.RefManager)1 PsiElement (com.intellij.psi.PsiElement)1 ArrayList (java.util.ArrayList)1