Search in sources :

Example 1 with ParameterList

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

the class FindParameterUsagesTest method testLocalReferences.

@Test
public void testLocalReferences() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(arg1, arg2)", "function(arg1 = 1, arg2 = \"name\")");
    FunctionStatement fn = buildFile.findChildByClass(FunctionStatement.class);
    ParameterList params = fn.getParameterList();
    PsiReference[] references = FindUsages.findAllReferences(params.findParameterByName("arg1"));
    assertThat(references).hasLength(1);
    references = FindUsages.findAllReferences(params.findParameterByName("arg2"));
    assertThat(references).hasLength(1);
}
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) PsiReference(com.intellij.psi.PsiReference) Test(org.junit.Test)

Example 2 with ParameterList

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

the class FindParameterUsagesTest method testNonLocalReferences.

@Test
public void testNonLocalReferences() {
    BuildFile foo = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(arg1, arg2)");
    BuildFile bar = createBuildFile(new WorkspacePath("java/com/google/other/BUILD"), "load(\"//java/com/google:build_defs.bzl\", \"function\")", "function(arg1 = 1, arg2 = \"name\", extra = x)");
    FunctionStatement fn = foo.findChildByClass(FunctionStatement.class);
    ParameterList params = fn.getParameterList();
    PsiReference[] references = FindUsages.findAllReferences(params.findParameterByName("arg1"));
    assertThat(references).hasLength(1);
    assertThat(references[0].getElement().getContainingFile()).isEqualTo(bar);
    references = FindUsages.findAllReferences(params.findParameterByName("arg2"));
    assertThat(references).hasLength(1);
    assertThat(references[0].getElement().getContainingFile()).isEqualTo(bar);
}
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) PsiReference(com.intellij.psi.PsiReference) Test(org.junit.Test)

Example 3 with ParameterList

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

Example 4 with ParameterList

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

the class BuildDocumentationProvider method describeFunction.

private static void describeFunction(FunctionStatement function, StringBuilder builder) {
    // just show the function declaration verbatim, including the parameter list.
    ParameterList paramList = function.getParameterList();
    if (paramList == null) {
        return;
    }
    builder.append("def ").append("<b>").append(function.getName()).append("</b>").append(paramList.getNode().getChars()).append("<br><br>");
}
Also used : ParameterList(com.google.idea.blaze.base.lang.buildfile.psi.ParameterList)

Aggregations

ParameterList (com.google.idea.blaze.base.lang.buildfile.psi.ParameterList)4 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)3 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)3 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)3 Test (org.junit.Test)3 PsiReference (com.intellij.psi.PsiReference)2 ArgumentList (com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList)1 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)1