Collection<FileTargetContext> (@NotNull PsiFile file) { boolean absolutePathReference = isAbsolutePathReference(); if (!absolutePathReference) { PsiElement context = file.getContext(); if (context != null) file = context.getContainingFile(); Collection<PsiFileSystemItem> folders = getIncludingFileContexts(file); if (folders != null) return toTargetContexts(folders); } PsiDirectory parent = file.getParent(); Module module = ModuleUtilCore.findModuleForPsiElement(parent == null ? file : parent); if (absolutePathReference && module == null) return emptyList(); PsiFileSystemItem originalFile = file.getOriginalFile(); VirtualFile virtualFile = originalFile.getVirtualFile(); if (virtualFile == null) return emptyList(); // reference helpers may provide non-unique results, use LinkedHashSet to collapse them preserving the order Set<FileTargetContext> list = new LinkedHashSet<>(); Project project = originalFile.getProject(); CommonProcessors.CollectProcessor<FileTargetContext> processor = new CommonProcessors.CollectProcessor<>(list); FileReferenceHelper[] helpers = FileReferenceHelperRegistrar.getHelpers(); for (FileReferenceHelper helper : helpers) { if (helper.isMine(project, virtualFile)) { if (!list.isEmpty() && helper.isFallback()) { continue; } if (!helper.processTargetContexts(this, virtualFile, processor)) { break; } } } if (!list.isEmpty()) { if (!ContainerUtil.exists(list, el -> !(el.getFileSystemItem() instanceof FileReferenceResolver))) { for (PsiFileSystemItem item : getParentDirectoryContext()) { list.add(new FileTargetContext(item)); } } return list; } return toTargetContexts(getParentDirectoryContext()); }