Search in sources :

Example 1 with ArgumentList

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);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 2 with ArgumentList

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;
}
Also used : StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) Keyword(com.google.idea.blaze.base.lang.buildfile.psi.Argument.Keyword) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 3 with ArgumentList

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);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 4 with ArgumentList

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"));
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) ParameterList(com.google.idea.blaze.base.lang.buildfile.psi.ParameterList) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Aggregations

ArgumentList (com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList)4 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)4 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)3 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)3 Test (org.junit.Test)3 Keyword (com.google.idea.blaze.base.lang.buildfile.psi.Argument.Keyword)1 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)1 Parameter (com.google.idea.blaze.base.lang.buildfile.psi.Parameter)1 ParameterList (com.google.idea.blaze.base.lang.buildfile.psi.ParameterList)1 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 Nullable (javax.annotation.Nullable)1