use of com.intellij.psi.search.SearchScope in project kotlin by JetBrains.
the class KotlinCallerMethodsTreeStructure method buildChildren.
@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
final PsiElement element = getTargetElement(descriptor);
KtElement codeBlockForLocalDeclaration = getEnclosingElementForLocalDeclaration(element);
if (codeBlockForLocalDeclaration != null) {
BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
final Map<PsiReference, PsiElement> referencesToElements = new HashMap<PsiReference, PsiElement>();
codeBlockForLocalDeclaration.accept(new CalleeReferenceVisitorBase(bindingContext, true) {
@Override
protected void processDeclaration(KtSimpleNameExpression reference, PsiElement declaration) {
if (!declaration.equals(element))
return;
//noinspection unchecked
PsiElement container = PsiTreeUtil.getParentOfType(reference, KtNamedFunction.class, KtPropertyAccessor.class, KtClassOrObject.class);
if (container instanceof KtPropertyAccessor) {
container = PsiTreeUtil.getParentOfType(container, KtProperty.class);
}
if (container != null) {
referencesToElements.put(ReferenceUtilKt.getMainReference(reference), container);
}
}
});
return collectNodeDescriptors(descriptor, referencesToElements, null);
}
SearchScope searchScope = getSearchScope(scopeType, basePsiClass);
Map<PsiElement, HierarchyNodeDescriptor> methodToDescriptorMap = Maps.newHashMap();
Object[] javaCallers = null;
if (element instanceof PsiMethod) {
javaCallers = javaTreeStructure.getChildElements(getJavaNodeDescriptor(descriptor));
processPsiMethodCallers(Collections.singleton((PsiMethod) element), descriptor, methodToDescriptorMap, searchScope, true);
}
if (element instanceof KtNamedFunction || element instanceof KtSecondaryConstructor) {
Collection<PsiMethod> lightMethods = LightClassUtil.INSTANCE.getLightClassMethods((KtFunction) element);
processPsiMethodCallers(lightMethods, descriptor, methodToDescriptorMap, searchScope, false);
}
if (element instanceof KtProperty) {
LightClassUtil.PropertyAccessorsPsiMethods propertyMethods = LightClassUtil.INSTANCE.getLightClassPropertyMethods((KtProperty) element);
processPsiMethodCallers(propertyMethods, descriptor, methodToDescriptorMap, searchScope, false);
}
if (element instanceof KtClassOrObject) {
KtPrimaryConstructor constructor = ((KtClassOrObject) element).getPrimaryConstructor();
if (constructor != null) {
PsiMethod lightMethod = LightClassUtil.INSTANCE.getLightClassMethod(constructor);
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
} else {
processKtClassOrObjectCallers((KtClassOrObject) element, descriptor, methodToDescriptorMap, searchScope);
}
}
Object[] callers = methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
return (javaCallers != null) ? ArrayUtil.mergeArrays(javaCallers, callers) : callers;
}
use of com.intellij.psi.search.SearchScope in project kotlin by JetBrains.
the class KtNamedDeclarationStub method getUseScope.
@NotNull
@Override
public SearchScope getUseScope() {
KtElement enclosingBlock = KtPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
if (enclosingBlock != null) {
PsiElement enclosingParent = enclosingBlock.getParent();
if (enclosingParent instanceof KtContainerNode) {
enclosingParent = enclosingParent.getParent();
}
if (enclosingBlock instanceof KtBlockExpression && enclosingParent instanceof KtDoWhileExpression) {
KtExpression condition = ((KtDoWhileExpression) enclosingParent).getCondition();
if (condition != null)
return new LocalSearchScope(new PsiElement[] { enclosingBlock, condition });
}
return new LocalSearchScope(enclosingBlock);
}
if (hasModifier(KtTokens.PRIVATE_KEYWORD)) {
KtElement containingClass = PsiTreeUtil.getParentOfType(this, KtClassOrObject.class);
if (containingClass instanceof KtObjectDeclaration && ((KtObjectDeclaration) containingClass).isCompanion()) {
KtElement companionObjectClass = PsiTreeUtil.getParentOfType(containingClass, KtClassOrObject.class);
if (companionObjectClass != null) {
containingClass = companionObjectClass;
}
}
if (containingClass != null) {
return new LocalSearchScope(containingClass);
}
}
SearchScope scope = super.getUseScope();
KtClassOrObject classOrObject = KtPsiUtilKt.getContainingClassOrObject(this);
if (classOrObject != null) {
scope = scope.intersectWith(classOrObject.getUseScope());
}
return scope;
}
use of com.intellij.psi.search.SearchScope in project oxy-template-support-plugin by mutant-industries.
the class GlobalVariableReferenceSearch method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
if (!(queryParameters.getElementToSearch() instanceof GlobalVariableDefinition)) {
return;
}
final GlobalVariableDefinition target = (GlobalVariableDefinition) queryParameters.getElementToSearch();
SearchScope scope = restrictScopeToOxyTemplates(queryParameters.getEffectiveSearchScope());
queryParameters.getOptimizer().searchWord(target.getName(), scope, UsageSearchContext.IN_CODE, true, target.getExpression(), new RequestResultProcessor() {
@Override
public boolean processTextOccurrence(@NotNull PsiElement element, int offsetInElement, @NotNull Processor<PsiReference> consumer) {
PsiReference reference;
if (element instanceof JSReferenceExpression && (reference = element.getReference()) != null) {
PsiElement resolveResult = reference.resolve();
if (resolveResult instanceof GlobalVariableDefinition && target.getExpression().isEquivalentTo(((GlobalVariableDefinition) resolveResult).getExpression())) {
return consumer.process(reference);
}
}
return true;
}
});
}
use of com.intellij.psi.search.SearchScope in project oxy-template-support-plugin by mutant-industries.
the class JavaMacroReferenceSearch method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiElement target = queryParameters.getElementToSearch();
PsiClass psiClass;
if (!(target instanceof PsiClass) || !OxyTemplateIndexUtil.isMacro(psiClass = (PsiClass) target)) {
return;
}
SearchScope scope = restrictScopeToOxyTemplates(queryParameters.getEffectiveSearchScope());
assert psiClass.getName() != null;
final String query = StringUtil.decapitalize(psiClass.getName().replaceFirst(MacroIndex.JAVA_MACRO_SUFFIX + "$", ""));
queryParameters.getOptimizer().searchWord(query, scope, UsageSearchContext.IN_CODE, true, target);
}
use of com.intellij.psi.search.SearchScope in project oxy-template-support-plugin by mutant-industries.
the class JavaGetterReferenceSearch method doSearch.
static void doSearch(@NotNull final PsiMethod method, @NotNull final SearchRequestCollector optimizer, SearchScope effectiveSearchScope) {
if (!method.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) {
return;
}
String methodName = method.getName();
if (!methodName.matches("((^is)|(^get))[A-Z].*")) {
return;
}
String query = StringUtils.decapitalize(methodName.replaceFirst("(^is)|(^get)", ""));
SearchScope scope = OxyTemplateReferenceSearch.restrictScopeToOxyTemplates(effectiveSearchScope);
optimizer.searchWord(query, scope, UsageSearchContext.IN_CODE, true, method, new RequestResultProcessor() {
@Override
public boolean processTextOccurrence(@NotNull PsiElement element, int offsetInElement, @NotNull Processor<PsiReference> consumer) {
PsiElement reference;
return !((element instanceof JSReferenceExpression && (reference = ((JSReferenceExpression) element).resolve()) != null) && reference.isEquivalentTo(method)) || consumer.process((JSReferenceExpression) element);
}
});
}
Aggregations