AbstractTreeNode (AbstractTreeNode<?> rootElement, VirtualFile file, Object element) { Object[] childElements = getChildren(rootElement); List<AbstractTreeNode<?>> nodes = getAllAcceptableNodes(childElements, file); if (nodes.size() == 1) return nodes.get(0); if (nodes.isEmpty()) return null; if (file.isDirectory()) { return nodes.get(0); } else { return performDeepSearch(nodes.toArray(), element, new HashSet<>()); } }