當前位置: 首頁>>代碼示例>>Java>>正文


Java FilenameIndex.getVirtualFilesByName方法代碼示例

本文整理匯總了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();
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:17,代碼來源:UniqueVFilePathBuilderImpl.java

示例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;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:21,代碼來源:ModuleHighlightUtil.java

示例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));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:JumpFromRemoteFileToLocalAction.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:34,代碼來源:UniqueVFilePathBuilderImpl.java

示例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();
}
 
開發者ID:pantsbuild,項目名稱:intellij-pants-plugin,代碼行數:10,代碼來源:OSSRefreshPromptIntegrationTest.java

示例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();
}
 
開發者ID:pantsbuild,項目名稱:intellij-pants-plugin,代碼行數:10,代碼來源:OSSFileSyncIntegrationTest.java

示例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));
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:11,代碼來源:JumpFromRemoteFileToLocalAction.java

示例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;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:11,代碼來源:GroovyCompiler.java

示例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;
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:36,代碼來源:UniqueVFilePathBuilderImpl.java

示例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);
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:15,代碼來源:JavaModuleGraphUtil.java

示例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));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:5,代碼來源:PsiPatchBaseDirectoryDetector.java

示例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;
}
 
開發者ID:typ0520,項目名稱:fastdex,代碼行數:12,代碼來源:GradleUtil.java


注:本文中的com.intellij.psi.search.FilenameIndex.getVirtualFilesByName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。