use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LabelRuleLookupElement method collectAllRules.
public static BuildLookupElement[] collectAllRules(BuildFile file, String originalString, String packagePrefix, @Nullable String excluded, QuoteType quoteType) {
if (packagePrefix.startsWith("//") || originalString.startsWith(":")) {
packagePrefix += ":";
}
String ruleFragment = LabelUtils.getRuleComponent(originalString);
List<BuildLookupElement> lookups = Lists.newArrayList();
for (FuncallExpression target : file.findChildrenByClass(FuncallExpression.class)) {
String targetName = target.getName();
if (targetName == null || Objects.equals(target.getName(), excluded) || !targetName.startsWith(ruleFragment)) {
continue;
}
String ruleType = target.getFunctionName();
if (ruleType == null) {
continue;
}
lookups.add(new LabelRuleLookupElement(packagePrefix, target, targetName, ruleType, quoteType));
}
return lookups.isEmpty() ? BuildLookupElement.EMPTY_ARRAY : lookups.toArray(new BuildLookupElement[lookups.size()]);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BlazeBuildFileRunConfigurationProducerTest method testProducedFromFuncallExpression.
@Test
public void testProducedFromFuncallExpression() {
PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
FuncallExpression target = PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class);
assertThat(target).isNotNull();
ConfigurationContext context = createContextFromPsi(target);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testOverridenBuiltInSymbolReference.
@Test
public void testOverridenBuiltInSymbolReference() {
setBuiltInRuleNames("java_library");
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "java_library = rule()");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"java_library\"", ")", "java_library(name = 'name')");
TargetExpression target = PsiUtils.findFirstChildOfClassRecursive(extFile, TargetExpression.class);
FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
LoadedSymbol loadElement = PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);
assertThat(target).isNotNull();
assertThat(funcall.getReferencedElement()).isEqualTo(target);
assertThat(loadElement.getImport().getReferencedElement()).isEqualTo(target);
assertThat(Arrays.stream(FindUsages.findAllReferences(target)).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(funcall, loadElement.getImport());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testAliasedFuncallReference.
@Test
public void testAliasedFuncallReference() {
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', newName = 'function'),", "newName(name = \"name\", deps = []");
LoadedSymbol loadedSymbol = PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);
FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
assertThat(funcall.getReferencedElement()).isEqualTo(loadedSymbol.getVisibleElement());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class LocalReferenceTest method testReferenceToFunctionArg.
@Test
public void testReferenceToFunctionArg() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/defs.bzl"), "def function(arg1, arg2):", " arg1(arg2)");
FunctionStatement def = file.findFunctionInScope("function");
FuncallExpression call = PsiUtils.findFirstChildOfClassRecursive(file, FuncallExpression.class);
Parameter fnParam = def.getParameterList().findParameterByName("arg1");
assertThat(fnParam).isNotNull();
assertThat(call.getReference().resolve()).isEqualTo(fnParam);
}
Aggregations