Search in sources :

Example 76 with BuildFile

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

the class GlobFindUsagesTest method testGlobWithExcludes.

@Test
public void testGlobWithExcludes() {
    PsiFile test = workspace.createPsiFile(new WorkspacePath("java/com/google/tests/Test.java"));
    PsiFile foo = workspace.createPsiFile(new WorkspacePath("java/com/google/Foo.java"));
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(" + "  ['**/*.java']," + "  exclude = ['tests/*.java'])");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    PsiReference[] references = FindUsages.findAllReferences(foo);
    assertThat(references).hasLength(1);
    assertThat(references[0].getElement()).isEqualTo(glob);
    assertThat(FindUsages.findAllReferences(test)).isEmpty();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) Test(org.junit.Test)

Example 77 with BuildFile

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

the class GlobFindUsagesTest method testSimpleGlobReferencingSingleFile2.

@Test
public void testSimpleGlobReferencingSingleFile2() {
    PsiFile ref = workspace.createPsiFile(new WorkspacePath("java/com/google/Test.java"));
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['*.java'])");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    PsiReference[] references = FindUsages.findAllReferences(ref);
    assertThat(references).hasLength(1);
    assertThat(references[0].getElement()).isEqualTo(glob);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) Test(org.junit.Test)

Example 78 with BuildFile

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

the class BuildFileFoldingBuilderTest method testEndOfFileFunctionDelcaration.

@Test
public void testEndOfFileFunctionDelcaration() {
    // bug 28618935: test no NPE in the case where there's no
    // statement list following the func-def colon
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "def function():");
    getFoldingRegions(file);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Test(org.junit.Test)

Example 79 with BuildFile

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

the class ArgumentCompletionContributorTest method testExistingKeywordArg.

@Test
public void testExistingKeywordArg() {
    completionTester.runWithAutoPopupEnabled(() -> {
        BuildFile file = createBuildFile(new WorkspacePath("BUILD"), "def function(name, deps, srcs):", "  # empty function", "function(name = \"lib\")");
        Editor editor = editorTest.openFileInEditor(file.getVirtualFile());
        editorTest.setCaretPosition(editor, 2, "function(".length());
        String[] completionItems = editorTest.getCompletionItemsAsStrings();
        assertThat(completionItems).asList().containsAllOf("name", "deps", "srcs", "function");
    });
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Editor(com.intellij.openapi.editor.Editor) Test(org.junit.Test)

Example 80 with BuildFile

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

the class BuildLabelAutoCompletionTest method testPopupAutocompleteAfterColon.

@Test
public void testPopupAutocompleteAfterColon() {
    completionTester.runWithAutoPopupEnabled(() -> {
        createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = 'target')");
        BuildFile file = createBuildFile(new WorkspacePath("BUILD"), "java_library(", "    name = 'lib',", "    srcs = ['//java/com/foo'],");
        Editor editor = editorTest.openFileInEditor(file.getVirtualFile());
        editorTest.setCaretPosition(editor, 2, "    srcs = ['//java/com/foo".length());
        completionTester.typeWithPauses(":");
        assertThat(currentLookupStrings()).containsExactly("'//java/com/foo:target'");
    });
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) Editor(com.intellij.openapi.editor.Editor) Test(org.junit.Test)

Aggregations

BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)216 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)197 Test (org.junit.Test)196 Editor (com.intellij.openapi.editor.Editor)46 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)37 PsiReference (com.intellij.psi.PsiReference)32 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)27 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)18 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)17 GlobExpression (com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression)16 LookupElement (com.intellij.codeInsight.lookup.LookupElement)13 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)10 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)8 Nullable (javax.annotation.Nullable)8 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)7 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)6 LoadStatement (com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement)6 PsiDirectory (com.intellij.psi.PsiDirectory)6 Label (com.google.idea.blaze.base.model.primitives.Label)5