本文整理匯總了Java中com.intellij.psi.search.FilenameIndex.getVirtualFilesByName方法的典型用法代碼示例。如果您正苦於以下問題:Java FilenameIndex.getVirtualFilesByName方法的具體用法?Java FilenameIndex.getVirtualFilesByName怎麽用?Java FilenameIndex.getVirtualFilesByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.search.FilenameIndex
的用法示例。
在下文中一共展示了FilenameIndex.getVirtualFilesByName方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUniqueVirtualFilePath
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
@NotNull
@Override
public String getUniqueVirtualFilePath(Project project, VirtualFile file) {
final Collection<VirtualFile> filesWithSameName = FilenameIndex.getVirtualFilesByName(project, file.getName(),
ProjectScope.getProjectScope(project));
if (filesWithSameName.size() > 1 && filesWithSameName.contains(file)) {
String path = project.getBasePath();
path = path == null ? "" : FileUtil.toSystemIndependentName(path);
UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<VirtualFile>(path, File.separator, 25);
for (VirtualFile virtualFile: filesWithSameName) {
builder.addPath(virtualFile, virtualFile.getPath());
}
return builder.getShortPath(file);
}
return file.getName();
}
示例2: checkFileDuplicates
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
@Nullable
static HighlightInfo checkFileDuplicates(@NotNull PsiJavaModule element, @NotNull PsiFile file)
{
Module module = findModule(file);
if(module != null)
{
Project project = file.getProject();
Collection<VirtualFile> others = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope());
if(others.size() > 1)
{
String message = JavaErrorMessages.message("module.file.duplicate");
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range(element)).descriptionAndTooltip(message).create();
others.stream().map(f -> PsiManager.getInstance(project).findFile(f)).filter(f -> f != file).findFirst().ifPresent(duplicate -> QuickFixAction.registerQuickFixAction(info, new
GoToSymbolFix(duplicate, JavaErrorMessages.message("module.open.duplicate.text"))));
return info;
}
}
return null;
}
示例3: findLocalFiles
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
private static Collection<VirtualFile> findLocalFiles(Project project, Url url, String fileName) {
for (LocalFileFinder finder : LocalFileFinder.EP_NAME.getExtensions()) {
final VirtualFile file = finder.findLocalFile(url, project);
if (file != null) {
return Collections.singletonList(file);
}
}
return FilenameIndex.getVirtualFilesByName(project, fileName, GlobalSearchScope.allScope(project));
}
示例4: filesWithTheSameName
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
@Nullable
private static UniqueNameBuilder<VirtualFile> filesWithTheSameName(String fileName, Project project,
boolean skipNonOpenedFiles,
GlobalSearchScope scope) {
Collection<VirtualFile> filesWithSameName = skipNonOpenedFiles ? Collections.<VirtualFile>emptySet() :
FilenameIndex.getVirtualFilesByName(project, fileName,
scope);
THashSet<VirtualFile> setOfFilesWithTheSameName = new THashSet<VirtualFile>(filesWithSameName);
// add open files out of project scope
for(VirtualFile openFile: FileEditorManager.getInstance(project).getOpenFiles()) {
if (openFile.getName().equals(fileName)) {
setOfFilesWithTheSameName.add(openFile);
}
}
for (VirtualFile recentlyEditedFile : EditorHistoryManager.getInstance(project).getFiles()) {
if (recentlyEditedFile.getName().equals(fileName)) {
setOfFilesWithTheSameName.add(recentlyEditedFile);
}
}
filesWithSameName = setOfFilesWithTheSameName;
if (filesWithSameName.size() > 1) {
String path = project.getBasePath();
path = path == null ? "" : FileUtil.toSystemIndependentName(path);
UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<VirtualFile>(path, File.separator, 25);
for (VirtualFile virtualFile: filesWithSameName) {
builder.addPath(virtualFile, virtualFile.getPath());
}
return builder;
}
return null;
}
示例5: firstMatchingVirtualFileInProject
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
/**
* Find VirtualFile in project by filename.
*/
@NotNull
private VirtualFile firstMatchingVirtualFileInProject(String filename) {
Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject));
assertTrue(String.format("Filename %s not found in project", filename), files.size() > 0);
return files.iterator().next();
}
示例6: searchForVirtualFileInProject
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
/**
* Find VirtualFile in project by filename.
*/
@NotNull
private VirtualFile searchForVirtualFileInProject(String filename) {
Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject));
assertEquals(1, files.size());
return files.iterator().next();
}
示例7: findLocalFiles
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
public static Collection<VirtualFile> findLocalFiles(Project project, String url, String fileName) {
for (LocalFileFinder finder : LocalFileFinder.EP_NAME.getExtensions()) {
final VirtualFile file = finder.findLocalFile(url, project);
if (file != null) {
return Collections.singletonList(file);
}
}
return FilenameIndex.getVirtualFilesByName(project, fileName, GlobalSearchScope.allScope(project));
}
示例8: needTransformCopying
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
private boolean needTransformCopying(CompileScope compileScope) {
final CompilerConfiguration configuration = CompilerConfiguration.getInstance(myProject);
final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
for (VirtualFile file : FilenameIndex.getVirtualFilesByName(myProject, AST_TRANSFORM_FILE_NAME, GlobalSearchScope.projectScope(myProject))) {
if (compileScope.belongs(file.getUrl()) && index.isInSource(file) && !configuration.isResourceFile(file)) {
return true;
}
}
return false;
}
示例9: filesWithTheSameName
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
@Nullable
private static UniqueNameBuilder<VirtualFile> filesWithTheSameName(String fileName, Project project,
boolean skipNonOpenedFiles,
GlobalSearchScope scope) {
Collection<VirtualFile> filesWithSameName = skipNonOpenedFiles ? Collections.emptySet() :
FilenameIndex.getVirtualFilesByName(project, fileName,
scope);
THashSet<VirtualFile> setOfFilesWithTheSameName = new THashSet<>(filesWithSameName);
// add open files out of project scope
for(VirtualFile openFile: FileEditorManager.getInstance(project).getOpenFiles()) {
if (openFile.getName().equals(fileName)) {
setOfFilesWithTheSameName.add(openFile);
}
}
if (!skipNonOpenedFiles) {
for (VirtualFile recentlyEditedFile : EditorHistoryManager.getInstance(project).getFiles()) {
if (recentlyEditedFile.getName().equals(fileName)) {
setOfFilesWithTheSameName.add(recentlyEditedFile);
}
}
}
filesWithSameName = setOfFilesWithTheSameName;
if (filesWithSameName.size() > 1) {
String path = project.getBasePath();
path = path == null ? "" : FileUtil.toSystemIndependentName(path);
UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<>(path, File.separator, 25);
for (VirtualFile virtualFile: filesWithSameName) {
builder.addPath(virtualFile, virtualFile.getPath());
}
return builder;
}
return null;
}
示例10: buildRequiresGraph
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
private static RequiresGraph buildRequiresGraph(Project project)
{
MultiMap<PsiJavaModule, PsiJavaModule> relations = MultiMap.create();
Set<String> transitiveEdges = ContainerUtil.newTroveSet();
for(Module module : ModuleManager.getInstance(project).getModules())
{
Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope());
Optional.ofNullable(ContainerUtil.getFirstItem(files)).map(PsiManager.getInstance(project)::findFile).map(f -> f instanceof PsiJavaFile ? ((PsiJavaFile) f).getModuleDeclaration() : null)
.ifPresent(m -> visit(m, relations, transitiveEdges));
}
Graph<PsiJavaModule> graph = GraphGenerator.generate(new ChameleonGraph<>(relations, true));
return new RequiresGraph(graph, transitiveEdges);
}
示例11: findFiles
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
@Override
public Collection<VirtualFile> findFiles(final String fileName) {
return FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.projectScope(myProject));
}
示例12: getAllGradleFile
import com.intellij.psi.search.FilenameIndex; //導入方法依賴的package包/類
/**
* 查找所有的build.gradle文件
*
* @param project
* @return
*/
public static Collection<VirtualFile> getAllGradleFile(Project project) {
Collection<VirtualFile> collection = FilenameIndex.getVirtualFilesByName(project,
GradleConstants.DEFAULT_SCRIPT_NAME, GlobalSearchScope.allScope(project));
return collection == null ? Collections.EMPTY_LIST : collection;
}