use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class ArgumentReference method resolveFunction.
@Nullable
protected FunctionStatement resolveFunction() {
FuncallExpression call = PsiTreeUtil.getParentOfType(myElement, FuncallExpression.class);
if (call == null) {
return null;
}
PsiElement callee = call.getReferencedElement();
return callee instanceof FunctionStatement ? (FunctionStatement) callee : null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BuildTargetElementEvaluator method getParentFuncallIfNameString.
@Nullable
private static FuncallExpression getParentFuncallIfNameString(PsiElement element) {
PsiElement parent = element.getParent();
if (!(parent instanceof StringLiteral)) {
return null;
}
parent = parent.getParent();
if (!(parent instanceof Keyword)) {
return null;
}
if (!Objects.equals(((Keyword) parent).getName(), "name")) {
return null;
}
parent = parent.getParent();
if (!(parent instanceof ArgumentList)) {
return null;
}
parent = parent.getParent();
return parent instanceof FuncallExpression ? (FuncallExpression) parent : null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class ExternalWorkspaceFindUsagesTest method testFindUsagesFromExternalWorkspaceFile.
@Test
public void testFindUsagesFromExternalWorkspaceFile() {
BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("BUILD"), "java_library(", " name = 'lib',", " exports = ['@junit//:jar'],", ")");
BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", " name = 'jar',", " jars = ['junit-4.11.jar'],", ")");
FuncallExpression target = externalFile.findRule("jar");
assertThat(target).isNotNull();
Argument.Keyword arg = workspaceBuildFile.findRule("lib").getKeywordArgument("exports");
StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(arg, StringLiteral.class);
assertThat(label).isNotNull();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(1);
assertThat(references[0].getElement()).isEqualTo(label);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class ExternalWorkspaceFindUsagesTest method testFindUsagesFromWorkspaceFile.
@Test
public void testFindUsagesFromWorkspaceFile() {
BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", " name = 'javax_inject',", " artifact = 'javax.inject:javax.inject:1',", " sha1 = '6975da39a7040257bd51d21a231b76c915872d38',", ")");
BuildFile refFile1 = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = 'javax_inject', exports = ['@javax_inject//jar'])");
BuildFile refFile2 = createBuildFile(new WorkspacePath("java/com/bar/build_defs.bzl"), "DEP = '@javax_inject//invalid:nonsense'");
FuncallExpression target = workspaceBuildFile.findRule("javax_inject");
StringLiteral ref1 = PsiUtils.findFirstChildOfClassRecursive(refFile1.findRule("javax_inject").getKeywordArgument("exports"), StringLiteral.class);
StringLiteral ref2 = PsiUtils.findFirstChildOfClassRecursive(refFile2, StringLiteral.class);
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(2);
assertThat(Arrays.stream(references).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(ref1, ref2);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class FindRuleUsagesTest method testLocalFullReference.
// test full package references, made locally
@Test
public void testLocalFullReference() {
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "java_library(name = \"target\")", "java_library(name = \"other\", deps = [\"//java/com/google:target\"]");
FuncallExpression target = buildFile.findChildByClass(FuncallExpression.class);
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(1);
PsiElement ref = references[0].getElement();
assertThat(ref).isInstanceOf(StringLiteral.class);
assertThat(ref.getParent()).isInstanceOf(ListLiteral.class);
}
Aggregations