use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testPackageLocalImportLabelFormat.
// TODO: If we want to support this deprecated format,
// we should start by relaxing the ":" requirement in Label
// public void testDeprecatedImportLabelFormat() {
// BuildFile extFile = createBuildFile(
// "java/com/google/build_defs.bzl",
// "def function(name, deps)");
//
// BuildFile buildFile = createBuildFile(
// "java/com/google/tools/BUILD",
// "load(",
// "\"/java/com/google/build_defs.bzl\",",
// "\"function\"",
// ")");
//
// LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
// assertThat(load.getImportPsiElement().getReferencedElement()).isEqualTo(extFile);
// }
@Test
public void testPackageLocalImportLabelFormat() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/tools/BUILD"), "load(", "\":build_defs.bzl\",", "\"function\"", ")");
LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
assertThat(load.getImportPsiElement().getReferencedElement()).isEqualTo(extFile);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testLoadedSymbolReference.
@Test
public void testLoadedSymbolReference() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "CONSTANT = 1");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"CONSTANT\"", ")", "NEW_CONSTANT = CONSTANT");
TargetExpression target = PsiUtils.findFirstChildOfClassRecursive(extFile, TargetExpression.class);
ReferenceExpression ref = PsiUtils.findFirstChildOfClassRecursive(buildFile, ReferenceExpression.class);
LoadedSymbol loadElement = PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);
assertThat(target).isNotNull();
assertThat(ref.getReferencedElement()).isEqualTo(target);
assertThat(loadElement.getImport().getReferencedElement()).isEqualTo(target);
assertThat(Arrays.stream(FindUsages.findAllReferences(target)).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(ref, loadElement.getImport());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class LocalReferenceTest method testReferenceToFunctionArg.
@Test
public void testReferenceToFunctionArg() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/defs.bzl"), "def function(arg1, arg2):", " arg1(arg2)");
FunctionStatement def = file.findFunctionInScope("function");
FuncallExpression call = PsiUtils.findFirstChildOfClassRecursive(file, FuncallExpression.class);
Parameter fnParam = def.getParameterList().findParameterByName("arg1");
assertThat(fnParam).isNotNull();
assertThat(call.getReference().resolve()).isEqualTo(fnParam);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile 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);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class PackageReferenceTest method testDirectReferenceResolves.
@Test
public void testDirectReferenceResolves() {
BuildFile buildFile1 = createBuildFile(new WorkspacePath("java/com/google/tools/BUILD"), "# contents");
BuildFile buildFile2 = createBuildFile(new WorkspacePath("java/com/google/other/BUILD"), "package_group(name = \"grp\", packages = [\"//java/com/google/tools\"])");
Argument.Keyword packagesArg = buildFile2.firstChildOfClass(FuncallExpression.class).getArgList().getKeywordArgument("packages");
StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(packagesArg, StringLiteral.class);
assertThat(string.getReferencedElement()).isEqualTo(buildFile1);
}
Aggregations