Collection<ChildFileInfo> (@NotNull final Project project, @NotNull final VirtualFile parentFile) { LOG.assertTrue(!parentFile.isDirectory()); if (!ProjectViewState.getInstance(project).getUseFileNestingRules()) return Collections.emptyList(); final Collection<NestingRule> rules = FileNestingBuilder.getInstance().getNestingRules(); if (rules.isEmpty()) return Collections.emptyList(); final Collection<NestingRule> rulesWhereItCanBeParent = filterRules(rules, parentFile.getName(), true); if (rulesWhereItCanBeParent.isEmpty()) return Collections.emptyList(); final Collection<NestingRule> rulesWhereItCanBeChild = filterRules(rules, parentFile.getName(), false); final VirtualFile dir = parentFile.getParent(); if (dir == null) return Collections.emptyList(); final VirtualFile[] children = dir.getChildren(); if (children.length <= 1) return Collections.emptyList(); final SmartList<ChildFileInfo> result = new SmartList<>(); for (VirtualFile child : children) { if (child.isDirectory()) continue; if (child.equals(parentFile)) continue; // if given parentFile itself appears to be a child of some other file, it means that it is not shown as parent node in Project View for (NestingRule rule : rulesWhereItCanBeChild) { final String childName = child.getName(); final Couple<Boolean> c = FileNestingBuilder.checkMatchingAsParentOrChild(rule, childName); final boolean matchesParent = c.first; if (matchesParent) { final String baseName = childName.substring(0, childName.length() - rule.getParentFileSuffix().length()); if (parentFile.getName().equals(baseName + rule.getChildFileSuffix())) { return Collections.emptyList(); // parentFile itself appears to be a child of childFile } } } for (NestingRule rule : rulesWhereItCanBeParent) { final String childName = child.getName(); final Couple<Boolean> c = FileNestingBuilder.checkMatchingAsParentOrChild(rule, childName); final boolean matchesChild = c.second; if (matchesChild) { final String baseName = childName.substring(0, childName.length() - rule.getChildFileSuffix().length()); if (parentFile.getName().equals(baseName + rule.getParentFileSuffix())) { result.add(new ChildFileInfo(child, baseName)); } } } } return result; }