本文整理汇总了Java中com.intellij.openapi.roots.ProjectRootManager.getFileIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectRootManager.getFileIndex方法的具体用法?Java ProjectRootManager.getFileIndex怎么用?Java ProjectRootManager.getFileIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ProjectRootManager
的用法示例。
在下文中一共展示了ProjectRootManager.getFileIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAvailable
import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@CheckReturnValue
@VisibleForTesting
@SuppressWarnings("WeakerAccess")
static boolean isAvailable(@Nonnull AnActionEvent event) {
final Project project = event.getProject();
if (project == null) {
return false;
}
final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
if (view == null) {
return false;
}
final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
final ProjectFileIndex fileIndex = rootManager.getFileIndex();
final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories())
.filter(directory -> {
final VirtualFile virtualFile = directory.getVirtualFile();
return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
})
.findFirst();
return sourceDirectory.isPresent();
}
示例2: getTopLevelRoots
import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public List<VirtualFile> getTopLevelRoots() {
List<VirtualFile> topLevelContentRoots = new ArrayList<VirtualFile>();
ProjectRootManager prm = ProjectRootManager.getInstance(myProject);
ProjectFileIndex index = prm.getFileIndex();
for (VirtualFile root : prm.getContentRoots()) {
VirtualFile parent = root.getParent();
if (parent == null || !index.isInContent(parent)) {
topLevelContentRoots.add(root);
}
}
return topLevelContentRoots;
}
示例3: getPackage
import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public static String getPackage(@NotNull PsiDirectory directory) {
final VirtualFile virtualFile = directory.getVirtualFile();
final Project project = directory.getProject();
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
return fileIndex.getPackageNameByDirectory(virtualFile);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PackageDotHtmlMayBePackageInfoInspectionBase.java
示例4: ProjectFileIndexFacade
import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public ProjectFileIndexFacade(final Project project, final ProjectRootManager rootManager, final DirectoryIndex directoryIndex) {
super(project);
myDirectoryIndex = directoryIndex;
myFileIndex = rootManager.getFileIndex();
}
示例5: DirectoryNode
import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public DirectoryNode(VirtualFile aDirectory,
Project project,
boolean compactPackages,
boolean showFQName,
VirtualFile baseDir, final VirtualFile[] contentRoots) {
super(project);
myVDirectory = aDirectory;
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
final ProjectFileIndex index = projectRootManager.getFileIndex();
String dirName = aDirectory.getName();
if (showFQName) {
final VirtualFile contentRoot = index.getContentRootForFile(myVDirectory);
if (contentRoot != null) {
if (Comparing.equal(myVDirectory, contentRoot)) {
myFQName = dirName;
}
else {
final VirtualFile sourceRoot = index.getSourceRootForFile(myVDirectory);
if (Comparing.equal(myVDirectory, sourceRoot)) {
myFQName = VfsUtilCore.getRelativePath(myVDirectory, contentRoot, '/');
}
else if (sourceRoot != null) {
myFQName = VfsUtilCore.getRelativePath(myVDirectory, sourceRoot, '/');
}
else {
myFQName = VfsUtilCore.getRelativePath(myVDirectory, contentRoot, '/');
}
}
if (contentRoots.length > 1 && ProjectRootsUtil.isModuleContentRoot(myVDirectory, project)) {
myFQName = getContentRootName(baseDir, myFQName);
}
}
else {
myFQName = FilePatternPackageSet.getLibRelativePath(myVDirectory, index);
}
dirName = myFQName;
} else {
if (contentRoots.length > 1 && ProjectRootsUtil.isModuleContentRoot(myVDirectory, project)) {
dirName = getContentRootName(baseDir, dirName);
}
}
myDirName = dirName;
myCompactPackages = compactPackages;
}
示例6: createBeanClass
import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@NotNull
private static PsiClass createBeanClass(final WizardData wizardData) throws MyException {
final PsiManager psiManager = PsiManager.getInstance(wizardData.myProject);
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(wizardData.myProject);
final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(wizardData.myFormFile);
if (sourceRoot == null) {
throw new MyException(UIDesignerBundle.message("error.form.file.is.not.in.source.root"));
}
final PsiDirectory rootDirectory = psiManager.findDirectory(sourceRoot);
LOG.assertTrue(rootDirectory != null);
final PsiPackage aPackage = JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(wizardData.myPackageName);
if (aPackage == null) {
throw new MyException(UIDesignerBundle.message("error.package.does.not.exist", wizardData.myPackageName));
}
PsiDirectory targetDir = null;
final PsiDirectory[] directories = aPackage.getDirectories();
for (final PsiDirectory psiDirectory : directories) {
if (PsiTreeUtil.isAncestor(rootDirectory, psiDirectory, false)) {
targetDir = psiDirectory;
break;
}
}
if (targetDir == null) {
// todo
throw new MyException(UIDesignerBundle.message("error.cannot.find.package", wizardData.myPackageName));
}
//noinspection HardCodedStringLiteral
final String body =
"public class " + wizardData.myShortClassName + "{\n" +
"public " + wizardData.myShortClassName + "(){}\n" +
"}";
try {
PsiFile sourceFile =
PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText(wizardData.myShortClassName + ".java", body);
sourceFile = (PsiFile)targetDir.add(sourceFile);
final PsiClass beanClass = ((PsiJavaFile)sourceFile).getClasses()[0];
final ArrayList<String> properties = new ArrayList<String>();
final HashMap<String, String> property2fqClassName = new HashMap<String, String>();
final FormProperty2BeanProperty[] bindings = wizardData.myBindings;
for (final FormProperty2BeanProperty binding : bindings) {
if (binding == null || binding.myBeanProperty == null) {
continue;
}
properties.add(binding.myBeanProperty.myName);
// todo: handle "casts" ?
final String propertyClassName = binding.myFormProperty.getComponentPropertyClassName();
property2fqClassName.put(binding.myBeanProperty.myName, propertyClassName);
}
generateBean(beanClass, ArrayUtil.toStringArray(properties), property2fqClassName);
return beanClass;
}
catch (IncorrectOperationException e) {
throw new MyException(e.getMessage());
}
}