Search in sources :

Example 16 with FunctionStatement

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

the class RenameRefactoringTest method testRenameLoadedFunction.

@Test
public void testRenameLoadedFunction() {
    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 fn = extFile.findChildByClass(FunctionStatement.class);
    testFixture.renameElement(fn, "action");
    assertFileContents(extFile, "def action(name, deps)");
    assertFileContents(buildFile, "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"action\"", ")", "action(name = \"name\", deps = []");
}
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) Test(org.junit.Test)

Example 17 with FunctionStatement

use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement 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 18 with FunctionStatement

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

Example 19 with FunctionStatement

use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement 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)

Example 20 with FunctionStatement

use of com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement 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);
}
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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Aggregations

FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)20 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)16 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)14 Test (org.junit.Test)14 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)6 PsiElement (com.intellij.psi.PsiElement)6 PsiReference (com.intellij.psi.PsiReference)6 Parameter (com.google.idea.blaze.base.lang.buildfile.psi.Parameter)5 LoadStatement (com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement)3 ParameterList (com.google.idea.blaze.base.lang.buildfile.psi.ParameterList)2 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)2 Nullable (javax.annotation.Nullable)2 NamedBuildLookupElement (com.google.idea.blaze.base.lang.buildfile.completion.NamedBuildLookupElement)1 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 ForStatement (com.google.idea.blaze.base.lang.buildfile.psi.ForStatement)1 StatementList (com.google.idea.blaze.base.lang.buildfile.psi.StatementList)1 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 Annotation (com.intellij.lang.annotation.Annotation)1