Search in sources :

Example 6 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class PackageReferenceTest method testLabelFragmentResolves.

@Test
public void testLabelFragmentResolves() {
    BuildFile buildFile1 = createBuildFile(new WorkspacePath("java/com/google/tools/BUILD"), "java_library(name = \"lib\")");
    BuildFile buildFile2 = createBuildFile(new WorkspacePath("java/com/google/other/BUILD"), "java_library(name = \"lib2\", exports = [\"//java/com/google/tools:lib\"])");
    FuncallExpression libTarget = buildFile1.firstChildOfClass(FuncallExpression.class);
    assertThat(libTarget).isNotNull();
    Argument.Keyword packagesArg = buildFile2.firstChildOfClass(FuncallExpression.class).getArgList().getKeywordArgument("exports");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(packagesArg, StringLiteral.class);
    PsiReference[] references = string.getReferences();
    assertThat(Arrays.stream(references).map(PsiReference::resolve).collect(Collectors.toList())).containsAllOf(libTarget, buildFile1);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 7 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression 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 8 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression 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)

Example 9 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class ExternalWorkspaceReferenceTest method testFileReferenceWithinExternalWorkspaceResolves.

@Test
public void testFileReferenceWithinExternalWorkspaceResolves() {
    BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'target',", "    jars = ['junit-4.11.jar'],", ")");
    PsiFile jarFile = createFileInExternalWorkspace("junit", new WorkspacePath("junit-4.11.jar"));
    FuncallExpression target = externalFile.findRule("target");
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(target.getKeywordArgument("jars"), StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(jarFile);
}
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) PsiFile(com.intellij.psi.PsiFile) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 10 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class ExternalWorkspaceReferenceTest method testExternalWorkspaceTargetReference.

@Test
public void testExternalWorkspaceTargetReference() {
    BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("BUILD"), "java_library(", "    name = 'lib',", "    exports = ['@junit//:jar'],", ")");
    BuildFile externalBuildFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'jar',", "    jars = ['junit-4.11.jar'],", ")");
    FuncallExpression target = externalBuildFile.findRule("jar");
    assertThat(target).isNotNull();
    Argument.Keyword arg = workspaceBuildFile.findRule("lib").getKeywordArgument("exports");
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(arg, 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) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) 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

FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)44 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)33 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)32 Test (org.junit.Test)32 PsiElement (com.intellij.psi.PsiElement)13 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)10 PsiReference (com.intellij.psi.PsiReference)10 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)7 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)6 PsiFile (com.intellij.psi.PsiFile)6 Nullable (javax.annotation.Nullable)5 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)4 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)2 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2