use of com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement 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.LoadStatement in project intellij by bazelbuild.
the class BuildParserTest method testLoadWithAlias.
@Test
public void testLoadWithAlias() throws Exception {
ASTNode tree = createAST("load('file', 'foo', baz = 'bar',)\n");
List<LoadStatement> stmts = getTopLevelNodesOfType(tree, LoadStatement.class);
assertThat(stmts).hasSize(1);
LoadStatement stmt = stmts.get(0);
assertThat(stmt.getImportedPath()).isEqualTo("file");
assertThat(stmt.getVisibleSymbolNames()).isEqualTo(new String[] { "foo", "baz" });
assertNoErrors();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement in project intellij by bazelbuild.
the class BuildParserTest method testLoad.
@Test
public void testLoad() throws Exception {
ASTNode tree = createAST("load('file', 'foo', 'bar',)\n");
List<LoadStatement> stmts = getTopLevelNodesOfType(tree, LoadStatement.class);
assertThat(stmts).hasSize(1);
LoadStatement stmt = stmts.get(0);
assertThat(stmt.getImportedPath()).isEqualTo("file");
assertThat(stmt.getVisibleSymbolNames()).isEqualTo(new String[] { "foo", "bar" });
assertNoErrors();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement in project intellij by bazelbuild.
the class FunctionStatementUsagesTest method testLoadedFunctionReferences.
@Test
public void testLoadedFunctionReferences() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google:build_defs.bzl\",", "\"function\"", ")");
FunctionStatement funcDef = extFile.findChildByClass(FunctionStatement.class);
LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
PsiReference[] references = FindUsages.findAllReferences(funcDef);
assertThat(references).hasLength(1);
PsiElement ref = references[0].getElement();
assertThat(ref).isInstanceOf(StringLiteral.class);
assertThat(ref.getParent().getParent()).isEqualTo(load);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement in project intellij by bazelbuild.
the class BuildFileFoldingBuilder method getPlaceholderText.
@Override
@Nullable
public String getPlaceholderText(ASTNode node) {
PsiElement psi = node.getPsi();
if (psi instanceof FuncallExpression) {
FuncallExpression expr = (FuncallExpression) psi;
String name = expr.getNameArgumentValue();
if (name != null) {
return "name = \"" + name + "\"...";
}
}
if (psi instanceof LoadStatement) {
String fileName = ((LoadStatement) psi).getImportedPath();
if (fileName != null) {
return "\"" + fileName + "\"...";
}
}
return "...";
}
Aggregations