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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations