use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class CompilerReferenceReader method getWholeHierarchy.
@Nullable("return null if the class hierarchy contains ambiguous qualified names")
private LightRef.NamedLightRef[] getWholeHierarchy(LightRef.LightClassHierarchyElementDef hierarchyElement, boolean checkBaseClassAmbiguity) throws StorageException {
Set<LightRef.NamedLightRef> result = new THashSet<>();
Queue<LightRef.NamedLightRef> q = new Queue<>(10);
q.addLast(hierarchyElement);
while (!q.isEmpty()) {
LightRef.NamedLightRef curClass = q.pullFirst();
if (result.add(curClass)) {
if (checkBaseClassAmbiguity || curClass != hierarchyElement) {
DefCount count = getDefinitionCount(curClass);
if (count == DefCount.NONE) {
//diagnostic
String baseHierarchyElement = getNameEnumerator().getName(hierarchyElement.getName());
String curHierarchyElement = getNameEnumerator().getName(curClass.getName());
LOG.error("Can't get definition files for: " + curHierarchyElement + " base class: " + baseHierarchyElement);
}
if (count != DefCount.ONE) {
return null;
}
}
myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(curClass).forEach((id, children) -> {
for (LightRef child : children) {
if (child instanceof LightRef.LightClassHierarchyElementDef) {
q.addLast((LightRef.LightClassHierarchyElementDef) child);
}
}
return true;
});
}
}
return result.toArray(new LightRef.NamedLightRef[result.size()]);
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class DirtyScopeHolder method getAllDirtyModules.
@NotNull
Set<Module> getAllDirtyModules() {
final Set<Module> dirtyModules = new THashSet<>(myVFSChangedModules);
for (Document document : myFileDocManager.getUnsavedDocuments()) {
final VirtualFile file = myFileDocManager.getFile(document);
if (file == null)
continue;
final Module m = getModuleForSourceContentFile(file);
if (m != null)
dirtyModules.add(m);
}
for (Document document : myPsiDocManager.getUncommittedDocuments()) {
final PsiFile psiFile = myPsiDocManager.getPsiFile(document);
if (psiFile == null)
continue;
final VirtualFile file = psiFile.getVirtualFile();
if (file == null)
continue;
final Module m = getModuleForSourceContentFile(file);
if (m != null)
dirtyModules.add(m);
}
return dirtyModules;
}
use of gnu.trove.THashSet in project kotlin by JetBrains.
the class SourceNavigationHelper method getOriginalClass.
@Nullable
public static PsiClass getOriginalClass(@NotNull KtClassOrObject classOrObject) {
// Copied from JavaPsiImplementationHelperImpl:getOriginalClass()
FqName fqName = classOrObject.getFqName();
if (fqName == null) {
return null;
}
KtFile file = classOrObject.getContainingKtFile();
VirtualFile vFile = file.getVirtualFile();
Project project = file.getProject();
final ProjectFileIndex idx = ProjectRootManager.getInstance(project).getFileIndex();
if (vFile == null || !idx.isInLibrarySource(vFile))
return null;
final Set<OrderEntry> orderEntries = new THashSet<OrderEntry>(idx.getOrderEntriesForFile(vFile));
return JavaPsiFacade.getInstance(project).findClass(fqName.asString(), new GlobalSearchScope(project) {
@Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
return 0;
}
@Override
public boolean contains(@NotNull VirtualFile file) {
List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
for (OrderEntry entry : entries) {
if (orderEntries.contains(entry))
return true;
}
return false;
}
@Override
public boolean isSearchInModuleContent(@NotNull Module aModule) {
return false;
}
@Override
public boolean isSearchInLibraries() {
return true;
}
});
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method processVirtualFile.
private void processVirtualFile(@NotNull final VirtualFile vfile, @NotNull final ProgressIndicator progress, @NotNull final Processor<? super PsiFile> localProcessor, @NotNull final AtomicBoolean canceled) throws ApplicationUtil.CannotRunReadActionException {
final PsiFile file = ApplicationUtil.tryRunReadAction(() -> vfile.isValid() ? myManager.findFile(vfile) : null);
if (file != null && !(file instanceof PsiBinaryFile)) {
// load contents outside read action
if (FileDocumentManager.getInstance().getCachedDocument(vfile) == null) {
// cache bytes in vfs
try {
vfile.contentsToByteArray();
} catch (IOException ignored) {
}
}
ApplicationUtil.tryRunReadAction(() -> {
final Project project = myManager.getProject();
if (project.isDisposed())
throw new ProcessCanceledException();
if (DumbService.isDumb(project))
throw new ApplicationUtil.CannotRunReadActionException();
List<PsiFile> psiRoots = file.getViewProvider().getAllFiles();
Set<PsiFile> processed = new THashSet<>(psiRoots.size() * 2, (float) 0.5);
for (final PsiFile psiRoot : psiRoots) {
progress.checkCanceled();
assert psiRoot != null : "One of the roots of file " + file + " is null. All roots: " + psiRoots + "; ViewProvider: " + file.getViewProvider() + "; Virtual file: " + file.getViewProvider().getVirtualFile();
if (!processed.add(psiRoot))
continue;
if (!psiRoot.isValid()) {
continue;
}
if (!localProcessor.process(psiRoot)) {
canceled.set(true);
break;
}
}
});
}
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class AdditionalIndexableFileSet method collectFilesAndDirectories.
private THashSet<VirtualFile> collectFilesAndDirectories() {
THashSet<VirtualFile> files = new THashSet<>();
THashSet<VirtualFile> directories = new THashSet<>();
if (myExtensions == null) {
myExtensions = Extensions.getExtensions(IndexableSetContributor.EP_NAME);
}
for (IndexableSetContributor contributor : myExtensions) {
for (VirtualFile root : IndexableSetContributor.getRootsToIndex(contributor)) {
(root.isDirectory() ? directories : files).add(root);
}
if (myProject != null) {
Set<VirtualFile> projectRoots = IndexableSetContributor.getProjectRootsToIndex(contributor, myProject);
for (VirtualFile root : projectRoots) {
(root.isDirectory() ? directories : files).add(root);
}
}
}
cachedFiles = files;
cachedDirectories = directories;
return directories;
}
Aggregations