use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LabelReferenceTest method testRulePreferredOverFile.
@Test
public void testRulePreferredOverFile() {
BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = 'lib')");
workspace.createDirectory(new WorkspacePath("java/com/foo/lib"));
BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "java_library(", " name = 'bar',", " src = glob(['**/*.java'])," + " deps = ['//java/com/foo:lib'],", ")");
FuncallExpression target = targetFile.findRule("lib");
assertThat(target).isNotNull();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(1);
PsiElement element = references[0].getElement();
FuncallExpression rule = PsiUtils.getParentOfType(element, FuncallExpression.class, true);
assertThat(rule.getName()).isEqualTo("bar");
assertThat(rule.getContainingFile()).isEqualTo(referencingFile);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression 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.FuncallExpression 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.FuncallExpression 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.FuncallExpression in project intellij by bazelbuild.
the class CopyBlazeTargetPathAction method getTargetBuildingFile.
/**
* Find a BUILD target building the selected file, if relevant.
*/
@Nullable
private static Label getTargetBuildingFile(Project project, AnActionEvent e) {
VirtualFile vf = e.getData(CommonDataKeys.VIRTUAL_FILE);
BlazePackage parentPackage = BuildFileUtils.getBuildFile(project, vf);
if (parentPackage == null) {
return null;
}
PsiElement target = BuildFileUtils.findBuildTarget(project, parentPackage, new File(vf.getPath()));
return target instanceof FuncallExpression ? ((FuncallExpression) target).resolveBuildLabel() : null;
}
Aggregations