Search in sources :

Example 6 with RuleDefinition

use of com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition 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 7 with RuleDefinition

use of com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition in project intellij by bazelbuild.

the class BuildDocumentationProvider method docsForBuiltInRule.

@Nullable
private static String docsForBuiltInRule(Project project, @Nullable String ruleName) {
    RuleDefinition rule = getBuiltInRule(project, ruleName);
    if (rule == null) {
        return null;
    }
    String link = Blaze.getBuildSystemProvider(project).getRuleDocumentationUrl(rule);
    if (link == null) {
        return null;
    }
    return String.format("External documentation for %s:<br><a href=\"%s\">%s</a>", rule.name, link, link);
}
Also used : RuleDefinition(com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition) Nullable(javax.annotation.Nullable)

Aggregations

RuleDefinition (com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition)7 ImmutableMap (com.google.common.collect.ImmutableMap)5 AttributeDefinition (com.google.idea.blaze.base.lang.buildfile.language.semantics.AttributeDefinition)2 BuildLanguageSpec (com.google.idea.blaze.base.lang.buildfile.language.semantics.BuildLanguageSpec)1 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)1 PsiElement (com.intellij.psi.PsiElement)1 TreeSet (java.util.TreeSet)1 Nullable (javax.annotation.Nullable)1