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