Search in sources :

Example 1 with FuncallExpression

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()]);
}
Also used : FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)

Example 2 with FuncallExpression

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);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 3 with FuncallExpression

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());
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 4 with FuncallExpression

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 5 with FuncallExpression

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);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Aggregations

FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)44 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)33 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)32 Test (org.junit.Test)32 PsiElement (com.intellij.psi.PsiElement)13 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)10 PsiReference (com.intellij.psi.PsiReference)10 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)7 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)6 PsiFile (com.intellij.psi.PsiFile)6 Nullable (javax.annotation.Nullable)5 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)4 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)2 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2