Search in sources :

Example 1 with LocalFileProvider

use of com.intellij.openapi.vfs.LocalFileProvider in project intellij-community by JetBrains.

the class ProjectUtilCore method displayUrlRelativeToProject.

public static String displayUrlRelativeToProject(@NotNull VirtualFile file, @NotNull String url, @NotNull Project project, boolean includeFilePath, boolean keepModuleAlwaysOnTheLeft) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir != null && includeFilePath) {
        //noinspection ConstantConditions
        final String projectHomeUrl = baseDir.getPresentableUrl();
        if (url.startsWith(projectHomeUrl)) {
            url = "..." + url.substring(projectHomeUrl.length());
        }
    }
    if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
        final VirtualFile fileForJar = ((LocalFileProvider) file.getFileSystem()).getLocalVirtualFileFor(file);
        if (fileForJar != null) {
            final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
            if (libraryEntry != null) {
                if (libraryEntry instanceof JdkOrderEntry) {
                    url = url + " - [" + ((JdkOrderEntry) libraryEntry).getJdkName() + "]";
                } else {
                    url = url + " - [" + libraryEntry.getPresentableName() + "]";
                }
            } else {
                url = url + " - [" + fileForJar.getName() + "]";
            }
        }
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module == null)
        return url;
    return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ? url + " - [" + module.getName() + "]" : "[" + module.getName() + "] - " + url;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LocalFileProvider(com.intellij.openapi.vfs.LocalFileProvider) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1 LocalFileProvider (com.intellij.openapi.vfs.LocalFileProvider)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1