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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations