本文整理汇总了Java中com.intellij.openapi.roots.ProjectFileIndex.getModuleForFile方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectFileIndex.getModuleForFile方法的具体用法?Java ProjectFileIndex.getModuleForFile怎么用?Java ProjectFileIndex.getModuleForFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ProjectFileIndex
的用法示例。
在下文中一共展示了ProjectFileIndex.getModuleForFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
public PsiElement resolve() {
final Project project = myFile.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile formVirtualFile = myFile.getVirtualFile();
if (formVirtualFile == null) {
return null;
}
final Module module = fileIndex.getModuleForFile(formVirtualFile);
if (module == null) {
return null;
}
final VirtualFile formFile = ResourceFileUtil.findResourceFileInDependents(module, getRangeText());
if (formFile == null) {
return null;
}
return PsiManager.getInstance(project).findFile(formFile);
}
示例2: MoveClassToModuleFix
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public MoveClassToModuleFix(String referenceName, Module currentModule, PsiDirectory root, PsiElement psiElement) {
myReferenceName = referenceName;
myCurrentModule = currentModule;
mySourceRoot = root;
final Project project = psiElement.getProject();
final PsiClass[] classes = PsiShortNamesCache.getInstance(project).getClassesByName(referenceName, GlobalSearchScope.allScope(project));
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (final PsiClass aClass : classes) {
if (!facade.getResolveHelper().isAccessible(aClass, psiElement, aClass)) continue;
final PsiFile psiFile = aClass.getContainingFile();
if (!(psiFile instanceof PsiJavaFile)) continue;
if (aClass.getQualifiedName() == null) continue;
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) continue;
final Module classModule = fileIndex.getModuleForFile(virtualFile);
if (classModule != null && classModule != currentModule && !ModuleRootManager.getInstance(currentModule).isDependsOn(classModule)) {
myModules.put(aClass, classModule);
}
}
}
示例3: getModulesFor
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
private Module[] getModulesFor(PsiDirectory dir) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
final VirtualFile vFile = dir.getVirtualFile();
final Set<Module> modules = new HashSet<Module>();
final Module module = fileIndex.getModuleForFile(vFile);
if (module != null) {
modules.add(module);
}
if (fileIndex.isInLibrarySource(vFile) || fileIndex.isInLibraryClasses(vFile)) {
final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(vFile);
if (orderEntries.isEmpty()) {
return Module.EMPTY_ARRAY;
}
for (OrderEntry entry : orderEntries) {
modules.add(entry.getOwnerModule());
}
}
return modules.toArray(new Module[modules.size()]);
}
示例4: matchesModule
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public static boolean matchesModule(final Pattern moduleGroupPattern,
final Pattern modulePattern,
final VirtualFile file,
final ProjectFileIndex fileIndex) {
final Module module = fileIndex.getModuleForFile(file);
if (module != null) {
if (modulePattern != null && modulePattern.matcher(module.getName()).matches()) return true;
if (moduleGroupPattern != null) {
final String[] groupPath = ModuleManager.getInstance(module.getProject()).getModuleGroupPath(module);
if (groupPath != null) {
for (String node : groupPath) {
if (moduleGroupPattern.matcher(node).matches()) return true;
}
}
}
}
return modulePattern == null && moduleGroupPattern == null;
}
示例5: getRelativePath
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的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);
}
}
示例6: getModule
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
protected static Module getModule(PsiDirectory dir) {
Project project = dir.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile vFile = dir.getVirtualFile();
if (fileIndex.isInLibrarySource(vFile) || fileIndex.isInLibraryClasses(vFile)) {
final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(vFile);
if (orderEntries.isEmpty()) {
return null;
}
Set<Module> modules = new HashSet<Module>();
for (OrderEntry orderEntry : orderEntries) {
modules.add(orderEntry.getOwnerModule());
}
final Module[] candidates = modules.toArray(new Module[modules.size()]);
Arrays.sort(candidates, ModuleManager.getInstance(project).moduleDependencyComparator());
return candidates[0];
}
return fileIndex.getModuleForFile(vFile);
}
示例7: getParentNodeFor
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Override
@Nullable
public ChangesBrowserNode getParentNodeFor(final StaticFilePath node, final ChangesBrowserNode rootNode) {
if (myProject.isDefault()) return null;
ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
VirtualFile vFile = node.getVf();
if (vFile == null) {
vFile = LocalFileSystem.getInstance().findFileByIoFile(new File(node.getPath()));
}
boolean hideExcludedFiles = Registry.is("ide.hide.excluded.files");
if (vFile != null && Comparing.equal(vFile, index.getContentRootForFile(vFile, hideExcludedFiles))) {
Module module = index.getModuleForFile(vFile, hideExcludedFiles);
return getNodeForModule(module, rootNode);
}
return null;
}
示例8: getFiles
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
/**
* @return read-only iterator of all valid PSI files that can have T.O.D.O items
* and which in specified <code>module</code>.
* @see FileTree#getFiles(VirtualFile)
*/
public Iterator<PsiFile> getFiles(Module module) {
if (module.isDisposed()) return Collections.<PsiFile>emptyList().iterator();
ArrayList<PsiFile> psiFileList = new ArrayList<PsiFile>();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
for (VirtualFile virtualFile : contentRoots) {
List<VirtualFile> files = myFileTree.getFiles(virtualFile);
PsiManager psiManager = PsiManager.getInstance(myProject);
for (VirtualFile file : files) {
if (fileIndex.getModuleForFile(file) != module) continue;
if (file.isValid()) {
PsiFile psiFile = psiManager.findFile(file);
if (psiFile != null) {
psiFileList.add(psiFile);
}
}
}
}
return psiFileList.iterator();
}
示例9: getSelectedGradleModule
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
protected Module getSelectedGradleModule(@NotNull AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Module module = MODULE_CONTEXT.getData(dataContext);
if (isGradleModule(module)) {
return module;
}
Project project = e.getProject();
if (project != null) {
VirtualFile file = VIRTUAL_FILE.getData(dataContext);
if (file != null) {
ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
module = fileIndex.getModuleForFile(file);
if (isGradleModule(module)) {
return module;
}
}
}
return null;
}
示例10: findContainingMavenizedModule
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
@Nullable
public static Module findContainingMavenizedModule(@NotNull PsiFile psiFile) {
VirtualFile file = psiFile.getVirtualFile();
if (file == null) return null;
Project project = psiFile.getProject();
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
if (!manager.isMavenizedProject()) return null;
ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
Module module = index.getModuleForFile(file);
if (module == null || !manager.isMavenizedModule(module)) return null;
return module;
}
示例11: resolve
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public PsiElement resolve() {
final Project project = myFile.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile formVirtualFile = myFile.getVirtualFile();
if (formVirtualFile == null) {
return null;
}
final Module module = fileIndex.getModuleForFile(formVirtualFile);
if (module == null) {
return null;
}
final PropertiesFile propertiesFile = PropertiesUtilBase.getPropertiesFile(myBundleName, module, null);
if (propertiesFile == null) {
return null;
}
IProperty property = propertiesFile.findPropertyByKey(getRangeText());
return property == null ? null : property.getPsiElement();
}
示例12: registerFixes
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public static void registerFixes(QuickFixActionRegistrar registrar, final PsiJavaCodeReferenceElement reference) {
final PsiElement psiElement = reference.getElement();
@NonNls final String referenceName = reference.getRangeInElement().substring(psiElement.getText());
Project project = psiElement.getProject();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile == null) return;
PsiDirectory dir = containingFile.getContainingDirectory();
if (dir == null) return;
VirtualFile classVFile = containingFile.getVirtualFile();
if (classVFile == null) return;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final Module currentModule = fileIndex.getModuleForFile(classVFile);
if (currentModule == null) return;
List<VirtualFile> sourceRoots = ModuleRootManager.getInstance(currentModule).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
if (sourceRoots.isEmpty()) return;
final PsiDirectory sourceDirectory = PsiManager.getInstance(project).findDirectory(sourceRoots.get(0));
if (sourceDirectory == null) return;
VirtualFile vsourceRoot = fileIndex.getSourceRootForFile(classVFile);
if (vsourceRoot == null) return;
final PsiDirectory sourceRoot = PsiManager.getInstance(project).findDirectory(vsourceRoot);
if (sourceRoot == null) return;
registrar.register(new MoveClassToModuleFix(referenceName, currentModule, sourceRoot, psiElement));
}
示例13: expand
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public String expand(DataContext dataContext) {
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return null;
}
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (file != null) {
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = projectFileIndex.getModuleForFile(file);
if (module != null){
boolean isTest = projectFileIndex.isInTestSourceContent(file);
String outputPathUrl = isTest ? CompilerModuleExtension.getInstance(module).getCompilerOutputUrlForTests()
: CompilerModuleExtension.getInstance(module).getCompilerOutputUrl();
if (outputPathUrl == null) return null;
return VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar);
}
}
Module[] allModules = ModuleManager.getInstance(project).getSortedModules();
if (allModules.length == 0) {
return null;
}
String[] paths = CompilerPathsEx.getOutputPaths(allModules);
final StringBuffer outputPath = new StringBuffer();
for (int idx = 0; idx < paths.length; idx++) {
String path = paths[idx];
if (idx > 0) {
outputPath.append(File.pathSeparator);
}
outputPath.append(path);
}
return outputPath.toString();
}
示例14: resolve
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public PsiElement resolve() {
final Project project = myFile.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile formVirtualFile = myFile.getVirtualFile();
if (formVirtualFile == null) {
return null;
}
final Module module = fileIndex.getModuleForFile(formVirtualFile);
if (module == null) {
return null;
}
PropertiesFile propertiesFile = PropertiesUtilBase.getPropertiesFile(getRangeText(), module, null);
return propertiesFile == null ? null : propertiesFile.getContainingFile();
}
示例15: getDirectoryChildren
import com.intellij.openapi.roots.ProjectFileIndex; //导入方法依赖的package包/类
public Collection<AbstractTreeNode> getDirectoryChildren(final PsiDirectory psiDirectory,
final ViewSettings settings,
final boolean withSubDirectories) {
final List<AbstractTreeNode> children = new ArrayList<AbstractTreeNode>();
final Project project = psiDirectory.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final Module module = fileIndex.getModuleForFile(psiDirectory.getVirtualFile());
final ModuleFileIndex moduleFileIndex = module == null ? null : ModuleRootManager.getInstance(module).getFileIndex();
if (!settings.isFlattenPackages() || skipDirectory(psiDirectory)) {
processPsiDirectoryChildren(psiDirectory, directoryChildrenInProject(psiDirectory, settings),
children, fileIndex, null, settings, withSubDirectories);
}
else { // source directory in "flatten packages" mode
final PsiDirectory parentDir = psiDirectory.getParentDirectory();
if (parentDir == null || skipDirectory(parentDir) && withSubDirectories) {
addAllSubpackages(children, psiDirectory, moduleFileIndex, settings);
}
if (withSubDirectories) {
PsiDirectory[] subdirs = psiDirectory.getSubdirectories();
for (PsiDirectory subdir : subdirs) {
if (!skipDirectory(subdir)) {
continue;
}
VirtualFile directoryFile = subdir.getVirtualFile();
if (Registry.is("ide.hide.excluded.files")) {
if (fileIndex.isExcluded(directoryFile)) continue;
}
else {
if (FileTypeRegistry.getInstance().isFileIgnored(directoryFile)) continue;
}
children.add(new PsiDirectoryNode(project, subdir, settings));
}
}
processPsiDirectoryChildren(psiDirectory, psiDirectory.getFiles(), children, fileIndex, moduleFileIndex, settings,
withSubDirectories);
}
return children;
}