From 9a565bcf4ced24f01d9bc25ea44dd5ba6eee13c8 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 21 Dec 2017 12:48:29 +0300 Subject: [PATCH] inspection view: initialize only visible nodes --- .../OfflineProblemDescriptorNode.java | 3 +-- .../codeInspection/ui/InspectionTreeNode.java | 8 ++++++- .../ui/ProblemDescriptionNode.java | 10 ++++----- .../codeInspection/ui/RefElementNode.java | 5 +++-- .../ui/SuppressableInspectionTreeNode.java | 22 ++++++++++--------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineProblemDescriptorNode.java b/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineProblemDescriptorNode.java index d50bf442ff58..040101721b9e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineProblemDescriptorNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineProblemDescriptorNode.java @@ -17,12 +17,11 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode { private OfflineProblemDescriptorNode(OfflineDescriptorResolveResult descriptorResolveResult, @NotNull InspectionToolPresentation presentation, @NotNull OfflineProblemDescriptor offlineDescriptor) { - super(descriptorResolveResult.getResolvedEntity(), descriptorResolveResult.getResolvedDescriptor(), presentation, false, offlineDescriptor::getLine); + super(descriptorResolveResult.getResolvedEntity(), descriptorResolveResult.getResolvedDescriptor(), presentation, offlineDescriptor::getLine); myDescriptorResolveResult = descriptorResolveResult; if (descriptorResolveResult.getResolvedDescriptor() == null) { setUserObject(offlineDescriptor); } - init(presentation.getContext().getProject()); } static OfflineProblemDescriptorNode create(@NotNull OfflineProblemDescriptor offlineDescriptor, diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java index c0638f6cee99..c0639d90e7d8 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.codeInspection.ui; @@ -193,6 +195,9 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { } } + protected void nodeAddedToTree() { + } + private void propagateUpdater(InspectionTreeUpdater updater) { if (myUpdater != null) return; myUpdater = updater; @@ -200,6 +205,7 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { while (enumeration.hasMoreElements()) { InspectionTreeNode child = (InspectionTreeNode)enumeration.nextElement(); child.propagateUpdater(updater); + child.nodeAddedToTree(); } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java index c176c771ffac..c4e2312c2891 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.codeInspection.ui; @@ -33,13 +35,12 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode { public ProblemDescriptionNode(RefEntity element, CommonProblemDescriptor descriptor, @NotNull InspectionToolPresentation presentation) { - this(element, descriptor, presentation, true, null); + this(element, descriptor, presentation, null); } protected ProblemDescriptionNode(@Nullable RefEntity element, CommonProblemDescriptor descriptor, @NotNull InspectionToolPresentation presentation, - boolean doInit, @Nullable IntSupplier lineNumberCounter) { super(descriptor, presentation); myElement = element; @@ -49,9 +50,6 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode { myLevel = descriptor instanceof ProblemDescriptor ? profile.getErrorLevel(HighlightDisplayKey.find(shortName), ((ProblemDescriptor)descriptor).getStartElement()) : profile.getTools(shortName, presentation.getContext().getProject()).getLevel(); - if (doInit) { - init(presentation.getContext().getProject()); - } myLineNumber = myDescriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)myDescriptor).getLineNumber() : (lineNumberCounter == null ? -1 : lineNumberCounter.getAsInt()); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java index 796068a63a12..50cab4646845 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.codeInspection.ui; @@ -26,7 +28,6 @@ public class RefElementNode extends SuppressableInspectionTreeNode { private final Icon myIcon; public RefElementNode(@Nullable RefEntity userObject, @NotNull InspectionToolPresentation presentation) { super(userObject, presentation); - init(presentation.getContext().getProject()); final RefEntity refEntity = getElement(); myIcon = refEntity == null ? null : refEntity.getIcon(false); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/SuppressableInspectionTreeNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/SuppressableInspectionTreeNode.java index 2256f7ee5715..7b5577f03364 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/SuppressableInspectionTreeNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/SuppressableInspectionTreeNode.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.codeInspection.ui; import com.intellij.codeInspection.CommonProblemDescriptor; @@ -76,15 +78,6 @@ public abstract class SuppressableInspectionTreeNode extends InspectionTreeNode myAvailableSuppressActions.remove(action); } - protected void init(Project project) { - myPresentableName = calculatePresentableName(); - myValid = calculateIsValid(); - myAvailableSuppressActions = getElement() == null - ? Collections.emptySet() - : calculateAvailableSuppressActions(project); - } - - @Nullable public abstract RefEntity getElement(); @@ -123,6 +116,15 @@ public abstract class SuppressableInspectionTreeNode extends InspectionTreeNode return !isValid() ? "No longer valid" : null; } + @Override + protected void nodeAddedToTree() { + myPresentableName = calculatePresentableName(); + myValid = calculateIsValid(); + myAvailableSuppressActions = getElement() == null + ? Collections.emptySet() + : calculateAvailableSuppressActions(myPresentation.getContext().getProject()); + } + @NotNull public final Pair getSuppressContent() { RefEntity refElement = getElement();