use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class LocalReferenceTest method testReferenceToFunctionArg.
@Test
public void testReferenceToFunctionArg() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/defs.bzl"), "def function(arg1, arg2):", " arg1(arg2)");
FunctionStatement def = file.findFunctionInScope("function");
FuncallExpression call = PsiUtils.findFirstChildOfClassRecursive(file, FuncallExpression.class);
Parameter fnParam = def.getParameterList().findParameterByName("arg1");
assertThat(fnParam).isNotNull();
assertThat(call.getReference().resolve()).isEqualTo(fnParam);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameFunctionParameter.
@Test
public void testRenameFunctionParameter() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", deps = []");
FunctionStatement fn = extFile.findChildByClass(FunctionStatement.class);
Parameter param = fn.getParameterList().findParameterByName("deps");
testFixture.renameElement(param, "exports");
assertFileContents(extFile, "def function(name, exports)");
assertFileContents(buildFile, "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", exports = []");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement 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.FunctionStatement in project intellij by bazelbuild.
the class FunctionStatementUsagesTest method testLocalReferences.
@Test
public void testLocalReferences() {
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, srcs, deps):", " # function body", "function(name = \"foo\")");
FunctionStatement funcDef = buildFile.findChildByClass(FunctionStatement.class);
PsiReference[] references = FindUsages.findAllReferences(funcDef);
assertThat(references).hasLength(1);
PsiElement ref = references[0].getElement();
assertThat(ref).isInstanceOf(FuncallExpression.class);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class ArgumentReference method resolveFunction.
@Nullable
protected FunctionStatement resolveFunction() {
FuncallExpression call = PsiTreeUtil.getParentOfType(myElement, FuncallExpression.class);
if (call == null) {
return null;
}
PsiElement callee = call.getReferencedElement();
return callee instanceof FunctionStatement ? (FunctionStatement) callee : null;
}
Aggregations