mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
batch inspections on-the-fly: do not reload nodes -> use tree model instead
This commit is contained in:
+22
-13
@@ -33,8 +33,7 @@ import com.intellij.util.ui.tree.TreeUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.MutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.*;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class InspectionRVContentProvider {
|
||||
@@ -73,14 +72,15 @@ public abstract class InspectionRVContentProvider {
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
final Map<String, Set<RefEntity>> content = tool.getContent();
|
||||
appendToolNodeContent(toolNode, parentNode, showStructure, content != null ? content : new HashMap<String, Set<RefEntity>>(),
|
||||
tool instanceof DescriptorProviderInspection ? ((DescriptorProviderInspection)tool).getProblemElements() : null);
|
||||
tool instanceof DescriptorProviderInspection ? ((DescriptorProviderInspection)tool).getProblemElements() : null, null);
|
||||
}
|
||||
|
||||
public abstract void appendToolNodeContent(final InspectionNode toolNode,
|
||||
final InspectionTreeNode parentNode,
|
||||
final boolean showStructure,
|
||||
final Map<String, Set<RefEntity>> contents,
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems);
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
final @Nullable DefaultTreeModel model);
|
||||
|
||||
protected abstract void appendDescriptor(final InspectionTool tool,
|
||||
final UserObjectContainer container,
|
||||
@@ -250,7 +250,7 @@ public abstract class InspectionRVContentProvider {
|
||||
}
|
||||
|
||||
@SuppressWarnings({"ConstantConditions"}) //class cast suppression
|
||||
protected static void merge(InspectionTreeNode child, InspectionTreeNode parent, boolean merge) {
|
||||
protected static void merge(@Nullable DefaultTreeModel model, InspectionTreeNode child, InspectionTreeNode parent, boolean merge) {
|
||||
if (merge) {
|
||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
||||
InspectionTreeNode current = (InspectionTreeNode)parent.getChildAt(i);
|
||||
@@ -259,43 +259,52 @@ public abstract class InspectionRVContentProvider {
|
||||
}
|
||||
if (current instanceof InspectionPackageNode) {
|
||||
if (((InspectionPackageNode)current).getPackageName().compareTo(((InspectionPackageNode)child).getPackageName()) == 0) {
|
||||
processDepth(child, current);
|
||||
processDepth(model, child, current);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (current instanceof RefElementNode) {
|
||||
if (((RefElementNode)current).getElement().getName().compareTo(((RefElementNode)child).getElement().getName()) == 0) {
|
||||
processDepth(child, current);
|
||||
processDepth(model, child, current);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (current instanceof InspectionNode) {
|
||||
if (((InspectionNode)current).getTool().getShortName().compareTo(((InspectionNode)child).getTool().getShortName()) == 0) {
|
||||
processDepth(child, current);
|
||||
processDepth(model, child, current);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (current instanceof InspectionModuleNode) {
|
||||
if (((InspectionModuleNode)current).getName().compareTo(((InspectionModuleNode)child).getName()) == 0) {
|
||||
processDepth(child, current);
|
||||
processDepth(model, child, current);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (current instanceof ProblemDescriptionNode) {
|
||||
if (((ProblemDescriptionNode)current).getDescriptor().getDescriptionTemplate()
|
||||
.compareTo(((ProblemDescriptionNode)child).getDescriptor().getDescriptionTemplate()) == 0) {
|
||||
processDepth(child, current);
|
||||
processDepth(model, child, current);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parent.add(child);
|
||||
add(model, child, parent);
|
||||
}
|
||||
|
||||
private static void processDepth(final InspectionTreeNode child, final InspectionTreeNode current) {
|
||||
protected static void add(@Nullable final DefaultTreeModel model, final InspectionTreeNode child, final InspectionTreeNode parent) {
|
||||
if (model == null) {
|
||||
parent.add(child);
|
||||
}
|
||||
else {
|
||||
model.insertNodeInto(child, parent, parent.getChildCount());
|
||||
}
|
||||
}
|
||||
|
||||
private static void processDepth(@Nullable DefaultTreeModel model, final InspectionTreeNode child, final InspectionTreeNode current) {
|
||||
for (int j = 0; j < child.getChildCount(); j++) {
|
||||
merge((InspectionTreeNode)child.getChildAt(j), current, true);
|
||||
merge(model, (InspectionTreeNode)child.getChildAt(j), current, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -33,6 +33,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -59,7 +60,7 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
final InspectionTreeNode parentNode,
|
||||
final boolean showStructure,
|
||||
final Map<String, Set<RefEntity>> contents,
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems) {
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems, DefaultTreeModel model) {
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
|
||||
Function<RefEntity, UserObjectContainer<RefEntity>> computeContainer = new Function<RefEntity, UserObjectContainer<RefEntity>>() {
|
||||
@@ -80,7 +81,7 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
List<InspectionTreeNode> list = buildTree(contents, false, tool, computeContainer, showStructure);
|
||||
|
||||
for (InspectionTreeNode node : list) {
|
||||
merge(node, toolNode, true);
|
||||
merge(model, node, toolNode, true);
|
||||
}
|
||||
|
||||
if (tool.isOldProblemsIncluded()) {
|
||||
@@ -96,10 +97,10 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
list = buildTree(tool.getOldContent(), true, tool, computeContainer, showStructure);
|
||||
|
||||
for (InspectionTreeNode node : list) {
|
||||
merge(node, toolNode, true);
|
||||
merge(model, node, toolNode, true);
|
||||
}
|
||||
}
|
||||
merge(toolNode, parentNode, true);
|
||||
merge(model, toolNode, parentNode, true);
|
||||
}
|
||||
|
||||
protected void appendDescriptor(final InspectionTool tool,
|
||||
|
||||
+6
-6
@@ -32,8 +32,8 @@ import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.TripleFunction;
|
||||
import com.intellij.util.containers.*;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -124,13 +124,13 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti
|
||||
contents.put(groupName, content);
|
||||
}
|
||||
content.add(refElement);
|
||||
view.getProvider().appendToolNodeContent(myToolNode,
|
||||
(InspectionTreeNode)myToolNode.getParent(), getContext().getUIOptions().SHOW_STRUCTURE,
|
||||
contents, problems);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
view.getProvider().appendToolNodeContent(myToolNode,
|
||||
(InspectionTreeNode)myToolNode.getParent(), getContext().getUIOptions().SHOW_STRUCTURE,
|
||||
contents, problems, (DefaultTreeModel)view.getTree().getModel());
|
||||
getContext().addView(view);
|
||||
((DefaultTreeModel)view.getTree().getModel()).reload(myToolNode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+3
-1
@@ -39,6 +39,7 @@ import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.util.*;
|
||||
@@ -110,7 +111,8 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
final InspectionTreeNode parentNode,
|
||||
final boolean showStructure,
|
||||
final Map<String, Set<RefEntity>> contents,
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems) {
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
final DefaultTreeModel model) {
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
final Map<String, Set<OfflineProblemDescriptor>> filteredContent = getFilteredContent(tool);
|
||||
if (filteredContent != null && !filteredContent.values().isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user