@NotNull public static Collection<PsiFileSystemItem> getAbsoluteTopLevelDirLocations( final @NotNull PsiFile file) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return Collections.emptyList(); } final Project project = file.getProject(); PsiDirectory parent = file.getParent(); final Module module = ModuleUtil.findModuleForPsiElement(parent == null ? file : parent); if (module == null) { return Collections.emptyList(); } final FileReferenceHelper[] helpers = FileReferenceHelperRegistrar.getHelpers(); final ArrayList<PsiFileSystemItem> list = new ArrayList<PsiFileSystemItem>(); for (FileReferenceHelper helper : helpers) { if (helper.isMine(project, virtualFile)) { final Collection<PsiFileSystemItem> roots = helper.getRoots(module); for (PsiFileSystemItem root : roots) { LOG.assertTrue(root != null, "Helper " + helper + " produced a null root for " + file); } list.addAll(roots); } } if (list.size() == 0) { list.addAll(FileReferenceHelperRegistrar.getNotNullHelper(file).getRoots(module)); } return list; }
public static FileReferenceSet createSet( PsiElement element, final boolean soft, boolean endingSlashNotAllowed, final boolean urlEncoded) { String text; int offset; final ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element); assert manipulator != null; final TextRange range = manipulator.getRangeInElement(element); offset = range.getStartOffset(); text = range.substring(element.getText()); for (final FileReferenceHelper helper : FileReferenceHelperRegistrar.getHelpers()) { text = helper.trimUrl(text); } return new FileReferenceSet(text, element, offset, null, true, endingSlashNotAllowed) { @Override protected boolean isUrlEncoded() { return urlEncoded; } @Override protected boolean isSoft() { return soft; } }; }
@NotNull private Collection<PsiFileSystemItem> getContextByFile(@NotNull PsiFile file) { final PsiElement context = file.getContext(); if (context != null) file = context.getContainingFile(); if (useIncludingFileAsContext()) { final FileContextProvider contextProvider = FileContextProvider.getProvider(file); if (contextProvider != null) { final Collection<PsiFileSystemItem> folders = contextProvider.getContextFolders(file); if (!folders.isEmpty()) { return folders; } final PsiFile contextFile = contextProvider.getContextFile(file); if (contextFile != null) { return Collections.<PsiFileSystemItem>singleton(contextFile.getParent()); } } } VirtualFile virtualFile = file.getOriginalFile().getVirtualFile(); if (virtualFile != null) { final FileReferenceHelper[] helpers = FileReferenceHelperRegistrar.getHelpers(); final ArrayList<PsiFileSystemItem> list = new ArrayList<PsiFileSystemItem>(); final Project project = file.getProject(); for (FileReferenceHelper helper : helpers) { if (helper.isMine(project, virtualFile)) { list.addAll(helper.getContexts(project, virtualFile)); } } if (list.size() > 0) { return list; } final VirtualFile parent = virtualFile.getParent(); if (parent != null) { final PsiDirectory directory = file.getManager().findDirectory(parent); if (directory != null) { return Collections.<PsiFileSystemItem>singleton(directory); } } } return Collections.emptyList(); }