Search in sources :

Example 1 with NamedBuildElement

use of com.google.idea.blaze.base.lang.buildfile.psi.NamedBuildElement in project intellij by bazelbuild.

the class BuildReferenceSearcher method processQuery.

@Override
public void processQuery(SearchParameters params, Processor<PsiReference> consumer) {
    PsiElement element = params.getElementToSearch();
    if (element instanceof NamedBuildElement) {
        String fnName = ((NamedBuildElement) element).getName();
        if (fnName != null) {
            searchForString(params, element, fnName);
        }
        return;
    }
    PsiFile file = ResolveUtil.asFileSearch(element);
    if (file != null) {
        processFileReferences(params, file);
        return;
    }
    if (!(element instanceof FuncallExpression)) {
        return;
    }
    FuncallExpression funcall = (FuncallExpression) element;
    PsiFile localFile = element.getContainingFile();
    if (localFile == null) {
        return;
    }
    Label label = funcall.resolveBuildLabel();
    if (label == null) {
        searchForExternalWorkspace(params, localFile, funcall);
        return;
    }
    List<String> stringsToSearch = LabelUtils.getAllValidLabelStrings(label, true);
    for (String string : stringsToSearch) {
        if (LabelUtils.isAbsolute(string)) {
            searchForString(params, element, string);
        } else {
            // only a valid reference from local package -- restrict the search scope accordingly
            SearchScope scope = limitScopeToFile(params.getScopeDeterminedByUser(), localFile);
            if (scope != null) {
                searchForString(params, scope, element, string);
            }
        }
    }
}
Also used : NamedBuildElement(com.google.idea.blaze.base.lang.buildfile.psi.NamedBuildElement) Label(com.google.idea.blaze.base.model.primitives.Label) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiFile(com.intellij.psi.PsiFile) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)1 NamedBuildElement (com.google.idea.blaze.base.lang.buildfile.psi.NamedBuildElement)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 SearchScope (com.intellij.psi.search.SearchScope)1