Exemple #1
0
  private static void createValueRootNode(
      NullAnalysisResult result,
      SliceRootNode oldRoot,
      final Map<SliceNode, NullAnalysisResult> map,
      SliceRootNode root,
      SliceNode oldRootStart,
      String nodeName,
      final int group) {
    Collection<PsiElement> groupedByValue = result.groupedByValue[group];
    if (groupedByValue.isEmpty()) {
      return;
    }
    SliceLeafValueClassNode valueRoot =
        new SliceLeafValueClassNode(root.getProject(), root, nodeName);
    root.myCachedChildren.add(valueRoot);

    Set<PsiElement> uniqueValues =
        new THashSet<PsiElement>(groupedByValue, SliceLeafAnalyzer.LEAF_ELEMENT_EQUALITY);
    for (final PsiElement expression : uniqueValues) {
      SliceNode newRoot =
          SliceLeafAnalyzer.filterTree(
              oldRootStart,
              new NullableFunction<SliceNode, SliceNode>() {
                @Override
                public SliceNode fun(SliceNode oldNode) {
                  if (oldNode.getDuplicate() != null) {
                    return null;
                  }

                  for (PsiElement nullSuspect : group(oldNode, map, group)) {
                    if (PsiEquivalenceUtil.areElementsEquivalent(nullSuspect, expression)) {
                      return oldNode.copy();
                    }
                  }
                  return null;
                }
              },
              new PairProcessor<SliceNode, List<SliceNode>>() {
                @Override
                public boolean process(SliceNode node, List<SliceNode> 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(),
              expression,
              valueRoot,
              Collections.singletonList(newRoot),
              oldRoot.getValue().params));
    }
  }