SliceRootNode (@NotNull Collection<? extends PsiElement> leaves, @NotNull SliceRootNode oldRoot, @NotNull Map<SliceNode, Collection<PsiElement>> map) { SliceNode oldRootStart = oldRoot.myCachedChildren.get(0); SliceRootNode root = oldRoot.copy(); root.setChanged(); root.targetEqualUsages.clear(); List<SliceNode> leafValueRoots = new ArrayList<>(leaves.size()); for (final PsiElement leafExpression : leaves) { SliceNode newNode = filterTree(oldRootStart, oldNode -> { if (oldNode.getDuplicate() != null) return null; if (!node(oldNode, map).contains(leafExpression)) return null; return oldNode.copy(); }, (node, children) -> { if (!children.isEmpty()) return true; PsiElement element = node.getValue().getElement(); if (element == null) return false; return element.getManager().areElementsEquivalent(element, leafExpression); // leaf can be there only if it's filtering expression }); SliceLeafValueRootNode lvNode = new SliceLeafValueRootNode(root.getProject(), root, myProvider.createRootUsage(leafExpression, oldRoot.getValue().params), Collections.singletonList(newNode)); leafValueRoots.add(lvNode); } root.setChildren(leafValueRoots); return root; }