Search in sources :

Example 6 with TargetExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression 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)

Example 7 with TargetExpression

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

the class LocalReferenceTest method testReferenceInsideFuncallExpression.

@Test
public void testReferenceInsideFuncallExpression() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "a.function(c)");
    TargetExpression target = file.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
    FuncallExpression funcall = file.findChildByClass(FuncallExpression.class);
    ReferenceExpression ref = funcall.firstChildOfClass(ReferenceExpression.class);
    assertThat(ref.getReferencedElement()).isEqualTo(target);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 8 with TargetExpression

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

the class LocalReferenceTest method testTargetInOuterScope.

@Test
public void testTargetInOuterScope() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "function(c = a)");
    TargetExpression target = file.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
    FuncallExpression funcall = file.findChildByClass(FuncallExpression.class);
    ReferenceExpression ref = funcall.getKeywordArgument("c").firstChildOfClass(ReferenceExpression.class);
    assertThat(ref.getReferencedElement()).isEqualTo(target);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Aggregations

BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)8 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)8 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)7 Test (org.junit.Test)7 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)4 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)4 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)3 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReference (com.intellij.psi.PsiReference)2 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 ForStatement (com.google.idea.blaze.base.lang.buildfile.psi.ForStatement)1 Parameter (com.google.idea.blaze.base.lang.buildfile.psi.Parameter)1 StatementList (com.google.idea.blaze.base.lang.buildfile.psi.StatementList)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1