Esempio 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);
 }
Esempio 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());
 }
Esempio n. 3
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());
 }
Esempio n. 4
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);
  }