Search in sources :

Example 36 with FuncallExpression

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

Example 37 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression 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);
}
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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 38 with FuncallExpression

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

the class LocalReferenceTest method testReferenceInsideFuncallExpression.

@Test
public void testReferenceInsideFuncallExpression() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "a.function(c)");
    TargetExpression target = file.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
    FuncallExpression funcall = file.findChildByClass(FuncallExpression.class);
    ReferenceExpression ref = funcall.firstChildOfClass(ReferenceExpression.class);
    assertThat(ref.getReferencedElement()).isEqualTo(target);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 39 with FuncallExpression

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

the class LocalReferenceTest method testTargetInOuterScope.

@Test
public void testTargetInOuterScope() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "function(c = a)");
    TargetExpression target = file.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
    FuncallExpression funcall = file.findChildByClass(FuncallExpression.class);
    ReferenceExpression ref = funcall.getKeywordArgument("c").firstChildOfClass(ReferenceExpression.class);
    assertThat(ref.getReferencedElement()).isEqualTo(target);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 40 with FuncallExpression

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

the class ProjectViewLabelReferenceTest method testTargetReference.

@Test
public void testTargetReference() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("foo/bar/BUILD"), "java_library(", "    name = 'lib',", ")");
    PsiFile projectView = workspace.createPsiFile(new WorkspacePath(".bazelproject"), "targets:", "  //foo/bar:lib");
    FuncallExpression target = ((BuildFile) buildFile).findRule("lib");
    ProjectViewPsiSectionItem importItem = PsiUtils.findFirstChildOfClassRecursive(projectView, ProjectViewPsiSectionItem.class);
    assertThat(importItem).isNotNull();
    assertThat(importItem.getReference().resolve()).isEqualTo(target);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) ProjectViewPsiSectionItem(com.google.idea.blaze.base.lang.projectview.psi.ProjectViewPsiSectionItem) PsiFile(com.intellij.psi.PsiFile) 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