Search in sources :

Example 1 with GlobExpression

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

the class GlobReferenceSearcher method processQuery.

@Override
public void processQuery(SearchParameters queryParameters, Processor<PsiReference> consumer) {
    PsiFileSystemItem file = ResolveUtil.asFileSystemItemSearch(queryParameters.getElementToSearch());
    if (file == null) {
        return;
    }
    BlazePackage containingPackage = BlazePackage.getContainingPackage(file);
    if (containingPackage == null || !inScope(queryParameters, containingPackage.buildFile)) {
        return;
    }
    String relativePath = containingPackage.getRelativePathToChild(file.getVirtualFile());
    if (relativePath == null) {
        return;
    }
    List<GlobExpression> globs = PsiUtils.findAllChildrenOfClassRecursive(containingPackage.buildFile, GlobExpression.class);
    for (GlobExpression glob : globs) {
        if (glob.matches(relativePath, file.isDirectory())) {
            consumer.process(globReference(glob, file));
        }
    }
}
Also used : GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 2 with GlobExpression

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

the class GlobReferenceTest method testExcludeDirectories2.

@Test
public void testExcludeDirectories2() {
    workspace.createDirectory(new WorkspacePath("java/com/google/tests"));
    workspace.createPsiFile(new WorkspacePath("java/com/google/tests/Test.java"));
    workspace.createPsiFile(new WorkspacePath("java/com/google/Foo.java"));
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['**/*'],  exclude = ['**/*'])");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    List<PsiElement> references = multiResolve(glob);
    assertThat(references).isEmpty();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 3 with GlobExpression

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

the class GlobReferenceTest method testIncludeDirectories.

@Test
public void testIncludeDirectories() {
    workspace.createDirectory(new WorkspacePath("java/com/google/tests"));
    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(" + "  ['**/*']," + "  exclude = ['BUILD']," + "  exclude_directories = 0)");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    List<PsiElement> references = multiResolve(glob);
    assertThat(references).hasSize(3);
    assertThat(references).containsExactly(foo, test, test.getParent());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiFile(com.intellij.psi.PsiFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 4 with GlobExpression

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

the class GlobReferenceTest method testGlobReferencingMultipleFiles.

@Test
public void testGlobReferencingMultipleFiles() {
    PsiFile ref1 = workspace.createPsiFile(new WorkspacePath("java/com/google/Test.java"));
    PsiFile ref2 = workspace.createPsiFile(new WorkspacePath("java/com/google/Foo.java"));
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['*.java'])");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    List<PsiElement> references = multiResolve(glob);
    assertThat(references).hasSize(2);
    assertThat(references).containsExactly(ref1, ref2);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiFile(com.intellij.psi.PsiFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 5 with GlobExpression

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

the class GlobReferenceTest method testExcludeDirectories.

@Test
public void testExcludeDirectories() {
    workspace.createDirectory(new WorkspacePath("java/com/google/tests"));
    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(['**/*'],  exclude = ['BUILD'])");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    List<PsiElement> references = multiResolve(glob);
    assertThat(references).hasSize(2);
    assertThat(references).containsExactly(foo, test);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiFile(com.intellij.psi.PsiFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Aggregations

GlobExpression (com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression)17 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)16 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)16 Test (org.junit.Test)16 PsiFile (com.intellij.psi.PsiFile)13 PsiElement (com.intellij.psi.PsiElement)10 PsiReference (com.intellij.psi.PsiReference)6 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1