Search in sources :

Example 1 with RequestResultProcessor

use of com.intellij.psi.search.RequestResultProcessor in project oxy-template-support-plugin by mutant-industries.

the class DwrMethodReferenceSearch method processQuery.

@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    PsiMethod method = queryParameters.getMethod();
    if (!method.getModifierList().hasModifierProperty(PsiModifier.PUBLIC) || !DwrReferenceResolver.isDwrMethod(method)) {
        return;
    }
    String query = method.getName();
    SearchScope scope = queryParameters.getEffectiveSearchScope();
    if (scope instanceof GlobalSearchScope) {
        // intersect(union(original scope, js file type scope), not(java file type scope))
        GlobalSearchScope jsFilesScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(method.getProject()), JavaScriptFileType.INSTANCE);
        scope = jsFilesScope.uniteWith((GlobalSearchScope) scope).intersectWith(GlobalSearchScope.notScope(GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(method.getProject()), JavaFileType.INSTANCE)));
    }
    queryParameters.getOptimizer().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);
        }
    });
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) PsiMethod(com.intellij.psi.PsiMethod) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) RequestResultProcessor(com.intellij.psi.search.RequestResultProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 2 with RequestResultProcessor

use of com.intellij.psi.search.RequestResultProcessor 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;
        }
    });
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) GlobalVariableDefinition(ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition) SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) RequestResultProcessor(com.intellij.psi.search.RequestResultProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 3 with RequestResultProcessor

use of com.intellij.psi.search.RequestResultProcessor 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);
        }
    });
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) RequestResultProcessor(com.intellij.psi.search.RequestResultProcessor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 PsiElement (com.intellij.psi.PsiElement)3 PsiReference (com.intellij.psi.PsiReference)3 RequestResultProcessor (com.intellij.psi.search.RequestResultProcessor)3 SearchScope (com.intellij.psi.search.SearchScope)3 PsiMethod (com.intellij.psi.PsiMethod)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 GlobalVariableDefinition (ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition)1