use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class LocalVariableUsagesTest method testLocalReferences.
@Test
public void testLocalReferences() {
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "localVar = 5", "funcall(localVar)", "def function(name):", " tempVar = localVar");
TargetExpression target = buildFile.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(2);
FuncallExpression funcall = buildFile.findChildByClass(FuncallExpression.class);
assertThat(funcall).isNotNull();
PsiElement firstRef = references[0].getElement();
assertThat(PsiUtils.getParentOfType(firstRef, FuncallExpression.class, true)).isEqualTo(funcall);
FunctionStatement function = buildFile.findChildByClass(FunctionStatement.class);
assertThat(function).isNotNull();
PsiElement secondRef = references[1].getElement();
assertThat(secondRef.getParent()).isInstanceOf(AssignmentStatement.class);
assertThat(PsiUtils.getParentOfType(secondRef, FunctionStatement.class, true)).isEqualTo(function);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class ArgumentReference method getVariants.
@Override
public Object[] getVariants() {
FunctionStatement function = resolveFunction();
if (function == null) {
return EMPTY_ARRAY;
}
List<LookupElement> params = Lists.newArrayList();
for (Parameter param : function.getParameters()) {
params.add(new NamedBuildLookupElement(param, QuoteType.NoQuotes));
}
return params.toArray();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class HighlightingAnnotator method visitParameter.
@Override
public void visitParameter(Parameter node) {
FunctionStatement function = PsiTreeUtil.getParentOfType(node, FunctionStatement.class);
if (function != null) {
PsiElement anchor = node.hasDefaultValue() ? node.getFirstChild() : node;
final Annotation annotation = getHolder().createInfoAnnotation(anchor, null);
annotation.setTextAttributes(BuildSyntaxHighlighter.BUILD_PARAMETER);
}
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement 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.FunctionStatement in project intellij by bazelbuild.
the class RenameRefactoringTest method testFunctionRenameValidation.
@Test
public void testFunctionRenameValidation() {
BuildFile file = createBuildFile(new WorkspacePath("com/google/foo/BUILD"), "def fn_name():", " return");
FunctionStatement fn = PsiUtils.findFirstChildOfClassRecursive(file, FunctionStatement.class);
assertThat(RenameUtil.isValidName(getProject(), fn, "name-with-dash")).isFalse();
assertThat(RenameUtil.isValidName(getProject(), fn, "name:withColon")).isFalse();
assertThat(RenameUtil.isValidName(getProject(), fn, "return")).isFalse();
assertThat(RenameUtil.isValidName(getProject(), fn, "name_with_underscore")).isTrue();
}
Aggregations