TreeNode (@NotNull TreeNode parent, @NotNull Class<?> type) { int childCount = parent.getChildCount(); for (int idx = 0; idx < childCount; idx++) { TreeNode child = parent.getChildAt(idx); if (type.isAssignableFrom(child.getClass())) { return child; } TreeNode firstChildOfType = getFirstChildOfType(child, type); if (firstChildOfType != null) { return firstChildOfType; } } return null; }