inspection view: internalize problem levels for ref and problem nodes

This commit is contained in:
Dmitry Batkovich
2017-11-13 12:13:12 +03:00
parent df6a596e15
commit ec0da9f9b7
3 changed files with 51 additions and 19 deletions
@@ -7,7 +7,9 @@ import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.util.AtomicClearableLazyValue;
import com.intellij.util.containers.Interner;
import com.intellij.util.ui.tree.TreeUtil;
import gnu.trove.TObjectHashingStrategy;
import gnu.trove.TObjectIntHashMap;
import gnu.trove.TObjectIntProcedure;
import org.jetbrains.annotations.NotNull;
@@ -25,6 +27,18 @@ import java.util.Enumeration;
* @author max
*/
public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
private static final Interner<LevelAndCount[]> LEVEL_AND_COUNT_INTERNER = new Interner<>(new TObjectHashingStrategy<LevelAndCount[]>() {
@Override
public int computeHashCode(LevelAndCount[] object) {
return Arrays.hashCode(object);
}
@Override
public boolean equals(LevelAndCount[] o1, LevelAndCount[] o2) {
return Arrays.equals(o1, o2);
}
});
protected final AtomicClearableLazyValue<LevelAndCount[]> myProblemLevels = new AtomicClearableLazyValue<LevelAndCount[]>() {
@NotNull
@Override
@@ -40,15 +54,21 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
return true;
}
});
Arrays.sort(arr, Comparator.<LevelAndCount, HighlightSeverity>comparing(levelAndCount -> levelAndCount.getLevel().getSeverity()).reversed());
return arr;
Arrays.sort(arr, Comparator.<LevelAndCount, HighlightSeverity>comparing(levelAndCount -> levelAndCount.getLevel().getSeverity())
.reversed());
return doesNeedInternProblemLevels() ? LEVEL_AND_COUNT_INTERNER.intern(arr) : arr;
}
};
protected volatile InspectionTreeUpdater myUpdater;
protected InspectionTreeNode (Object userObject) {
protected InspectionTreeNode(Object userObject) {
super(userObject);
}
protected boolean doesNeedInternProblemLevels() {
return false;
}
@Nullable
public Icon getIcon(boolean expanded) {
return null;
@@ -145,7 +165,7 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
}
}
int index = TreeUtil.indexedBinarySearch(this, child, InspectionResultsViewComparator.getInstance());
if (!allowDuplication && index >= 0){
if (!allowDuplication && index >= 0) {
return (InspectionTreeNode)getChildAt(index);
}
insert(child, Math.abs(index + 1));
@@ -1,24 +1,11 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.codeHighlighting.HighlightDisplayLevel;
import org.jetbrains.annotations.NotNull;
class LevelAndCount {
@NotNull
private final HighlightDisplayLevel myLevel;
private final int myCount;
@@ -32,6 +19,26 @@ class LevelAndCount {
return myLevel;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LevelAndCount count = (LevelAndCount)o;
if (myCount != count.myCount) return false;
if (myLevel != null ? !myLevel.equals(count.myLevel) : count.myLevel != null) return false;
return true;
}
@Override
public int hashCode() {
int result = myLevel != null ? myLevel.hashCode() : 0;
result = 31 * result + myCount;
return result;
}
public int getCount() {
return myCount;
}
@@ -34,6 +34,11 @@ public abstract class SuppressableInspectionTreeNode extends InspectionTreeNode
myPresentation = presentation;
}
@Override
protected boolean doesNeedInternProblemLevels() {
return true;
}
@NotNull
public InspectionToolPresentation getPresentation() {
return myPresentation;