Search in sources :

Example 31 with FuncallExpression

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

the class ExternalWorkspaceReferenceTest method testLocalTargetReferenceWithinExternalWorkspaceResolves.

@Test
public void testLocalTargetReferenceWithinExternalWorkspaceResolves() {
    BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'jar',", "    jars = ['junit-4.11.jar'],", ")", "java_library(", "    name = 'lib',", "    srcs = [':jar'],", ")");
    FuncallExpression target = externalFile.findRule("jar");
    assertThat(target).isNotNull();
    Argument.Keyword arg = externalFile.findRule("lib").getKeywordArgument("srcs");
    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)

Example 32 with FuncallExpression

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

the class LabelReferenceTest method testTargetInAnotherPackageResolves.

@Test
public void testTargetInAnotherPackageResolves() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "rule(name = \"target\")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "rule(name = \"other\", dep = \"//java/com/google/foo:target\")");
    FuncallExpression target = targetFile.findRule("target");
    assertThat(target).isNotNull();
    Argument.Keyword depArgument = referencingFile.findRule("other").getKeywordArgument("dep");
    assertThat(depArgument.getValue().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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 33 with FuncallExpression

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

the class LabelReferenceTest method testAbsoluteLabelInSkylarkExtension.

@Test
public void testAbsoluteLabelInSkylarkExtension() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "rule(name = \"foo\")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/foo/skylark.bzl"), "LIST = ['//java/com/google/foo:foo']");
    FuncallExpression target = targetFile.findRule("foo");
    assertThat(target).isNotNull();
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(referencingFile, 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 34 with FuncallExpression

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

the class LabelReferenceTest method testLabelWithImplicitRuleName.

@Test
public void testLabelWithImplicitRuleName() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "rule(name = \"foo\")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "rule(name = \"other\", dep = \"//java/com/google/foo\")");
    FuncallExpression target = targetFile.findRule("foo");
    assertThat(target).isNotNull();
    Argument.Keyword depArgument = referencingFile.findRule("other").getKeywordArgument("dep");
    assertThat(depArgument.getValue().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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 35 with FuncallExpression

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

the class LabelReferenceTest method testLocalRuleReference.

@Test
public void testLocalRuleReference() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "java_library(name = \"lib\")", "java_library(name = \"foo\", deps = [\":lib\"])", "java_library(name = \"bar\", deps = [\"//java/com/google:lib\"])");
    FuncallExpression lib = file.findRule("lib");
    FuncallExpression foo = file.findRule("foo");
    FuncallExpression bar = file.findRule("bar");
    assertThat(lib).isNotNull();
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(foo.getKeywordArgument("deps"), StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(lib);
    label = PsiUtils.findFirstChildOfClassRecursive(bar.getKeywordArgument("deps"), StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(lib);
}
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

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