From 166499669e5caa286128b5d9db761be76ff50d16 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 23 Jul 2013 13:28:07 +0400 Subject: [PATCH] do not run inspection twice --- .../ex/GlobalInspectionContextImpl.java | 118 +++++++++--------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 21af6a0ad875..aa1a7f41db78 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -307,8 +307,6 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp }); } - - @Override protected void runTools(@NotNull AnalysisScope scope, boolean runGlobalToolsOnly) { final InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject()); @@ -316,50 +314,10 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp final List localTools = new ArrayList(); final List globalSimpleTools = new ArrayList(); initializeTools(globalTools, localTools, globalSimpleTools); - appendPairedInspectionsForUnfairTools(globalTools, localTools, globalSimpleTools); + appendPairedInspectionsForUnfairTools(globalTools, globalSimpleTools, localTools); - final List needRepeatSearchRequest = new ArrayList(); ((RefManagerImpl)getRefManager()).initializeAnnotators(); - - for (Tools tools : globalTools) { - for (ScopeToolState state : tools.getTools()) { - InspectionToolWrapper toolWrapper = state.getTool(); - GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool(); - InspectionToolPresentation toolPresentation = getPresentation(toolWrapper); - try { - if (tool.isGraphNeeded()) { - ((RefManagerImpl)getRefManager()).findAllDeclarations(); - } - tool.runInspection(scope, inspectionManager, this, toolPresentation); - if (tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) { - needRepeatSearchRequest.add(toolWrapper); - } - } - catch (ProcessCanceledException e) { - throw e; - } - catch (IndexNotReadyException e) { - throw e; - } - catch (Exception e) { - LOG.error(e); - } - } - } - for (GlobalInspectionContextExtension extension : myExtensions.values()) { - try { - extension.performPostRunActivities(needRepeatSearchRequest, this); - } - catch (ProcessCanceledException e) { - throw e; - } - catch (IndexNotReadyException e) { - throw e; - } - catch (Exception e) { - LOG.error(e); - } - } + runGlobalTools(scope, inspectionManager, globalTools); if (runGlobalToolsOnly) return; final PsiManager psiManager = PsiManager.getInstance(getProject()); @@ -431,7 +389,53 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp } } - private void appendPairedInspectionsForUnfairTools(List globalTools, List localTools, List globalSimpleTools) { + private void runGlobalTools(AnalysisScope scope, InspectionManagerEx inspectionManager, List globalTools) { + final List needRepeatSearchRequest = new ArrayList(); + + for (Tools tools : globalTools) { + for (ScopeToolState state : tools.getTools()) { + InspectionToolWrapper toolWrapper = state.getTool(); + GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool(); + InspectionToolPresentation toolPresentation = getPresentation(toolWrapper); + try { + if (tool.isGraphNeeded()) { + ((RefManagerImpl)getRefManager()).findAllDeclarations(); + } + tool.runInspection(scope, inspectionManager, this, toolPresentation); + if (tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) { + needRepeatSearchRequest.add(toolWrapper); + } + } + catch (ProcessCanceledException e) { + throw e; + } + catch (IndexNotReadyException e) { + throw e; + } + catch (Exception e) { + LOG.error(e); + } + } + } + for (GlobalInspectionContextExtension extension : myExtensions.values()) { + try { + extension.performPostRunActivities(needRepeatSearchRequest, this); + } + catch (ProcessCanceledException e) { + throw e; + } + catch (IndexNotReadyException e) { + throw e; + } + catch (Exception e) { + LOG.error(e); + } + } + } + + private void appendPairedInspectionsForUnfairTools(@NotNull List globalTools, + @NotNull List globalSimpleTools, + @NotNull List localTools) { Tools[] larray = localTools.toArray(new Tools[localTools.size()]); for (Tools tool : larray) { LocalInspectionToolWrapper toolWrapper = (LocalInspectionToolWrapper)tool.getTool(); @@ -439,19 +443,17 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp if (localTool instanceof PairedUnfairLocalInspectionTool) { String batchShortName = ((PairedUnfairLocalInspectionTool)localTool).getInspectionForBatchShortName(); InspectionProfile currentProfile = getCurrentProfile(); - if (currentProfile != null) { - InspectionToolWrapper batchInspection = currentProfile.getInspectionTool(batchShortName, getProject()); - if (batchInspection != null) { - // add to existing inspections to run - InspectionProfileEntry batchTool = batchInspection.getTool(); - Tools newTool = new ToolsImpl(batchInspection, batchInspection.getDefaultLevel(), true); - if (batchTool instanceof LocalInspectionTool) localTools.add(newTool); - else if (batchTool instanceof GlobalSimpleInspectionTool) globalSimpleTools.add(newTool); - else if (batchTool instanceof GlobalInspectionTool) globalTools.add(newTool); - else throw new AssertionError(batchTool); - myTools.put(batchShortName, newTool); - batchInspection.initialize(this); - } + InspectionToolWrapper batchInspection = currentProfile == null ? null : currentProfile.getInspectionTool(batchShortName, getProject()); + if (batchInspection != null && !myTools.containsKey(batchShortName)) { + // add to existing inspections to run + InspectionProfileEntry batchTool = batchInspection.getTool(); + Tools newTool = new ToolsImpl(batchInspection, batchInspection.getDefaultLevel(), true); + if (batchTool instanceof LocalInspectionTool) localTools.add(newTool); + else if (batchTool instanceof GlobalSimpleInspectionTool) globalSimpleTools.add(newTool); + else if (batchTool instanceof GlobalInspectionTool) globalTools.add(newTool); + else throw new AssertionError(batchTool); + myTools.put(batchShortName, newTool); + batchInspection.initialize(this); } } }