Search in sources :

Example 26 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class BuildElementGenerator method createKeywordArgument.

public Argument.Keyword createKeywordArgument(String keyword, String value) {
    String dummyText = String.format("foo(%s = \"%s\")", keyword, value);
    FuncallExpression funcall = (FuncallExpression) createExpressionFromText(dummyText);
    return (Argument.Keyword) funcall.getArguments()[0];
}
Also used : FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)

Example 27 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class BuildFileFoldingBuilder method getPlaceholderText.

@Override
@Nullable
public String getPlaceholderText(ASTNode node) {
    PsiElement psi = node.getPsi();
    if (psi instanceof FuncallExpression) {
        FuncallExpression expr = (FuncallExpression) psi;
        String name = expr.getNameArgumentValue();
        if (name != null) {
            return "name = \"" + name + "\"...";
        }
    }
    if (psi instanceof LoadStatement) {
        String fileName = ((LoadStatement) psi).getImportedPath();
        if (fileName != null) {
            return "\"" + fileName + "\"...";
        }
    }
    return "...";
}
Also used : LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 28 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class BuiltInRuleAnnotator method visitFuncallExpression.

@Override
public void visitFuncallExpression(FuncallExpression node) {
    BuildLanguageSpec spec = BuildLanguageSpecProvider.getInstance().getLanguageSpec(node.getProject());
    if (spec == null) {
        return;
    }
    String ruleName = node.getFunctionName();
    RuleDefinition rule = spec.getRule(ruleName);
    if (rule == null) {
        return;
    }
    if (node.getReferencedElement() != null) {
        // this has been locally overridden, so don't attempt validation
        return;
    }
    Set<String> missingAttributes = new TreeSet<>(rule.mandatoryAttributes.keySet());
    for (Argument arg : node.getArguments()) {
        if (arg instanceof Argument.StarStar) {
            missingAttributes.clear();
            continue;
        }
        String name = arg.getName();
        if (name == null) {
            continue;
        }
        AttributeDefinition attribute = rule.getAttribute(name);
        if (attribute == null) {
            markError(arg, String.format("Unrecognized attribute '%s' for rule type '%s'", name, ruleName));
            continue;
        }
        missingAttributes.remove(name);
        Expression argValue = arg.getValue();
        if (argValue == null) {
            continue;
        }
        PsiElement rootElement = PsiUtils.getReferencedTargetValue(argValue);
        if (!BuildElementValidation.possiblyValidType(rootElement, attribute.type)) {
            markError(arg, String.format("Invalid value for attribute '%s'. Expected a value of type '%s'", name, attribute.type));
        }
    }
    if (!missingAttributes.isEmpty()) {
        markError(node, String.format("Target missing required attribute(s): %s", Joiner.on(',').join(missingAttributes)));
    }
}
Also used : Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) Expression(com.google.idea.blaze.base.lang.buildfile.psi.Expression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) TreeSet(java.util.TreeSet) AttributeDefinition(com.google.idea.blaze.base.lang.buildfile.language.semantics.AttributeDefinition) RuleDefinition(com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition) BuildLanguageSpec(com.google.idea.blaze.base.lang.buildfile.language.semantics.BuildLanguageSpec) PsiElement(com.intellij.psi.PsiElement)

Example 29 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class RenameRefactoringTest method testRenameExternalWorkspaceTarget.

@Test
public void testRenameExternalWorkspaceTarget() {
    BuildFile workspaceFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", "    name = \"javax\",", "    artifact = \"javax.inject:javax.inject:1\",", "    sha1 = \"6975da39a7040257bd51d21a231b76c915872d38\",", ")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = \"javax_inject\", exports = [\"@javax//jar\"])");
    FuncallExpression targetRule = PsiUtils.findFirstChildOfClassRecursive(workspaceFile, FuncallExpression.class);
    testFixture.renameElement(targetRule, "v2_lib");
    assertFileContents(workspaceFile, "maven_jar(", "    name = \"v2_lib\",", "    artifact = \"javax.inject:javax.inject:1\",", "    sha1 = \"6975da39a7040257bd51d21a231b76c915872d38\",", ")");
    assertFileContents(referencingFile, "java_library(name = \"javax_inject\", exports = [\"@v2_lib//jar\"])");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 30 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class RenameRefactoringTest method testTargetRenameValidation.

@Test
public void testTargetRenameValidation() {
    BuildFile file = createBuildFile(new WorkspacePath("com/google/foo/BUILD"), "rule_type(name = \"target\")");
    FuncallExpression target = PsiUtils.findFirstChildOfClassRecursive(file, FuncallExpression.class);
    assertThat(RenameUtil.isValidName(getProject(), target, "name-with_allowed,meta=chars+-./@~")).isTrue();
    assertThat(RenameUtil.isValidName(getProject(), target, "name:withColon")).isFalse();
    assertThat(RenameUtil.isValidName(getProject(), target, "/start-with-slash")).isFalse();
    assertThat(RenameUtil.isValidName(getProject(), target, "up-level-ref/../etc")).isFalse();
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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