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;
}
}
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);
}
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);
}
Aggregations