private ArrayList<AbstractTreeNode> getPathToElement(Object element) { ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>(); final AbstractTreeStructure treeStructure = myAbstractTreeBuilder.getTreeStructure(); if (treeStructure != null) { addToPath( (AbstractTreeNode) treeStructure.getRootElement(), element, result, new THashSet<Object>()); } return result; }
public static void startAnalyzeValues( @NotNull final AbstractTreeStructure treeStructure, @NotNull final Runnable finish) { final SliceRootNode root = (SliceRootNode) treeStructure.getRootElement(); final Ref<Collection<PsiElement>> leafExpressions = Ref.create(null); final Map<SliceNode, Collection<PsiElement>> map = createMap(); ProgressManager.getInstance() .run( new Task.Backgroundable( root.getProject(), "Expanding all nodes... (may very well take the whole day)", true) { @Override public void run(@NotNull final ProgressIndicator indicator) { Collection<PsiElement> l = calcLeafExpressions(root, treeStructure, map); leafExpressions.set(l); } @Override public void onCancel() { finish.run(); } @Override public void onSuccess() { try { Collection<PsiElement> leaves = leafExpressions.get(); if (leaves == null) return; // cancelled if (leaves.isEmpty()) { Messages.showErrorDialog( "Unable to find leaf expressions to group by", "Cannot group"); return; } groupByValues(leaves, root, map); } finally { finish.run(); } } }); }
private static int doPrint( StringBuilder buffer, int currentLevel, Object node, AbstractTreeStructure structure, @Nullable Comparator comparator, int maxRowCount, int currentLine, char paddingChar, @Nullable Queryable.PrintInfo printInfo) { if (currentLine >= maxRowCount && maxRowCount != -1) return currentLine; StringUtil.repeatSymbol(buffer, paddingChar, currentLevel); buffer.append(toString(node, printInfo)).append("\n"); currentLine++; Object[] children = structure.getChildElements(node); if (comparator != null) { ArrayList<?> list = new ArrayList<Object>(Arrays.asList(children)); @SuppressWarnings({"UnnecessaryLocalVariable", "unchecked"}) Comparator<Object> c = comparator; Collections.sort(list, c); children = ArrayUtil.toObjectArray(list); } for (Object child : children) { currentLine = doPrint( buffer, currentLevel + 1, child, structure, comparator, maxRowCount, currentLine, paddingChar, printInfo); } return currentLine; }
public static void startAnalyzeNullness( final AbstractTreeStructure treeStructure, final Runnable finish) { final SliceRootNode root = (SliceRootNode) treeStructure.getRootElement(); final Ref<NullAnalysisResult> leafExpressions = Ref.create(null); final Map<SliceNode, NullAnalysisResult> map = createMap(); ProgressManager.getInstance() .run( new Task.Backgroundable( root.getProject(), "Expanding all nodes... (may very well take the whole day)", true) { @Override public void run(@NotNull final ProgressIndicator indicator) { NullAnalysisResult l = calcNullableLeaves(root, treeStructure, map); leafExpressions.set(l); } @Override public void onCancel() { finish.run(); } @Override public void onSuccess() { try { NullAnalysisResult leaves = leafExpressions.get(); if (leaves == null) return; // cancelled groupByNullness(leaves, root, map); } finally { finish.run(); } } }); }
@Override public SliceNode getFirstChild(@NotNull SliceNode element) { Object[] children = myTreeStructure.getChildElements(element); return children.length == 0 ? null : (SliceNode) children[0]; }
public static void assertTreeStructureEquals( final AbstractTreeStructure treeStructure, final String expected) { assertEquals( expected, print(treeStructure, treeStructure.getRootElement(), 0, null, -1, ' ', null).toString()); }