Search in sources :

Example 41 with BuildFile

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\"");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 42 with BuildFile

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\"]");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) Test(org.junit.Test)

Example 43 with BuildFile

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");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) Test(org.junit.Test)

Example 44 with BuildFile

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 = []");
}
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) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) Test(org.junit.Test)

Example 45 with BuildFile

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);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Aggregations

BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)216 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)197 Test (org.junit.Test)196 Editor (com.intellij.openapi.editor.Editor)46 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)37 PsiReference (com.intellij.psi.PsiReference)32 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)27 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)18 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)17 GlobExpression (com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression)16 LookupElement (com.intellij.codeInsight.lookup.LookupElement)13 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)10 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)8 Nullable (javax.annotation.Nullable)8 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)7 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)6 LoadStatement (com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement)6 PsiDirectory (com.intellij.psi.PsiDirectory)6 Label (com.google.idea.blaze.base.model.primitives.Label)5