Search in sources :

Example 1 with Argument

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

the class GlobErrorAnnotator method visitGlobExpression.

@Override
public void visitGlobExpression(GlobExpression node) {
    Argument[] args = node.getArguments();
    boolean hasIncludes = false;
    for (int i = 0; i < args.length; i++) {
        Argument arg = args[i];
        String name = arg instanceof Argument.Keyword ? arg.getName() : null;
        if ("include".equals(name) || (arg instanceof Argument.Positional && i == 0)) {
            hasIncludes = checkIncludes(arg.getValue());
        } else if ("exclude".equals(name)) {
            checkListContents("exclude", arg.getValue());
        } else if ("exclude_directories".equals(name)) {
            checkExcludeDirsNode(arg);
        } else {
            markError(arg, "Unrecognized glob argument");
        }
    }
    if (!hasIncludes) {
        markError(node, "Glob expression must contain at least one included string");
    }
}
Also used : Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument)

Example 2 with Argument

use of com.google.idea.blaze.base.lang.buildfile.psi.Argument 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 3 with Argument

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

the class BuildEnterHandler method skipElement.

private static boolean skipElement(PsiElement element, int offset) {
    PsiElement parent = element.getParent();
    if (parent == null || parent.getNode() == null || parent instanceof PsiFileSystemItem) {
        return false;
    }
    TextRange childRange = element.getNode().getTextRange();
    return childRange.equals(parent.getNode().getTextRange()) || childRange.getStartOffset() == offset && (parent instanceof Argument || parent instanceof Parameter);
}
Also used : Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) TextRange(com.intellij.openapi.util.TextRange) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement)

Aggregations

Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)3 PsiElement (com.intellij.psi.PsiElement)2 AttributeDefinition (com.google.idea.blaze.base.lang.buildfile.language.semantics.AttributeDefinition)1 BuildLanguageSpec (com.google.idea.blaze.base.lang.buildfile.language.semantics.BuildLanguageSpec)1 RuleDefinition (com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)1 Parameter (com.google.idea.blaze.base.lang.buildfile.psi.Parameter)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 TreeSet (java.util.TreeSet)1