SliceLeafValueClassNode (NullAnalysisResult result, SliceRootNode oldRoot, final Map<SliceNode, NullAnalysisResult> map, SliceRootNode root, SliceNode oldRootStart, String nodeName, final int group) { Collection<PsiElement> groupedByValue = result.groupedByValue.get(group); if (groupedByValue.isEmpty()) { return null; } SliceLeafValueClassNode valueRoot = new SliceLeafValueClassNode(root.getProject(), root, nodeName); Set<PsiElement> uniqueValues = CollectionFactory.createCustomHashingStrategySet(myLeafEquality); uniqueValues.addAll(groupedByValue); for (final PsiElement expression : uniqueValues) { SliceNode newRoot = SliceLeafAnalyzer.filterTree(oldRootStart, oldNode -> { if (oldNode.getDuplicate() != null) { return null; } for (PsiElement nullSuspect : group(oldNode, map, group)) { if (PsiEquivalenceUtil.areElementsEquivalent(nullSuspect, expression)) { return oldNode.copy(); } } return null; }, (node, children) -> { if (!children.isEmpty()) return true; PsiElement element = node.getValue().getElement(); if (element == null) return false; return PsiEquivalenceUtil.areElementsEquivalent(element, expression); // leaf can be there only if it's filtering expression }); valueRoot.myCachedChildren.add( new SliceLeafValueRootNode(root.getProject(), valueRoot, myProvider.createRootUsage(expression, oldRoot.getValue().params), Collections.singletonList(newRoot)) ); } return valueRoot; }