use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class TodoPackageNode method getFileCount.
private int getFileCount(final PackageElement packageElement) {
int count = 0;
if (getSettings().isFlattenPackages()) {
final PsiPackage aPackage = packageElement.getPackage();
final Module module = packageElement.getModule();
final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
final PsiDirectory[] directories = aPackage.getDirectories(scope);
for (PsiDirectory directory : directories) {
Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
while (iterator.hasNext()) {
PsiFile psiFile = iterator.next();
if (getStructure().accept(psiFile))
count++;
}
}
} else {
Iterator<PsiFile> iterator = getFiles(packageElement);
while (iterator.hasNext()) {
PsiFile psiFile = iterator.next();
if (getStructure().accept(psiFile)) {
count++;
}
}
}
return count;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class DefaultSymbolNavigationContributor method processElementsWithName.
@Override
public void processElementsWithName(@NotNull String name, @NotNull final Processor<NavigationItem> processor, @NotNull final FindSymbolParameters parameters) {
GlobalSearchScope scope = parameters.getSearchScope();
IdFilter filter = parameters.getIdFilter();
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(scope.getProject());
String completePattern = parameters.getCompletePattern();
final Condition<PsiMember> qualifiedMatcher = getQualifiedNameMatcher(completePattern);
//noinspection UnusedDeclaration
final Set<PsiMethod> collectedMethods = new THashSet<>();
boolean success = cache.processFieldsWithName(name, field -> {
if (isOpenable(field) && qualifiedMatcher.value(field))
return processor.process(field);
return true;
}, scope, filter) && cache.processClassesWithName(name, aClass -> {
if (isOpenable(aClass) && qualifiedMatcher.value(aClass))
return processor.process(aClass);
return true;
}, scope, filter) && cache.processMethodsWithName(name, method -> {
if (!method.isConstructor() && isOpenable(method) && qualifiedMatcher.value(method)) {
collectedMethods.add(method);
}
return true;
}, scope, filter);
if (success) {
// hashSuperMethod accesses index and can not be invoked without risk of the deadlock in processMethodsWithName
Iterator<PsiMethod> iterator = collectedMethods.iterator();
while (iterator.hasNext()) {
PsiMethod method = iterator.next();
if (!hasSuperMethod(method, scope, qualifiedMatcher) && !processor.process(method))
return;
ProgressManager.checkCanceled();
iterator.remove();
}
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PackageUtil method getSubpackages.
@NotNull
public static PsiPackage[] getSubpackages(@NotNull PsiPackage aPackage, @Nullable Module module, final boolean searchInLibraries) {
final GlobalSearchScope scopeToShow = getScopeToShow(aPackage.getProject(), module, searchInLibraries);
List<PsiPackage> result = new ArrayList<>();
for (PsiPackage psiPackage : aPackage.getSubPackages(scopeToShow)) {
// skip "default" subpackages as they should be attributed to other modules
// this is the case when contents of one module is nested into contents of another
final String name = psiPackage.getName();
if (name != null && !name.isEmpty()) {
result.add(psiPackage);
}
}
return result.toArray(new PsiPackage[result.size()]);
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PackageElementNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
final PackageElement value = getValue();
if (value == null)
return Collections.emptyList();
final List<AbstractTreeNode> children = new ArrayList<>();
final Module module = value.getModule();
final PsiPackage aPackage = value.getPackage();
if (!getSettings().isFlattenPackages()) {
final PsiPackage[] subpackages = PackageUtil.getSubpackages(aPackage, module, isLibraryElement());
for (PsiPackage subpackage : subpackages) {
PackageUtil.addPackageAsChild(children, subpackage, module, getSettings(), isLibraryElement());
}
}
// process only files in package's directories
final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(aPackage.getProject(), module, isLibraryElement());
PsiFile[] packageChildren = aPackage.getFiles(scopeToShow);
for (PsiFile file : packageChildren) {
if (file.getVirtualFile() != null) {
children.add(new PsiFileNode(getProject(), file, getSettings()));
}
}
return children;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PsiClassImplUtil method getClassUseScope.
@NotNull
public static SearchScope getClassUseScope(@NotNull PsiClass aClass) {
if (aClass instanceof PsiAnonymousClass) {
return new LocalSearchScope(aClass);
}
final GlobalSearchScope maximalUseScope = ResolveScopeManager.getElementUseScope(aClass);
PsiFile file = aClass.getContainingFile();
if (PsiImplUtil.isInServerPage(file))
return maximalUseScope;
final PsiClass containingClass = aClass.getContainingClass();
if (aClass.hasModifierProperty(PsiModifier.PUBLIC) || aClass.hasModifierProperty(PsiModifier.PROTECTED)) {
return containingClass == null ? maximalUseScope : containingClass.getUseScope();
} else if (aClass.hasModifierProperty(PsiModifier.PRIVATE) || aClass instanceof PsiTypeParameter) {
PsiClass topClass = PsiUtil.getTopLevelClass(aClass);
return new LocalSearchScope(topClass == null ? aClass.getContainingFile() : topClass);
} else {
PsiPackage aPackage = null;
if (file instanceof PsiJavaFile) {
aPackage = JavaPsiFacade.getInstance(aClass.getProject()).findPackage(((PsiJavaFile) file).getPackageName());
}
if (aPackage == null) {
PsiDirectory dir = file.getContainingDirectory();
if (dir != null) {
aPackage = JavaDirectoryService.getInstance().getPackage(dir);
}
}
if (aPackage != null) {
SearchScope scope = PackageScope.packageScope(aPackage, false);
scope = scope.intersectWith(maximalUseScope);
return scope;
}
return new LocalSearchScope(file);
}
}
Aggregations