public PsiClass findClass(@NotNull ClassId classId, @NotNull GlobalSearchScope scope) { ProgressIndicatorAndCompilationCanceledStatus .checkCanceled(); // We hope this method is being called often enough to cancel daemon // processes smoothly String qualifiedName = classId.asSingleFqName().asString(); if (shouldUseSlowResolve()) { PsiClass[] classes = findClassesInDumbMode(qualifiedName, scope); if (classes.length != 0) { return classes[0]; } return null; } for (KotlinPsiElementFinderWrapper finder : finders()) { if (finder instanceof KotlinPsiElementFinderImpl) { PsiClass aClass = ((KotlinPsiElementFinderImpl) finder).findClass(classId, scope); if (aClass != null) return aClass; } else { PsiClass aClass = finder.findClass(qualifiedName, scope); if (aClass != null) return aClass; } } return null; }
public PsiJavaPackage findPackage(@NotNull String qualifiedName, GlobalSearchScope searchScope) { PackageCache cache = SoftReference.dereference(packageCache); if (cache == null) { packageCache = new SoftReference<PackageCache>(cache = new PackageCache()); } Pair<String, GlobalSearchScope> key = new Pair<String, GlobalSearchScope>(qualifiedName, searchScope); PsiJavaPackage aPackage = cache.packageInScopeCache.get(key); if (aPackage != null) { return aPackage; } KotlinPsiElementFinderWrapper[] finders = filteredFinders(); Boolean packageFoundInAllScope = cache.hasPackageInAllScopeCache.get(qualifiedName); if (packageFoundInAllScope != null) { if (!packageFoundInAllScope.booleanValue()) return null; // Package was found in AllScope with some of finders but is absent in packageCache for // current scope. // We check only finders that depend on scope. for (KotlinPsiElementFinderWrapper finder : finders) { if (!finder.isSameResultForAnyScope()) { aPackage = finder.findPackage(qualifiedName, searchScope); if (aPackage != null) { return ConcurrencyUtil.cacheOrGet(cache.packageInScopeCache, key, aPackage); } } } } else { for (KotlinPsiElementFinderWrapper finder : finders) { aPackage = finder.findPackage(qualifiedName, searchScope); if (aPackage != null) { return ConcurrencyUtil.cacheOrGet(cache.packageInScopeCache, key, aPackage); } } boolean found = false; for (KotlinPsiElementFinderWrapper finder : finders) { if (!finder.isSameResultForAnyScope()) { aPackage = finder.findPackage(qualifiedName, GlobalSearchScope.allScope(project)); if (aPackage != null) { found = true; break; } } } cache.hasPackageInAllScopeCache.put(qualifiedName, found); } return null; }