use of com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList in project intellij by bazelbuild.
the class KeywordReferenceTest method testKwargsReference.
@Test
public void testKwargsReference() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, **kwargs)", "function(name = \"name\", deps = [])");
ArgumentList args = file.firstChildOfClass(FuncallExpression.class).getArgList();
assertThat(args.getKeywordArgument("deps").getReferencedElement()).isInstanceOf(Parameter.StarStar.class);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList in project intellij by bazelbuild.
the class BuildTargetElementEvaluator method getParentFuncallIfNameString.
@Nullable
private static FuncallExpression getParentFuncallIfNameString(PsiElement element) {
PsiElement parent = element.getParent();
if (!(parent instanceof StringLiteral)) {
return null;
}
parent = parent.getParent();
if (!(parent instanceof Keyword)) {
return null;
}
if (!Objects.equals(((Keyword) parent).getName(), "name")) {
return null;
}
parent = parent.getParent();
if (!(parent instanceof ArgumentList)) {
return null;
}
parent = parent.getParent();
return parent instanceof FuncallExpression ? (FuncallExpression) parent : null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList in project intellij by bazelbuild.
the class JavaClassQualifiedNameReferenceTest method testReferencesJavaClass.
@Test
public void testReferencesJavaClass() {
PsiFile javaFile = workspace.createPsiFile(new WorkspacePath("java/com/google/bin/Main.java"), "package com.google.bin;", "public class Main {", " public void main() {}", "}");
PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "java_binary(", " name = 'binary',", " main_class = 'com.google.bin.Main',", ")");
ArgumentList args = file.firstChildOfClass(FuncallExpression.class).getArgList();
assertThat(args.getKeywordArgument("main_class").getValue().getReferencedElement()).isEqualTo(javaClass);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList in project intellij by bazelbuild.
the class KeywordReferenceTest method testPlainKeywordReference.
@Test
public void testPlainKeywordReference() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, deps)", "function(name = \"name\", deps = [])");
ParameterList params = file.firstChildOfClass(FunctionStatement.class).getParameterList();
assertThat(params.getElements()).hasLength(2);
ArgumentList args = file.firstChildOfClass(FuncallExpression.class).getArgList();
assertThat(args.getKeywordArgument("name").getReferencedElement()).isEqualTo(params.findParameterByName("name"));
assertThat(args.getKeywordArgument("deps").getReferencedElement()).isEqualTo(params.findParameterByName("deps"));
}
Aggregations