TreeUtil { @Nullable public static Tree getTree(@NotNull Tree tree, @NotNull String path) { for (String element : PathUtils.elements(path)) { if (PathUtils.denotesParent(element)) { if (tree.isRoot()) { return null; } else { tree = tree.getParent(); } } else if (!PathUtils.denotesCurrent(element)) { tree = tree.getChild(element); } } return tree; } private  TreeUtil(); @Nullable static String getPrimaryTypeName(@NotNull Tree tree); @Nullable static String getPrimaryTypeName(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree); @NotNull static Iterable<String> getMixinTypeNames(@NotNull Tree tree); @NotNull static Iterable<String> getMixinTypeNames(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree); @Nullable static Iterable<String> getStrings(@NotNull Tree tree, @NotNull String propertyName); @Nullable static String getString(@NotNull Tree tree, @NotNull String propertyName); @Nullable static String getString(@NotNull Tree tree, @NotNull String name, @Nullable String defaultValue); static boolean getBoolean(@NotNull Tree tree, @NotNull String propertyName); @Nullable static String getName(@NotNull Tree tree, @NotNull String name); @NotNull static Iterable<String> getNames(@NotNull Tree tree, @NotNull String name); static long getLong(@NotNull Tree tree, @NotNull String name, long defaultValue); @Nullable static Tree getTree(@NotNull Tree tree, @NotNull String path); static Tree addChild(
            @NotNull Tree parent, @NotNull String name,
            @Nullable String typeName, @NotNull Tree typeRoot,
            @Nullable String userID); @NotNull static Tree addChild(@NotNull Tree tree, @NotNull String childName, @NotNull String primaryTypeName); @NotNull static Tree getOrAddChild(@NotNull Tree tree, @NotNull String childName, @NotNull String primaryTypeName); static void addMixin(@NotNull Tree tree, @NotNull String mixinName, @NotNull Tree typeRoot, @Nullable String userID); static void autoCreateItems(@NotNull Tree tree, @NotNull Tree type, @NotNull Tree typeRoot, @Nullable String userID); static PropertyState autoCreateProperty(@NotNull String name,
                                                   @NotNull Tree definition,
                                                   @Nullable String userID); static String getDefaultChildType(
            Tree typeRoot, Tree parent, String childName); static List<Tree> getEffectiveType(Tree tree, Tree typeRoot); static String findDefaultPrimaryType(Tree definitions, boolean sns); static boolean isNodeType(Tree tree, String typeName, Tree typeRoot); static boolean isReadOnlyTree(@NotNull Tree tree);  }
@Test public void testGetTree() { String relPath = PathUtils.relativize(PathUtils.ROOT_PATH, child.getPath()); Tree t = TreeUtil.getTree(rootTree, relPath); assertEquals(CHILD_PATH, t.getPath()); }
@Test public void testGetTreeWithCurrentElements() { String relPath = "./././"+PathUtils.relativize(PathUtils.ROOT_PATH, child.getPath()); Tree t = TreeUtil.getTree(rootTree, relPath); assertEquals(CHILD_PATH, t.getPath()); }
@Test public void testGetTreeWithParentElements() { String relPath = PathUtils.relativize(PathUtils.ROOT_PATH, child.getPath()) + "/.."; Tree t = TreeUtil.getTree(rootTree, relPath); assertEquals(child.getParent().getPath(), t.getPath()); }
@Test public void testGetTreeWithAbsolutePath() { assertEquals(CHILD_PATH, TreeUtil.getTree(rootTree, child.getPath()).getPath()); }
@Test public void testGetTreeWithNonExisting() { assertEquals(nonExisting.getPath(), TreeUtil.getTree(rootTree, "nonExisting").getPath()); }
@Test public void testGetTreeWithParentOfRootNonExisting() { assertNull(TreeUtil.getTree(rootTree, "x/../../../x")); }