use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameLoadedFunction.
@Test
public void testRenameLoadedFunction() {
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);
testFixture.renameElement(fn, "action");
assertFileContents(extFile, "def action(name, deps)");
assertFileContents(buildFile, "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"action\"", ")", "action(name = \"name\", deps = []");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testMultipleImportedFunctions.
@Test
public void testMultipleImportedFunctions() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def fn1(name, deps)", "def fn2(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google:build_defs.bzl\",", "\"fn1\"", "\"fn2\"", ")");
LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
assertThat(load.getImportPsiElement().getReferencedElement()).isEqualTo(extFile);
FunctionStatement[] functions = extFile.childrenOfClass(FunctionStatement.class);
assertThat(functions).hasLength(2);
assertThat(load.getImportedFunctionReferences()).isEqualTo(functions);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testRelativePathInSubdirectory.
// relative paths in skylark extensions which lie in subdirectories
// are relative to the parent blaze package directory
@Test
public void testRelativePathInSubdirectory() {
workspace.createFile(new WorkspacePath("java/com/google/BUILD"));
BuildFile referencedFile = createBuildFile(new WorkspacePath("java/com/google/nonPackageSubdirectory/skylark.bzl"), "def function(): return");
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/nonPackageSubdirectory/other.bzl"), "load(" + " ':nonPackageSubdirectory/skylark.bzl',", " 'function',", ")", "function()");
FunctionStatement function = referencedFile.firstChildOfClass(FunctionStatement.class);
FuncallExpression funcall = file.firstChildOfClass(FuncallExpression.class);
assertThat(function).isNotNull();
assertThat(funcall.getReferencedElement()).isEqualTo(function);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testStandardLoadReference.
@Test
public void testStandardLoadReference() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google:build_defs.bzl\",", "\"function\"", ")");
LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
assertThat(load.getImportPsiElement().getReferencedElement()).isEqualTo(extFile);
FunctionStatement function = extFile.firstChildOfClass(FunctionStatement.class);
assertThat(function).isNotNull();
assertThat(load.getImportedSymbolElements()).hasLength(1);
assertThat(load.getImportedSymbolElements()[0].getLoadedElement()).isEqualTo(function);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testFuncallReference.
@Test
public void testFuncallReference() {
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 function = extFile.firstChildOfClass(FunctionStatement.class);
FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
assertThat(function).isNotNull();
assertThat(funcall.getReferencedElement()).isEqualTo(function);
}
Aggregations