use of com.intellij.ide.projectView.impl.nodes.NestingTreeNode in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (!(parent instanceof PsiDirectoryNode))
return children;
final Collection<NestingRule> rules = getNestingRules();
if (rules.isEmpty())
return children;
final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = calcParentToChildren(children, rules);
if (parentToChildren.isEmpty())
return children;
// initial ArrayList size may be not exact, not a big problem
final Collection<AbstractTreeNode> newChildren = new ArrayList<>(children.size() - parentToChildren.size());
final Set<PsiFileNode> childrenToMoveDown = new THashSet<>(parentToChildren.values());
for (AbstractTreeNode node : children) {
if (!(node instanceof PsiFileNode)) {
newChildren.add(node);
continue;
}
if (childrenToMoveDown.contains(node)) {
continue;
}
final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode) node);
if (childrenOfThisFile.isEmpty()) {
newChildren.add(node);
continue;
}
newChildren.add(new NestingTreeNode((PsiFileNode) node, childrenOfThisFile));
}
return newChildren;
}
Aggregations