当前位置: 首页>>代码示例>>Java>>正文


Java VfsUtilCore.getRelativePath方法代码示例

本文整理汇总了Java中com.intellij.openapi.vfs.VfsUtilCore.getRelativePath方法的典型用法代码示例。如果您正苦于以下问题:Java VfsUtilCore.getRelativePath方法的具体用法?Java VfsUtilCore.getRelativePath怎么用?Java VfsUtilCore.getRelativePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.vfs.VfsUtilCore的用法示例。


在下文中一共展示了VfsUtilCore.getRelativePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatRelativePath

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
@NotNull
private static CellAppearanceEx formatRelativePath(@NotNull final ContentFolder folder, @NotNull final Icon icon) {
  LightFilePointer folderFile = new LightFilePointer(folder.getUrl());
  VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(folder.getContentEntry().getUrl());
  if (file == null) return FileAppearanceService.getInstance().forInvalidUrl(folderFile.getPresentableUrl());

  String contentPath = file.getPath();
  String relativePath;
  SimpleTextAttributes textAttributes;
  VirtualFile folderFileFile = folderFile.getFile();
  if (folderFileFile == null) {
    String absolutePath = folderFile.getPresentableUrl();
    relativePath = absolutePath.startsWith(contentPath) ? absolutePath.substring(contentPath.length()) : absolutePath;
    textAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
  }
  else {
    relativePath = VfsUtilCore.getRelativePath(folderFileFile, file, File.separatorChar);
    textAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
  }

  relativePath = StringUtil.isEmpty(relativePath) ? "." + File.separatorChar : relativePath;
  return new SimpleTextCellAppearance(relativePath, icon, textAttributes);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:OrderEntryAppearanceServiceImpl.java

示例2: copyFile

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
private boolean copyFile(VirtualFile file, VirtualFile src, File destinationFile, VirtualFile dest) throws IOException {
  String relativePath = VfsUtilCore.getRelativePath(file, src, File.separatorChar);
  if (relativePath == null) {
    LOG.error(file.getPath() + " is not a child of " + src, new Exception());
    return false;
  }
  if (file.isDirectory()) {
    checkedCreateDirectoryIfMissing(new File(destinationFile, relativePath));
  }
  else {
    VirtualFile targetDir = dest;
    if (relativePath.indexOf(File.separatorChar) > 0) {
      String directories = relativePath.substring(0, relativePath.lastIndexOf(File.separatorChar));
      File newParent = new File(destinationFile, directories);
      targetDir = checkedCreateDirectoryIfMissing(newParent);
    }
    VfsUtilCore.copyFile(this, file, targetDir);
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:RecipeContext.java

示例3: getRelativePath

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
@Nullable
public static String getRelativePath(@NotNull VirtualFile virtualFile,
                                     @NotNull ProjectFileIndex index,
                                     final boolean useFQName,
                                     VirtualFile projectBaseDir) {
  final VirtualFile contentRootForFile = index.getContentRootForFile(virtualFile);
  if (contentRootForFile != null) {
    return VfsUtilCore.getRelativePath(virtualFile, contentRootForFile, '/');
  }
  final Module module = index.getModuleForFile(virtualFile);
  if (module != null) {
    if (projectBaseDir != null) {
      if (VfsUtilCore.isAncestor(projectBaseDir, virtualFile, false)){
        final String projectRelativePath = VfsUtilCore.getRelativePath(virtualFile, projectBaseDir, '/');
        return useFQName ? projectRelativePath : projectRelativePath.substring(projectRelativePath.indexOf('/') + 1);
      }
    }
    return virtualFile.getPath();
  } else {
    return getLibRelativePath(virtualFile, index);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:FilePatternPackageSet.java

示例4: findMatchingRoot

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
@Nullable
private static ImportSpecification findMatchingRoot(
    VirtualFile fileToImport, List<HeadersSearchRoot> roots, boolean asUserHeader) {
  for (HeadersSearchRoot root : roots) {
    if (!(root instanceof IncludedHeadersRoot)) {
      continue;
    }
    IncludedHeadersRoot includedHeadersRoot = (IncludedHeadersRoot) root;
    if (asUserHeader != includedHeadersRoot.isUserHeaders()) {
      continue;
    }
    VirtualFile rootBase = root.getVirtualFile();
    String relativePath = VfsUtilCore.getRelativePath(fileToImport, rootBase);
    if (relativePath == null) {
      continue;
    }
    return new ImportSpecification(
        relativePath,
        asUserHeader
            ? ImportSpecification.Kind.USER_HEADER_SEARCH_PATH
            : ImportSpecification.Kind.SYSTEM_HEADER_SEARCH_PATH);
  }
  return null;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:25,代码来源:BlazeCppAutoImportHelper.java

示例5: collectFiles2Move

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
private static void collectFiles2Move(Map<PsiFile, TargetDirectoryWrapper> files2Move,
                                      Map<PsiDirectory, TargetDirectoryWrapper> nestedDirsToMove,
                                      PsiDirectory directory,
                                      PsiDirectory rootDirectory,
                                      @NotNull TargetDirectoryWrapper targetDirectory) {
  final PsiElement[] children = directory.getChildren();
  final String relativePath = VfsUtilCore.getRelativePath(directory.getVirtualFile(), rootDirectory.getVirtualFile(), '/');

  final TargetDirectoryWrapper newTargetDirectory = relativePath.length() == 0
                                                    ? targetDirectory
                                                    : targetDirectory.findOrCreateChild(relativePath);
  nestedDirsToMove.put(directory, newTargetDirectory);
  for (PsiElement child : children) {
    if (child instanceof PsiFile) {
      files2Move.put((PsiFile)child, newTargetDirectory);
    }
    else if (child instanceof PsiDirectory){
      collectFiles2Move(files2Move, nestedDirsToMove, (PsiDirectory)child, directory, newTargetDirectory);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MoveDirectoryWithClassesProcessor.java

示例6: visitRoot

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
public boolean visitRoot(VirtualFile root, Module module, Sdk sdk, boolean isModuleSource) {
  if (myVFile != null) {
    final String relativePath = VfsUtilCore.getRelativePath(myVFile, root, '/');
    if (relativePath != null && !relativePath.isEmpty()) {
      List<String> result = StringUtil.split(relativePath, "/");
      if (result.size() > 0) {
        result.set(result.size() - 1, FileUtil.getNameWithoutExtension(result.get(result.size() - 1)));
      }
      for (String component : result) {
        if (!PyNames.isIdentifier(component)) {
          return true;
        }
      }
      myResults.add(QualifiedName.fromComponents(result));
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:QualifiedNameFinder.java

示例7: getPackageDirs

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
private static String getPackageDirs(DataContext dataContext) {
  final Module module = LangDataKeys.MODULE.getData(dataContext);
  if (module != null) {
    final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
    if (sourceRoots.length > 0) {
      for (VirtualFile sourceRoot : sourceRoots) {
        // TODO notify if we have multiple source roots and can't build mapping automatically
        final VirtualFile contentRoot = ProjectFileIndex.SERVICE.getInstance(module.getProject()).getContentRootForFile(sourceRoot);
        if (contentRoot != null && !Comparing.equal(contentRoot, sourceRoot)) {
          final String relativePath = VfsUtilCore.getRelativePath(sourceRoot, contentRoot, '/');
          return "\n    package_dir={'': '" + relativePath + "'},";
        }
      }
    }
  }
  return "";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:CreateSetupPyAction.java

示例8: getClassesLanguageLevel

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
/**
 * For files under a library source root, returns the language level configured for the corresponding classes root.
 *
 * @param virtualFile virtual file for which language level is requested.
 * @return language level for classes root or null if file is not under a library source root or no matching classes root is found.
 */
@Nullable
private LanguageLevel getClassesLanguageLevel(VirtualFile virtualFile) {
  final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
  final VirtualFile sourceRoot = index.getSourceRootForFile(virtualFile);
  final VirtualFile folder = virtualFile.getParent();
  if (sourceRoot != null && folder != null) {
    String relativePath = VfsUtilCore.getRelativePath(folder, sourceRoot, '/');
    if (relativePath == null) {
      throw new AssertionError("Null relative path: folder=" + folder + "; root=" + sourceRoot);
    }
    List<OrderEntry> orderEntries = index.getOrderEntriesForFile(virtualFile);
    if (orderEntries.isEmpty()) {
      LOG.error("Inconsistent: " + DirectoryIndex.getInstance(myProject).getInfoForFile(folder).toString());
    }
    final String className = virtualFile.getNameWithoutExtension();
    final VirtualFile[] files = orderEntries.get(0).getFiles(OrderRootType.CLASSES);
    for (VirtualFile rootFile : files) {
      final VirtualFile classFile = rootFile.findFileByRelativePath(relativePath);
      if (classFile != null) {
        final PsiJavaFile javaFile = getPsiFileInRoot(classFile, className);
        if (javaFile != null) {
          return javaFile.getLanguageLevel();
        }
      }
    }
    return LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel();
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:JavaPsiImplementationHelperImpl.java

示例9: getRelativePathInSources

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
@Nullable
private static String getRelativePathInSources(@NotNull VirtualFile file, final @NotNull ModuleOutputPackagingElement moduleElement,
                                              @NotNull PackagingElementResolvingContext context) {
  for (VirtualFile sourceRoot : moduleElement.getSourceRoots(context)) {
    if (VfsUtilCore.isAncestor(sourceRoot, file, true)) {
      return VfsUtilCore.getRelativePath(file, sourceRoot, '/');
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ArtifactUtil.java

示例10: isSameSupposedUrl

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
private static <T extends RootUrlPair> boolean isSameSupposedUrl(@NotNull T child, @NotNull T parent) {
  boolean result = false;

  if (VfsUtilCore.isAncestor(parent.getVirtualFile(), child.getVirtualFile(), true)) {
    String relativePath = VfsUtilCore.getRelativePath(child.getVirtualFile(), parent.getVirtualFile(), '/');
    // get child's supposed and real urls
    final String supposed = getSupposedUrl(parent.getUrl(), relativePath);
    if (supposed.equals(child.getUrl())) {
      result = true;
    }
  }

  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:UniqueRootsFilter.java

示例11: getPath

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
@Nullable
protected String getPath(final Object value) {
  final VirtualFile file = (VirtualFile)value;
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myFile.getProject()).getFileIndex();
  if (file != null) {
    VirtualFile root = fileIndex.getSourceRootForFile(file);
    if (root == null) {
      root = fileIndex.getContentRootForFile(file);
    }
    if (root != null) {
      return VfsUtilCore.getRelativePath(file, root, '/');
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:FileIncludeContextHectorPanel.java

示例12: getContentRootName

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
private String getContentRootName(final VirtualFile baseDir, final String dirName) {
  if (baseDir != null) {
    if (!Comparing.equal(myVDirectory, baseDir)) {
      if (VfsUtil.isAncestor(baseDir, myVDirectory, false)) {
        return VfsUtilCore.getRelativePath(myVDirectory, baseDir, '/');
      }
      else {
        return myVDirectory.getPresentableUrl();
      }
    }
  } else {
    return myVDirectory.getPresentableUrl();
  }
  return dirName;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:DirectoryNode.java

示例13: getFQName

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
public String getFQName() {
  final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
  VirtualFile directory = myVDirectory;
  VirtualFile contentRoot = index.getContentRootForFile(directory);
  if (Comparing.equal(directory, contentRoot)) {
    return "";
  }
  if (contentRoot == null) {
    return "";
  }
  return VfsUtilCore.getRelativePath(directory, contentRoot, '/');
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:DirectoryNode.java

示例14: collapse2eclipsePathRelative2Module

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
@Nullable
private static String collapse2eclipsePathRelative2Module(VirtualFile file, Module module) {
  final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
  for (VirtualFile otherRoot : contentRoots) {
    if (VfsUtilCore.isAncestor(otherRoot, file, false)) {
      return "/" + module.getName() + "/" + VfsUtilCore.getRelativePath(file, otherRoot, '/');
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:EPathUtil.java

示例15: getStringRepresentation

import com.intellij.openapi.vfs.VfsUtilCore; //导入方法依赖的package包/类
public String getStringRepresentation(@NotNull IdeaSourceProvider sourceProvider, @Nullable VirtualFile baseFile) {
  StringBuilder sb = new StringBuilder();
  VirtualFile manifestFile = sourceProvider.getManifestFile();
  String manifestPath = null;
  if (manifestFile != null) {
    if (baseFile != null) {
      manifestPath = VfsUtilCore.getRelativePath(manifestFile, baseFile, File.separatorChar);
    } else {
      manifestPath = manifestFile.getPath();
    }
  }
  sb.append("Manifest File: ");
  sb.append(manifestPath);
  sb.append('\n');

  sb.append("Java Directories: ");
  sb.append(fileSetToString(sourceProvider.getJavaDirectories(), baseFile));
  sb.append('\n');
  sb.append("Res Directories: ");
  sb.append(fileSetToString(sourceProvider.getResDirectories(), baseFile));
  sb.append('\n');
  sb.append("Assets Directories: ");
  sb.append(fileSetToString(sourceProvider.getAssetsDirectories(), baseFile));
  sb.append('\n');
  sb.append("AIDL Directories: ");
  sb.append(fileSetToString(sourceProvider.getAidlDirectories(), baseFile));
  sb.append('\n');
  sb.append("Renderscript Directories: ");
  sb.append(fileSetToString(sourceProvider.getRenderscriptDirectories(), baseFile));
  sb.append('\n');
  sb.append("Jni Directories: ");
  sb.append(fileSetToString(sourceProvider.getJniDirectories(), baseFile));
  sb.append('\n');
  sb.append("Resources Directories: ");
  sb.append(fileSetToString(sourceProvider.getResourcesDirectories(), baseFile));
  sb.append('\n');
  return sb.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:IdeaSourceProviderTest.java


注:本文中的com.intellij.openapi.vfs.VfsUtilCore.getRelativePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。