Search in sources :

Example 1 with ForStatement

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

the class ResolveUtil method searchInScope.

/**
 * Walks up PSI tree of local file, checking PsiNamedElements
 */
public static void searchInScope(PsiElement originalElement, Processor<BuildElement> processor) {
    // TODO: Handle list comprehension (where variable is defined *later* in the code)
    boolean topLevelScope = true;
    PsiElement element = originalElement;
    while (!(element instanceof PsiFileSystemItem)) {
        PsiElement parent = element.getParent();
        if (parent instanceof BuildFile) {
            if (!((BuildFile) parent).searchSymbolsInScope(processor, topLevelScope ? element : null)) {
                return;
            }
        } else if (parent instanceof FunctionStatement) {
            topLevelScope = false;
            for (Parameter param : ((FunctionStatement) parent).getParameters()) {
                if (!processor.process(param)) {
                    return;
                }
            }
        } else if (parent instanceof ForStatement) {
            for (Expression expr : ((ForStatement) parent).getForLoopVariables()) {
                if (expr instanceof TargetExpression && !processor.process(expr)) {
                    return;
                }
            }
        } else if (parent instanceof StatementList) {
            if (!visitChildAssignmentStatements((BuildElement) parent, (Processor) processor)) {
                return;
            }
        }
        element = parent;
    }
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) Expression(com.google.idea.blaze.base.lang.buildfile.psi.Expression) StatementList(com.google.idea.blaze.base.lang.buildfile.psi.StatementList) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ForStatement(com.google.idea.blaze.base.lang.buildfile.psi.ForStatement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 ForStatement (com.google.idea.blaze.base.lang.buildfile.psi.ForStatement)1 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)1 Parameter (com.google.idea.blaze.base.lang.buildfile.psi.Parameter)1 StatementList (com.google.idea.blaze.base.lang.buildfile.psi.StatementList)1 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1