本文整理汇总了Java中com.intellij.openapi.roots.FileIndexFacade.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FileIndexFacade.getInstance方法的具体用法?Java FileIndexFacade.getInstance怎么用?Java FileIndexFacade.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.FileIndexFacade
的用法示例。
在下文中一共展示了FileIndexFacade.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapClass
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@Nullable
private PsiClass mapClass(@NotNull PsiClass psiClass) {
String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null) {
return psiClass;
}
PsiFile file = psiClass.getContainingFile();
if (file == null || !file.getViewProvider().isPhysical()) {
return psiClass;
}
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
return psiClass;
}
final FileIndexFacade index = FileIndexFacade.getInstance(file.getProject());
if (!index.isInSource(vFile) && !index.isInLibrarySource(vFile) && !index.isInLibraryClasses(vFile)) {
return psiClass;
}
return JavaPsiFacade.getInstance(psiClass.getProject()).findClass(qualifiedName, myResolveScope);
}
示例2: getPsiClasses
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
public static PsiClass[] getPsiClasses(@NotNull PsiDirectory dir, PsiFile[] psiFiles) {
FileIndexFacade index = FileIndexFacade.getInstance(dir.getProject());
VirtualFile virtualDir = dir.getVirtualFile();
boolean onlyCompiled = index.isInLibraryClasses(virtualDir) && !index.isInSourceContent(virtualDir);
List<PsiClass> classes = null;
for (PsiFile file : psiFiles) {
if (onlyCompiled && !(file instanceof ClsFileImpl)) {
continue;
}
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
PsiClass[] psiClasses = ((PsiClassOwner)file).getClasses();
if (psiClasses.length == 0) continue;
if (classes == null) classes = new ArrayList<PsiClass>();
ContainerUtil.addAll(classes, psiClasses);
}
}
return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
}
示例3: processFilesContainingAllKeys
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
private static boolean processFilesContainingAllKeys(@NotNull Project project,
@NotNull final GlobalSearchScope scope,
@Nullable final Condition<Integer> checker,
@NotNull final Collection<IdIndexEntry> keys,
@NotNull final Processor<VirtualFile> processor) {
final FileIndexFacade index = FileIndexFacade.getInstance(project);
return DumbService.getInstance(project).runReadActionInSmartMode(new Computable<Boolean>() {
@Override
public Boolean compute() {
return FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, keys, scope, checker, new Processor<VirtualFile>() {
@Override
public boolean process(VirtualFile file) {
return !index.shouldBeFound(scope, file) || processor.process(file);
}
});
}
});
}
示例4: getClasses
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
@Override
public PsiClass[] getClasses(@NotNull PsiDirectory dir) {
LOG.assertTrue(dir.isValid());
FileIndexFacade index = FileIndexFacade.getInstance(dir.getProject());
VirtualFile virtualDir = dir.getVirtualFile();
boolean onlyCompiled = index.isInLibraryClasses(virtualDir) && !index.isInSourceContent(virtualDir);
List<PsiClass> classes = null;
for (PsiFile file : dir.getFiles()) {
if (onlyCompiled && !(file instanceof ClsFileImpl)) {
continue;
}
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
PsiClass[] psiClasses = ((PsiClassOwner)file).getClasses();
if (psiClasses.length == 0) continue;
if (classes == null) classes = new ArrayList<PsiClass>();
ContainerUtil.addAll(classes, psiClasses);
}
}
return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
}
示例5: processFilesWithText
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
public boolean processFilesWithText(@NotNull final GlobalSearchScope scope,
final short searchContext,
final boolean caseSensitively,
@NotNull String text,
@NotNull final Processor<VirtualFile> processor) {
List<IdIndexEntry> entries = getWordEntries(text, caseSensitively);
if (entries.isEmpty()) return true;
final CommonProcessors.CollectProcessor<VirtualFile> collectProcessor = new CommonProcessors.CollectProcessor<VirtualFile>();
processFilesContainingAllKeys(scope, new Condition<Integer>() {
@Override
public boolean value(Integer integer) {
return (integer.intValue() & searchContext) != 0;
}
}, collectProcessor, entries);
final FileIndexFacade index = FileIndexFacade.getInstance(myManager.getProject());
return ContainerUtil.process(collectProcessor.getResults(), new ReadActionProcessor<VirtualFile>() {
@Override
public boolean processInReadAction(VirtualFile virtualFile) {
return !index.shouldBeFound(scope, virtualFile) || processor.process(virtualFile);
}
});
}
示例6: getClassNames
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
@Override
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
Set<String> names = null;
FileIndexFacade facade = FileIndexFacade.getInstance(myProject);
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
for (PsiFile file : dir.getFiles()) {
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
VirtualFile vFile = file.getVirtualFile();
if (vFile != null &&
!(file instanceof PsiCompiledElement) &&
!facade.isInSourceContent(vFile) &&
(!scope.isForceSearchingInLibrarySources() || !StubTreeLoader.getInstance().canHaveStub(vFile))) {
continue;
}
Set<String> inFile =
file instanceof PsiClassOwnerEx ? ((PsiClassOwnerEx)file).getClassNames() : getClassNames(((PsiClassOwner)file).getClasses());
if (inFile.isEmpty()) continue;
if (names == null) names = new HashSet<String>();
names.addAll(inFile);
}
}
}
return names == null ? Collections.<String>emptySet() : names;
}
示例7: checkClassUnderSources
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
private boolean checkClassUnderSources(final PsiElement element, final Project project) {
final PsiFile file = element.getContainingFile();
if (file != null && file.getVirtualFile() != null) {
final FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
final VirtualFile vf = file.getVirtualFile();
return indexFacade.isInSource(vf) || indexFacade.isInSourceContent(vf);
}
return false;
}
示例8: getPsiFile
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
/**
* Tries to find PSI file for a virtual file and throws assertion error with debug info if it is null.
*/
@NotNull
public static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
PsiManager psiManager = PsiManager.getInstance(project);
PsiFile psi = psiManager.findFile(file);
if (psi != null) return psi;
FileType fileType = file.getFileType();
FileViewProvider viewProvider = psiManager.findViewProvider(file);
Document document = FileDocumentManager.getInstance().getDocument(file);
boolean ignored = !(file instanceof LightVirtualFile) && FileTypeRegistry.getInstance().isFileIgnored(file);
VirtualFile vDir = file.getParent();
PsiDirectory psiDir = vDir == null ? null : PsiManager.getInstance(project).findDirectory(vDir);
FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
StringBuilder sb = new StringBuilder();
sb.append("valid=").append(file.isValid()).
append(" isDirectory=").append(file.isDirectory()).
append(" hasDocument=").append(document != null).
append(" length=").append(file.getLength());
sb.append("\nproject=").append(project.getName()).
append(" default=").append(project.isDefault()).
append(" open=").append(project.isOpen());;
sb.append("\nfileType=").append(fileType.getName()).append("/").append(fileType.getClass().getName());
sb.append("\nisIgnored=").append(ignored);
sb.append(" underIgnored=").append(indexFacade.isUnderIgnored(file));
sb.append(" inLibrary=").append(indexFacade.isInLibrarySource(file) || indexFacade.isInLibraryClasses(file));
sb.append(" parentDir=").append(vDir == null ? "no-vfs" : vDir.isDirectory() ? "has-vfs-dir" : "has-vfs-file").
append("/").append(psiDir == null ? "no-psi" : "has-psi");
sb.append("\nviewProvider=").append(viewProvider == null ? "null" : viewProvider.getClass().getName());
if (viewProvider != null) {
List<PsiFile> files = viewProvider.getAllFiles();
sb.append(" language=").append(viewProvider.getBaseLanguage().getID());
sb.append(" physical=").append(viewProvider.isPhysical());
sb.append(" rootCount=").append(files.size());
for (PsiFile o : files) {
sb.append("\n root=").append(o.getLanguage().getID()).append("/").append(o.getClass().getName());
}
}
LOG.error("no PSI for file '" + file.getName() + "'", new Attachment(file.getPresentableUrl(), sb.toString()));
throw new AssertionError();
}
示例9: buildProjectScope
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
@Override
public GlobalSearchScope buildProjectScope() {
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
if (projectRootManager == null) {
return new EverythingGlobalScope(myProject) {
@Override
public boolean isSearchInLibraries() {
return false;
}
};
}
return new ProjectScopeImpl(myProject, FileIndexFacade.getInstance(myProject));
}
示例10: buildProjectScope
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
/**
* Project directories are commonly included in PYTHONPATH and as a result are listed as library classes. Core logic
* includes them in project scope only if they are also marked as source roots. Python code is often not marked as source
* root, so we need to override the core logic and check only whether the file is under project content.
*
* @return project search scope
*/
@NotNull
@Override
public GlobalSearchScope buildProjectScope() {
final FileIndexFacade fileIndex = FileIndexFacade.getInstance(myProject);
return new ProjectScopeImpl(myProject, fileIndex) {
@Override
public boolean contains(@NotNull VirtualFile file) {
if (file instanceof VirtualFileWindow) return true;
return fileIndex.isInContent(file);
}
};
}
示例11: isInSourceFiles
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
private static boolean isInSourceFiles(@Nullable VirtualFile file, @NotNull Project project) {
if (file != null && !(file instanceof LightVirtualFile)) {
final FileIndexFacade index = FileIndexFacade.getInstance(project);
if (index.isInSource(file) || index.isInLibraryClasses(file)) {
return true;
}
}
return false;
}
示例12: filterOutIgnored
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
private static Collection<VirtualFile> filterOutIgnored(
@NotNull Project project, @NotNull Collection<VirtualFile> files) {
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
final FileIndexFacade fileIndex = FileIndexFacade.getInstance(project);
return Collections2.filter(
files, file -> !changeListManager.isIgnoredFile(file) && !fileIndex.isExcludedFile(file));
}
示例13: getClassNames
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
@Override
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
Set<String> names = null;
FileIndexFacade facade = FileIndexFacade.getInstance(myProject);
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
for (PsiFile file : dir.getFiles()) {
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
VirtualFile vFile = file.getVirtualFile();
if (vFile != null &&
!(file instanceof PsiCompiledElement) &&
!facade.isInSourceContent(vFile) &&
(!scope.isForceSearchingInLibrarySources() ||
!StubTreeLoader.getInstance().canHaveStub(vFile))) {
continue;
}
Set<String> inFile = file instanceof PsiClassOwnerEx ? ((PsiClassOwnerEx)file).getClassNames() : getClassNames(((PsiClassOwner)file).getClasses());
if (inFile.isEmpty()) continue;
if (names == null) names = new HashSet<String>();
names.addAll(inFile);
}
}
}
return names == null ? Collections.<String>emptySet() : names;
}
示例14: isCheapEnoughToSearch
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
@NotNull
@Override
public SearchCostResult isCheapEnoughToSearch(@NotNull String name,
@NotNull final GlobalSearchScope scope,
@Nullable final PsiFile fileToIgnoreOccurencesIn,
@Nullable final ProgressIndicator progress) {
final AtomicInteger count = new AtomicInteger();
final FileIndexFacade index = FileIndexFacade.getInstance(myManager.getProject());
final Processor<VirtualFile> processor = new Processor<VirtualFile>() {
private final VirtualFile fileToIgnoreOccurencesInVirtualFile =
fileToIgnoreOccurencesIn != null ? fileToIgnoreOccurencesIn.getVirtualFile() : null;
@Override
public boolean process(VirtualFile file) {
if (progress != null) progress.checkCanceled();
if (Comparing.equal(file, fileToIgnoreOccurencesInVirtualFile)) return true;
if (!index.shouldBeFound(scope, file)) return true;
final int value = count.incrementAndGet();
return value < 10;
}
};
List<IdIndexEntry> keys = getWordEntries(name, true);
boolean cheap = keys.isEmpty() || processFilesContainingAllKeys(scope, null, processor, keys);
if (!cheap) {
return SearchCostResult.TOO_MANY_OCCURRENCES;
}
return count.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES;
}
示例15: getPsiFile
import com.intellij.openapi.roots.FileIndexFacade; //导入方法依赖的package包/类
/**
* Tries to find PSI file for a virtual file and throws assertion error with debug info if it is null.
*/
@Nonnull
public static PsiFile getPsiFile(@Nonnull Project project, @Nonnull VirtualFile file) {
PsiManager psiManager = PsiManager.getInstance(project);
PsiFile psi = psiManager.findFile(file);
if (psi != null) return psi;
FileType fileType = file.getFileType();
FileViewProvider viewProvider = psiManager.findViewProvider(file);
Document document = FileDocumentManager.getInstance().getDocument(file);
boolean ignored = !(file instanceof LightVirtualFile) && FileTypeRegistry.getInstance().isFileIgnored(file);
VirtualFile vDir = file.getParent();
PsiDirectory psiDir = vDir == null ? null : PsiManager.getInstance(project).findDirectory(vDir);
FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
StringBuilder sb = new StringBuilder();
sb.append("valid=").append(file.isValid()).
append(" isDirectory=").append(file.isDirectory()).
append(" hasDocument=").append(document != null).
append(" length=").append(file.getLength());
sb.append("\nproject=").append(project.getName()).
append(" default=").append(project.isDefault()).
append(" open=").append(project.isOpen());;
sb.append("\nfileType=").append(fileType.getName()).append("/").append(fileType.getClass().getName());
sb.append("\nisIgnored=").append(ignored);
sb.append(" underIgnored=").append(indexFacade.isUnderIgnored(file));
sb.append(" inLibrary=").append(indexFacade.isInLibrarySource(file) || indexFacade.isInLibraryClasses(file));
sb.append(" parentDir=").append(vDir == null ? "no-vfs" : vDir.isDirectory() ? "has-vfs-dir" : "has-vfs-file").
append("/").append(psiDir == null ? "no-psi" : "has-psi");
sb.append("\nviewProvider=").append(viewProvider == null ? "null" : viewProvider.getClass().getName());
if (viewProvider != null) {
List<PsiFile> files = viewProvider.getAllFiles();
sb.append(" language=").append(viewProvider.getBaseLanguage().getID());
sb.append(" physical=").append(viewProvider.isPhysical());
sb.append(" rootCount=").append(files.size());
for (PsiFile o : files) {
sb.append("\n root=").append(o.getLanguage().getID()).append("/").append(o.getClass().getName());
}
}
LOG.error("no PSI for file '" + file.getName() + "'", new Attachment(file.getPresentableUrl(), sb.toString()));
throw new AssertionError();
}