use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class FunctionStatementUsagesTest method testFuncallReference.
@Test
public void testFuncallReference() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", deps = []");
FunctionStatement function = extFile.firstChildOfClass(FunctionStatement.class);
FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
PsiReference[] references = FindUsages.findAllReferences(function);
assertThat(references).hasLength(2);
assertThat(references[1].getElement()).isEqualTo(funcall);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LocalVariableUsagesTest method testLocalReferences.
@Test
public void testLocalReferences() {
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "localVar = 5", "funcall(localVar)", "def function(name):", " tempVar = localVar");
TargetExpression target = buildFile.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(2);
FuncallExpression funcall = buildFile.findChildByClass(FuncallExpression.class);
assertThat(funcall).isNotNull();
PsiElement firstRef = references[0].getElement();
assertThat(PsiUtils.getParentOfType(firstRef, FuncallExpression.class, true)).isEqualTo(funcall);
FunctionStatement function = buildFile.findChildByClass(FunctionStatement.class);
assertThat(function).isNotNull();
PsiElement secondRef = references[1].getElement();
assertThat(secondRef.getParent()).isInstanceOf(AssignmentStatement.class);
assertThat(PsiUtils.getParentOfType(secondRef, FunctionStatement.class, true)).isEqualTo(function);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BuildReferenceManager method resolveLabel.
/**
* Finds the PSI element associated with the given label.
*/
@Nullable
public PsiElement resolveLabel(Label label, boolean excludeRules) {
File packageDir = WorkspaceHelper.resolveBlazePackage(project, label);
if (packageDir == null) {
return null;
}
String targetName = label.targetName().toString();
if (targetName.equals("__pkg__")) {
return findBuildFile(packageDir);
}
if (!excludeRules) {
FuncallExpression target = findRule(packageDir, targetName);
if (target != null) {
return target;
}
}
// try a direct file reference (e.g. ":a.java")
File fullFile = new File(packageDir, targetName);
if (FileOperationProvider.getInstance().exists(fullFile)) {
return resolveFile(fullFile);
}
return null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LabelReference method getRuleLookups.
private BuildLookupElement[] getRuleLookups(String labelString) {
if (labelString.endsWith("/") || (labelString.startsWith("/") && !labelString.contains(":")) || skylarkExtensionReference(myElement)) {
return BuildLookupElement.EMPTY_ARRAY;
}
String packagePrefix = LabelUtils.getPackagePathComponent(labelString);
BuildFile referencedBuildFile = LabelUtils.getReferencedBuildFile(myElement.getContainingFile(), packagePrefix);
if (referencedBuildFile == null) {
return BuildLookupElement.EMPTY_ARRAY;
}
String self = null;
if (referencedBuildFile == myElement.getContainingFile()) {
FuncallExpression funcall = PsiUtils.getParentOfType(myElement, FuncallExpression.class, true);
if (funcall != null) {
self = funcall.getName();
}
}
return LabelRuleLookupElement.collectAllRules(referencedBuildFile, labelString, packagePrefix, self, myElement.getQuoteType());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BuildReferenceSearcher method processQuery.
@Override
public void processQuery(SearchParameters params, Processor<PsiReference> consumer) {
PsiElement element = params.getElementToSearch();
if (element instanceof NamedBuildElement) {
String fnName = ((NamedBuildElement) element).getName();
if (fnName != null) {
searchForString(params, element, fnName);
}
return;
}
PsiFile file = ResolveUtil.asFileSearch(element);
if (file != null) {
processFileReferences(params, file);
return;
}
if (!(element instanceof FuncallExpression)) {
return;
}
FuncallExpression funcall = (FuncallExpression) element;
PsiFile localFile = element.getContainingFile();
if (localFile == null) {
return;
}
Label label = funcall.resolveBuildLabel();
if (label == null) {
searchForExternalWorkspace(params, localFile, funcall);
return;
}
List<String> stringsToSearch = LabelUtils.getAllValidLabelStrings(label, true);
for (String string : stringsToSearch) {
if (LabelUtils.isAbsolute(string)) {
searchForString(params, element, string);
} else {
// only a valid reference from local package -- restrict the search scope accordingly
SearchScope scope = limitScopeToFile(params.getScopeDeterminedByUser(), localFile);
if (scope != null) {
searchForString(params, scope, element, string);
}
}
}
}
Aggregations