Search in sources :

Example 6 with LoadStatement

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

the class LoadedSkylarkExtensionTest method testMultipleImportedFunctions.

@Test
public void testMultipleImportedFunctions() {
    BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def fn1(name, deps)", "def fn2(name, deps)");
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google:build_defs.bzl\",", "\"fn1\"", "\"fn2\"", ")");
    LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
    assertThat(load.getImportPsiElement().getReferencedElement()).isEqualTo(extFile);
    FunctionStatement[] functions = extFile.childrenOfClass(FunctionStatement.class);
    assertThat(functions).hasLength(2);
    assertThat(load.getImportedFunctionReferences()).isEqualTo(functions);
}
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) Test(org.junit.Test)

Example 7 with LoadStatement

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

the class LoadedSkylarkExtensionTest method testStandardLoadReference.

@Test
public void testStandardLoadReference() {
    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\"", ")");
    LoadStatement load = buildFile.firstChildOfClass(LoadStatement.class);
    assertThat(load.getImportPsiElement().getReferencedElement()).isEqualTo(extFile);
    FunctionStatement function = extFile.firstChildOfClass(FunctionStatement.class);
    assertThat(function).isNotNull();
    assertThat(load.getImportedSymbolElements()).hasLength(1);
    assertThat(load.getImportedSymbolElements()[0].getLoadedElement()).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) LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) Test(org.junit.Test)

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