Search in sources :

Example 1 with LoadStatement

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

Example 2 with LoadStatement

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();
}
Also used : LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) Test(org.junit.Test)

Example 3 with LoadStatement

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();
}
Also used : LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) Test(org.junit.Test)

Example 4 with LoadStatement

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);
}
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) LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 5 with LoadStatement

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 "...";
}
Also used : LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Aggregations

LoadStatement (com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement)7 Test (org.junit.Test)6 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)3 ASTNode (com.intellij.lang.ASTNode)2 FileASTNode (com.intellij.lang.FileASTNode)2 PsiElement (com.intellij.psi.PsiElement)2 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)1 PsiReference (com.intellij.psi.PsiReference)1 Nullable (javax.annotation.Nullable)1