本文整理匯總了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());
}
}