From 4f541dc35f1eda6b12956a539a95de5e253f94e6 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Wed, 9 Aug 2017 12:17:40 +0300 Subject: [PATCH] inspections: allow global inspection to provide local cleanup tool (eg: RedundantThrowsDeclarationInspection) --- .../ex/GlobalInspectionToolWrapper.java | 6 +++++- .../ex/GlobalInspectionContextImpl.java | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java index b1ea6bb6f6e6..ff19150c288c 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionToolWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ package com.intellij.codeInspection.ex; import com.intellij.codeInspection.*; import com.intellij.codeInspection.reference.RefGraphAnnotator; import com.intellij.codeInspection.reference.RefManagerImpl; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.ArrayUtil; import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class GlobalInspectionToolWrapper extends InspectionToolWrapper { + private static final Logger LOG = Logger.getInstance(GlobalInspectionToolWrapper.class); + public GlobalInspectionToolWrapper(@NotNull GlobalInspectionTool globalInspectionTool) { super(globalInspectionTool); } @@ -84,6 +87,7 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> { assert tools != null; - return tools.getTool().getTool() instanceof CleanupLocalInspectionTool; + return tools.getTool().isCleanupTool(); }); boolean includeDoNotShow = includeDoNotShow(profile); final RefManagerImpl refManager = (RefManagerImpl)getRefManager(); @@ -957,8 +957,11 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp if (isBinary(file)) return; final List lTools = new ArrayList<>(); for (final Tools tools : inspectionTools) { - final InspectionToolWrapper tool = tools.getEnabledTool(file, includeDoNotShow); - if (tool instanceof LocalInspectionToolWrapper) { + InspectionToolWrapper tool = tools.getEnabledTool(file, includeDoNotShow); + if (tool instanceof GlobalInspectionToolWrapper) { + tool = ((GlobalInspectionToolWrapper)tool).getSharedLocalInspectionToolWrapper(); + } + if (tool != null) { lTools.add((LocalInspectionToolWrapper)tool); tool.initialize(GlobalInspectionContextImpl.this); }