/** Test whether the second node is a (direct) child of the first one. * @param parent parent node * @param son son node * @return <code>true</code> if so */ public static boolean isSon(Node parent, Node son) { return son.getParentNode() == parent; }
/** Find the root for a given node. * @param node the node * @return its root */ public static Node findRoot(Node node) { for (;;) { Node parent = node.getParentNode(); if (parent == null) { return node; } node = parent; } }
/** Find a path (by name) from one node to the root or a parent. * @param node the node to start in * @param parent parent node to stop in (can be <code>null</code> for the root) * @return list of child names--i.e. a path from the parent to the child node * @exception IllegalArgumentException if <code>node</code>'s getName() * method returns <code>null</code> */ public static String[] createPath(Node node, Node parent) { LinkedList<String> ar = new LinkedList<String>(); while ((node != null) && (node != parent)) { if (node.getName() == null) { boolean isFilter = false; if (node instanceof FilterNode) { isFilter = true; } throw new IllegalArgumentException( "Node:" + node.getClass() // NOI18N +"[" + node.getDisplayName() + "]" // NOI18N +(isFilter ? (" of original:" + ((FilterNode) node).getOriginal().getClass()) : "") // NOI18N +" gets null name!" ); // NOI18N } ar.addFirst(node.getName()); node = node.getParentNode(); } String[] res = new String[ar.size()]; ar.toArray(res); return res; }
Node parentNode = node.getParentNode();
protected boolean selectionAccept(Node[] nodes) { if (nodes.length == 0) { return true; } Node parent = nodes[0].getParentNode(); for (int i = 1; i < nodes.length; i++) { if (nodes[i].getParentNode() != parent) { return false; } } return true; }
/** */ private static JUnitTestMethodNode getTestMethodNode(Node node) { while (!(node instanceof JUnitTestMethodNode)) { node = node.getParentNode(); } return (JUnitTestMethodNode) node; }
/** */ public static TestMethodNode getTestMethodNode(Node node) { while (!(node instanceof TestMethodNode)) { node = node.getParentNode(); } return (TestMethodNode) node; }
protected boolean selectionAccept(Node[] nodes) { if (nodes.length == 0) return true; Node parent = nodes[0].getParentNode (); for (int i = 1; i < nodes.length; i++) { if (nodes[i].getParentNode () != parent) { return false; } } return true; }
/** Test whether the second node is a (direct) child of the first one. * @param parent parent node * @param son son node * @return <code>true</code> if so */ public static boolean isSon (Node parent, Node son) { return son.getParentNode () == parent; }
private TestsuiteNode getSelectedSuite(Node selected) { if (selected instanceof TestMethodNode) { return (TestsuiteNode) selected.getParentNode(); } else if (selected instanceof TestsuiteNode) { return (TestsuiteNode) selected; } else if (selected instanceof CallstackFrameNode) { return (TestsuiteNode) selected.getParentNode().getParentNode(); } return getFirstFailedSuite(); }
/** Checks whether given Node is a subnode of rootContext. * @return true if specified Node is under current rootContext */ private boolean isUnderRoot(Node node) { while (node != null) { if (node.equals(rootContext)) { return true; } node = node.getParentNode(); } return false; }
private final void collectNodes(Node n, Map<Node,?> collect) { assert Children.MUTEX.isReadAccess(); while (n != null && n != rootContext) { collect.put(n, null); n = n.getParentNode(); } }
/** Checks whether given Node is a subnode of rootContext. * @return true if specified Node is under current rootContext */ private boolean isUnderRoot(Node rootContext, Node node) { while (node != null) { if (node.equals(rootContext)) { return true; } node = node.getParentNode(); } return false; }
private Index getIndexSupport (Node n) { Node parent = n.getParentNode (); assert parent != null : "Node " + n + " has a parent."; Index index = parent.getLookup ().lookup (Index.class); assert index != null : "Node " + parent + " has Index cookie."; return index; }
/** Helper method. Returns index cookie or null, if some * conditions weren't satisfied */ private Index getIndexCookie (Node[] activatedNodes) { if ((activatedNodes == null) || (activatedNodes.length != 1)) return null; Node parent = activatedNodes[0].getParentNode(); if (parent == null) return null; return (Index)parent.getCookie(Index.class); }
private static Project getNodeProject(Node node) { if (node == null) { return null; } Project project = node.getLookup().lookup(Project.class); if (project != null) { return project; } else { return getNodeProject(node.getParentNode()); } }
private static boolean isParent(Node parent, Node child) { if (NodeOp.isSon(parent, child)) { return true; } Node p = child.getParentNode(); if (p == null) { return false; } return isParent(parent, p); }
public void actionPerformed(ActionEvent e) { if (traversalAllowed) { Node pan = manager.getExploredContext(); pan = pan.getParentNode(); if (pan != null) { manager.setExploredContext(pan, manager.getSelectedNodes()); } } }
public void actionPerformed(ActionEvent e) { if (traversalAllowed) { Node pan = manager.getExploredContext(); pan = pan.getParentNode(); if (pan != null) manager.setExploredContext(pan, manager.getSelectedNodes()); } } public boolean isEnabled() {
private int getNodePosition (Node n) { Index supp = getIndexSupport (n); DataFolder df = n.getParentNode ().getLookup ().lookup (DataFolder.class); df.getNodeDelegate ().getChildren ().getNodes (true); int pos = supp.indexOf (n); // #141851: getNodes()/getNodePosition() is not called under Children.MUTEX // therefore it is not guaranteed that node will be found (node could be deleted meanwhile) // assert pos != -1 : "Node " + n + " has position " + pos + " in children " + Arrays.asList (n.getParentNode ().getChildren ().getNodes ()); return pos; }