本文整理汇总了Java中com.intellij.openapi.roots.ProjectFileIndex.getClassRootForFile方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectFileIndex.getClassRootForFile方法的具体用法?Java ProjectFileIndex.getClassRootForFile怎么用?Java ProjectFileIndex.getClassRootForFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ProjectFileIndex
的用法示例。
在下文中一共展示了ProjectFileIndex.getClassRootForFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
public String toString() {
if (myText == null) {
Module module = ModuleUtilCore.findModuleForPsiElement(myClass);
if (module != null) {
myText = module.getName();
}
else {
VirtualFile virtualFile = myClass.getContainingFile().getVirtualFile();
final ProjectFileIndex index = ProjectRootManager.getInstance(myClass.getProject()).getFileIndex();
VirtualFile root = index.getSourceRootForFile(virtualFile);
if (root == null) {
root = index.getClassRootForFile(virtualFile);
}
if (root != null) {
myText = root.getName();
}
else {
myText = virtualFile.getPath();
}
}
}
return myText;
}
示例2: addSourceDirectoriesFromLibraries
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
private static void addSourceDirectoriesFromLibraries(@NotNull Project project,
@NotNull VirtualFile file,
@NotNull Collection<VirtualFile> outSourceRoots) {
ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
// if we already are in the sources, search just in this directory only
if (index.isInLibrarySource(file)) return;
VirtualFile classRoot = index.getClassRootForFile(file);
if (classRoot == null) return;
String relativePath = VfsUtilCore.getRelativePath(file, classRoot);
if (relativePath == null) return;
for (OrderEntry orderEntry : index.getOrderEntriesForFile(file)) {
for (VirtualFile sourceRoot : orderEntry.getFiles(OrderRootType.SOURCES)) {
VirtualFile sourceFile = sourceRoot.findFileByRelativePath(relativePath);
if (sourceFile != null) {
outSourceRoots.add(sourceFile);
}
}
}
}
示例3: getRootDirectoryForPackage
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public static String getRootDirectoryForPackage(PsiDirectory directory) {
PsiManager manager = directory.getManager();
final VirtualFile virtualFile = directory.getVirtualFile();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(manager.getProject()).getFileIndex();
VirtualFile root = fileIndex.getSourceRootForFile(virtualFile);
if (root == null) {
root = fileIndex.getClassRootForFile(virtualFile);
}
if (root != null) {
return root.getPresentableUrl();
}
return null;
}