use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class SimpleAccessorReferenceSearcher method addPropertyAccessUsages.
static void addPropertyAccessUsages(@NotNull PsiMethod method, @NotNull SearchScope scope, @NotNull SearchRequestCollector collector) {
final String propertyName = PropertyUtil.getPropertyName(method);
if (StringUtil.isNotEmpty(propertyName)) {
SearchScope additional = GlobalSearchScope.EMPTY_SCOPE;
for (CustomPropertyScopeProvider provider : Extensions.getExtensions(CustomPropertyScopeProvider.EP_NAME)) {
additional = additional.union(provider.getScope(method.getProject()));
}
SearchScope propScope = scope.intersectWith(method.getUseScope()).intersectWith(additional);
collector.searchWord(propertyName, propScope, UsageSearchContext.IN_FOREIGN_LANGUAGES, true, method);
}
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class VariableInIncompleteCodeSearcher method processQuery.
@Override
public void processQuery(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
final PsiElement refElement = p.getElementToSearch();
if (!refElement.isValid() || !(refElement instanceof PsiVariable))
return;
final String name = ((PsiVariable) refElement).getName();
if (StringUtil.isEmptyOrSpaces(name))
return;
SearchScope scope = p.getEffectiveSearchScope();
if (!(scope instanceof LocalSearchScope)) {
final PsiFile file = refElement.getContainingFile();
if (file == null || file instanceof PsiCompiledElement)
return;
//process incomplete references to the 'field' in the same file only
scope = new LocalSearchScope(new PsiElement[] { file }, null, !PsiSearchHelperImpl.shouldProcessInjectedPsi(p.getScopeDeterminedByUser()));
} else {
PsiElement[] elements = ((LocalSearchScope) scope).getScope();
PsiElement[] sourceElements = ContainerUtil.findAllAsArray(elements, e -> !(e instanceof PsiCompiledElement));
if (sourceElements.length != elements.length) {
if (sourceElements.length == 0)
return;
scope = new LocalSearchScope(sourceElements);
}
}
PsiElement[] elements = ((LocalSearchScope) scope).getScope();
if (elements.length == 0)
return;
PsiSearchHelper.SERVICE.getInstance(p.getProject()).processElementsWithWord((element, offsetInElement) -> {
for (PsiElement child = element.findElementAt(offsetInElement); child != null; child = child.getParent()) {
if (!child.textMatches(name)) {
break;
}
if (child instanceof PsiJavaCodeReferenceElement) {
final PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement) child;
if (!ref.isQualified() && !(ref.getParent() instanceof PsiMethodCallExpression) && ref.resolve() == null && ref.advancedResolve(true).getElement() == refElement) {
consumer.process(ref);
}
}
}
return true;
}, scope, name, UsageSearchContext.ANY, true);
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class ResolveVariable15Test method testNavigateToEnumFunction.
public void testNavigateToEnumFunction() throws Exception {
PsiElement element = resolveTarget();
assertTrue(element instanceof PsiMethod);
PsiClass aClass = ((PsiMethod) element).getContainingClass();
assertTrue(aClass instanceof PsiEnumConstantInitializer);
SearchScope scope = element.getUseScope();
assertFalse(scope instanceof LocalSearchScope);
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class SubtypesHierarchyTreeStructure method buildChildren.
@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
final Object element = ((TypeHierarchyNodeDescriptor) descriptor).getPsiClass();
if (!(element instanceof PsiClass))
return ArrayUtil.EMPTY_OBJECT_ARRAY;
final PsiClass psiClass = (PsiClass) element;
if (CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName())) {
return new Object[] { IdeBundle.message("node.hierarchy.java.lang.object") };
}
if (psiClass instanceof PsiAnonymousClass)
return ArrayUtil.EMPTY_OBJECT_ARRAY;
if (psiClass.hasModifierProperty(PsiModifier.FINAL))
return ArrayUtil.EMPTY_OBJECT_ARRAY;
final SearchScope searchScope = psiClass.getUseScope().intersectWith(getSearchScope(myCurrentScopeType, psiClass));
final List<PsiClass> classes = new ArrayList<>(searchInheritors(psiClass, searchScope));
final List<HierarchyNodeDescriptor> descriptors = new ArrayList<>(classes.size());
for (PsiClass aClass : classes) {
descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, aClass, false));
}
FunctionalExpressionSearch.search(psiClass, searchScope).forEach(expression -> {
descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, expression, false));
return true;
});
return descriptors.toArray(new HierarchyNodeDescriptor[descriptors.size()]);
}
use of com.intellij.psi.search.SearchScope 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