use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameRule.
@Test
public void testRenameRule() {
BuildFile fooPackage = createBuildFile(new WorkspacePath("com/google/foo/BUILD"), "rule_type(name = \"target\")", "java_library(name = \"local_ref\", srcs = [\":target\"])");
BuildFile barPackage = createBuildFile(new WorkspacePath("com/google/test/bar/BUILD"), "rule_type(name = \"ref\", arg = \"//com/google/foo:target\")", "top_level_ref = \"//com/google/foo:target\"");
FuncallExpression targetRule = PsiUtils.findFirstChildOfClassRecursive(fooPackage, FuncallExpression.class);
testFixture.renameElement(targetRule, "newTargetName");
assertFileContents(fooPackage, "rule_type(name = \"newTargetName\")", "java_library(name = \"local_ref\", srcs = [\":newTargetName\"])");
assertFileContents(barPackage, "rule_type(name = \"ref\", arg = \"//com/google/foo:newTargetName\")", "top_level_ref = \"//com/google/foo:newTargetName\"");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameDirectory.
// all references, including path fragments in labels, should be renamed.
@Test
public void testRenameDirectory() {
createBuildFile(new WorkspacePath("java/com/baz/BUILD"));
createBuildFile(new WorkspacePath("java/com/google/tools/BUILD"));
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", deps = [\"//java/com/baz:target\"]");
renameDirectory(new WorkspacePath("java/com"), new WorkspacePath("java/alt"));
assertFileContents(buildFile, "load(", "\"//java/alt/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", deps = [\"//java/alt/baz:target\"]");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameLocalVariable.
@Test
public void testRenameLocalVariable() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "c = a");
TargetExpression target = PsiUtils.findFirstChildOfClassRecursive(file, TargetExpression.class);
assertThat(target.getText()).isEqualTo("a");
testFixture.renameElement(target, "b");
assertFileContents(file, "b = 1", "c = b");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile 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.BuildFile in project intellij by bazelbuild.
the class ExternalWorkspaceReferenceTest method testReferenceToWorkspaceFileContents.
@Test
public void testReferenceToWorkspaceFileContents() {
BuildFile workspaceFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", " name = 'w3c_css_sac',", " artifact = 'org.w3c.css:sac:1.3',", " sha1 = 'cdb2dcb4e22b83d6b32b93095f644c3462739e82',", ")");
BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/pkg/BUILD"), "rule(", " name = 'other',", " dep = '@w3c_css_sac//jar'", ")");
FuncallExpression target = workspaceFile.findRule("w3c_css_sac");
assertThat(target).isNotNull();
FuncallExpression other = referencingFile.findRule("other");
StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(other.getKeywordArgument("dep"), StringLiteral.class);
assertThat(label.getReferencedElement()).isEqualTo(target);
}
Aggregations