Search in sources :

Example 66 with BuildFile

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

the class FindRuleUsagesTest method testLocalReferences.

@Test
public void testLocalReferences() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "java_library(name = \"target\")", "top_level_ref = \":target\"", "java_library(name = \"other\", deps = [\":target\"]");
    FuncallExpression target = buildFile.findChildByClass(FuncallExpression.class);
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(2);
    PsiElement firstRef = references[0].getElement();
    assertThat(firstRef).isInstanceOf(StringLiteral.class);
    assertThat(firstRef.getParent()).isInstanceOf(AssignmentStatement.class);
    PsiElement secondRef = references[1].getElement();
    assertThat(secondRef).isInstanceOf(StringLiteral.class);
    assertThat(secondRef.getParent()).isInstanceOf(ListLiteral.class);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 67 with BuildFile

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

the class FindRuleUsagesTest method testInvalidReferenceDoesntResolve.

@Test
public void testInvalidReferenceDoesntResolve() {
    // reference ":target" from another build file (missing package path in label)
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "java_library(name = \"target\")");
    createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "java_library(name = \"ref\", exports = [\":target\"])");
    FuncallExpression target = targetFile.findChildByClass(FuncallExpression.class);
    assertThat(target).isNotNull();
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(0);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 68 with BuildFile

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

the class FindRuleUsagesTest method testNonLocalReferences.

@Test
public void testNonLocalReferences() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "java_library(name = \"target\")");
    BuildFile refFile = createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "java_library(name = \"ref\", exports = [\"//java/com/google/foo:target\"])");
    FuncallExpression target = targetFile.findChildByClass(FuncallExpression.class);
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(1);
    PsiElement ref = references[0].getElement();
    assertThat(ref).isInstanceOf(StringLiteral.class);
    assertThat(ref.getContainingFile()).isEqualTo(refFile);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 69 with BuildFile

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

the class FindRuleUsagesTest method testFindUsagesWorksFromNameString.

@Test
public void testFindUsagesWorksFromNameString() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "java_library(name = \"tar<caret>get\")");
    BuildFile refFile = createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "java_library(name = \"ref\", exports = [\"//java/com/google/foo:target\"])");
    testFixture.configureFromExistingVirtualFile(targetFile.getVirtualFile());
    PsiElement targetElement = GotoDeclarationAction.findElementToShowUsagesOf(testFixture.getEditor(), testFixture.getEditor().getCaretModel().getOffset());
    PsiReference[] references = FindUsages.findAllReferences(targetElement);
    assertThat(references).hasLength(1);
    PsiElement ref = references[0].getElement();
    assertThat(ref).isInstanceOf(StringLiteral.class);
    assertThat(ref.getContainingFile()).isEqualTo(refFile);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 70 with BuildFile

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

the class FunctionStatementUsagesTest method testLocalReferences.

@Test
public void testLocalReferences() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, srcs, deps):", "    # function body", "function(name = \"foo\")");
    FunctionStatement funcDef = buildFile.findChildByClass(FunctionStatement.class);
    PsiReference[] references = FindUsages.findAllReferences(funcDef);
    assertThat(references).hasLength(1);
    PsiElement ref = references[0].getElement();
    assertThat(ref).isInstanceOf(FuncallExpression.class);
}
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) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) 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