Ejemplo n.º 1
0
 public void testLeafExpressionsAreEmptyInCaseOfInfinitelyExpandingTreeWithDuplicateNodes()
     throws Exception {
   SliceTreeStructure treeStructure = configureTree("Tuple");
   SliceNode root = (SliceNode) treeStructure.getRootElement();
   Collection<PsiElement> leaves =
       SliceLeafAnalyzer.calcLeafExpressions(root, treeStructure, SliceLeafAnalyzer.createMap());
   assertNotNull(leaves);
   assertEmpty(leaves);
 }
Ejemplo n.º 2
0
 public void testLeafExpressionsSimple() throws Exception {
   SliceTreeStructure treeStructure = configureTree("DupSlice");
   SliceNode root = (SliceNode) treeStructure.getRootElement();
   Collection<PsiElement> leaves =
       SliceLeafAnalyzer.calcLeafExpressions(root, treeStructure, SliceLeafAnalyzer.createMap());
   assertNotNull(leaves);
   PsiElement element = assertOneElement(leaves);
   assertTrue(element instanceof PsiLiteralExpression);
   assertEquals(1111111111, ((PsiLiteral) element).getValue());
 }
Ejemplo n.º 3
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));
    }
  }
Ejemplo n.º 4
0
 public void testLeafExpressionsMoreComplex() throws Exception {
   SliceTreeStructure treeStructure = configureTree("Duplicate");
   SliceNode root = (SliceNode) treeStructure.getRootElement();
   Collection<PsiElement> leaves =
       SliceLeafAnalyzer.calcLeafExpressions(root, treeStructure, SliceLeafAnalyzer.createMap());
   assertNotNull(leaves);
   assertEquals(2, leaves.size());
   List<PsiElement> list = new ArrayList<PsiElement>(leaves);
   Collections.sort(
       list,
       new Comparator<PsiElement>() {
         @Override
         public int compare(PsiElement o1, PsiElement o2) {
           return o1.getText().compareTo(o2.getText());
         }
       });
   assertTrue(list.get(0) instanceof PsiLiteralExpression);
   assertEquals(false, ((PsiLiteral) list.get(0)).getValue());
   assertTrue(list.get(1) instanceof PsiLiteralExpression);
   assertEquals(true, ((PsiLiteral) list.get(1)).getValue());
 }
Ejemplo n.º 5
0
  public void testGroupByValuesCorrectLeaves() throws Exception {
    SliceTreeStructure treeStructure = configureTree("DuplicateLeaves");
    SliceRootNode root = (SliceRootNode) treeStructure.getRootElement();
    Map<SliceNode, Collection<PsiElement>> map = SliceLeafAnalyzer.createMap();
    Collection<PsiElement> leaves = SliceLeafAnalyzer.calcLeafExpressions(root, treeStructure, map);
    assertNotNull(leaves);
    assertEquals(1, leaves.size());
    PsiElement leaf = leaves.iterator().next();
    assertTrue(leaf instanceof PsiLiteralExpression);
    assertEquals("\"oo\"", leaf.getText());

    SliceRootNode newRoot = SliceLeafAnalyzer.createTreeGroupedByValues(leaves, root, map);
    Collection<? extends AbstractTreeNode> children = newRoot.getChildren();
    assertEquals(1, children.size());
    SliceNode child = (SliceNode) children.iterator().next();
    assertTrue(child instanceof SliceLeafValueRootNode);

    children = child.getChildren();
    assertEquals(1, children.size());
    child = (SliceNode) children.iterator().next();
    assertTrue(child.getValue().getElement() instanceof PsiField);

    children = child.getChildren();
    assertEquals(1, children.size());
    child = (SliceNode) children.iterator().next();
    assertTrue(child.getValue().getElement() instanceof PsiReferenceExpression);

    children = child.getChildren();
    assertEquals(1, children.size());
    child = (SliceNode) children.iterator().next();
    assertTrue(child.getValue().getElement() instanceof PsiReferenceExpression);

    children = child.getChildren();
    assertEquals(1, children.size());
    child = (SliceNode) children.iterator().next();
    assertTrue(child.getValue().getElement() instanceof PsiLiteralExpression);
    assertEquals(child.getValue().getElement(), leaf);
  }