diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java index e2d035f63eb3..d506f8d1c1db 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java @@ -92,7 +92,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G } } - AnalysisScope getCurrentScope() { + public AnalysisScope getCurrentScope() { return myCurrentScope; } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java index 08234f194ab8..2feab8fec30e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/ViewOfflineResultsAction.java @@ -222,7 +222,7 @@ public class ViewOfflineResultsAction extends AnAction { context.setExternalProfile(inspectionProfile); context.setCurrentScope(scope); context.initializeTools(new ArrayList(), new ArrayList(), new ArrayList()); - final InspectionResultsView view = new InspectionResultsView(project, inspectionProfile, scope, context, + final InspectionResultsView view = new InspectionResultsView(context, new OfflineInspectionRVContentProvider(resMap, project)); ((RefManagerImpl)context.getRefManager()).startOfflineView(); view.update(); 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 bb9a2d92cd1d..8db114bd35a3 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -110,7 +110,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp } public synchronized void addView(@NotNull InspectionResultsView view, @NotNull String title) { - if (myContent != null) return; + LOG.assertTrue(myContent == null, "GlobalInspectionContext is busy under other view now"); myContentManager.getValue().addContentManagerListener(new ContentManagerAdapter() { @Override public void contentRemoved(ContentManagerEvent event) { @@ -314,8 +314,9 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp @Override protected void launchInspections(@NotNull final AnalysisScope scope) { - myUIOptions = AnalysisUIOptions.getInstance(getProject()).copy(); - myView = new InspectionResultsView(getProject(), getCurrentProfile(), scope, this, new InspectionRVContentProviderImpl(getProject())); + if (!ApplicationManager.getApplication().isUnitTestMode()) { + myUIOptions = AnalysisUIOptions.getInstance(getProject()).copy(); + } super.launchInspections(scope); } @@ -333,15 +334,23 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp public void run() { LOG.info("Code inspection finished"); - if (myView != null) { - if (!myView.update() && !getUIOptions().SHOW_ONLY_DIFF) { - NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName()), MessageType.INFO).notify(getProject()); - close(true); - } - else { - addView(myView); + final InspectionResultsView view; + if (myView == null) { + view = new InspectionResultsView(GlobalInspectionContextImpl.this, + new InspectionRVContentProviderImpl(getProject())); + } else { + view = null; + } + if (!(myView == null ? view : myView).update() && !getUIOptions().SHOW_ONLY_DIFF) { + NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName()), MessageType.INFO).notify(getProject()); + close(true); + if (view != null) { + Disposer.dispose(view); } } + else if (view != null) { + addView(view); + } } }); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java index cc87a9c5bd14..3c716a4e1c4b 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java @@ -223,14 +223,19 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro } final GlobalInspectionContextImpl context = getContext(); + if (!(refElement instanceof RefElement)) { + return; + } if (myToolWrapper instanceof LocalInspectionToolWrapper) { - final InspectionResultsView view = context.getView(); - if (view == null || !(refElement instanceof RefElement)) { - return; - } UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { + InspectionResultsView view = context.getView(); + if (view == null) { + view = new InspectionResultsView(context, + new InspectionRVContentProviderImpl(context.getProject())); + context.addView(view); + } if (!isDisposed()) { final InspectionNode toolNode; synchronized (myToolLock) { @@ -259,7 +264,6 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro view.getProvider().appendToolNodeContent(context, toolNode, (InspectionTreeNode)toolNode.getParent(), context.getUIOptions().SHOW_STRUCTURE, contents, problems, (DefaultTreeModel)view.getTree().getModel()); - context.addView(view); } } }); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index 240b9a482e9d..4e50769ac5c9 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -94,6 +94,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren private final ConcurrentMap> myGroups = ContainerUtil.newConcurrentMap(); private final OccurenceNavigator myOccurenceNavigator; private volatile InspectionProfile myInspectionProfile; + @NotNull private final AnalysisScope myScope; @NonNls private static final String HELP_ID = "reference.toolWindows.inspections"; @@ -111,20 +112,16 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren private AnAction myExcludeAction; private Editor myPreviewEditor; - public InspectionResultsView(@NotNull final Project project, - final InspectionProfile inspectionProfile, - @NotNull AnalysisScope scope, - @NotNull GlobalInspectionContextImpl globalInspectionContext, + public InspectionResultsView(@NotNull GlobalInspectionContextImpl globalInspectionContext, @NotNull InspectionRVContentProvider provider) { setLayout(new BorderLayout()); - - myProject = project; - myInspectionProfile = inspectionProfile; - myScope = scope; + myProject = globalInspectionContext.getProject(); + myInspectionProfile = globalInspectionContext.getCurrentProfile(); + myScope = globalInspectionContext.getCurrentScope(); myGlobalInspectionContext = globalInspectionContext; myProvider = provider; - myTree = new InspectionTree(project, globalInspectionContext); + myTree = new InspectionTree(myProject, globalInspectionContext); initTreeListeners(); myOccurenceNavigator = initOccurenceNavigator(); @@ -144,6 +141,8 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren TreeUtil.selectFirstNode(myTree); } + + private void initTreeListeners() { myTree.getSelectionModel().addTreeSelectionListener(e -> { syncRightPanel();