use of com.google.idea.blaze.base.lang.buildfile.language.semantics.BuildLanguageSpec in project intellij by bazelbuild.
the class BuildLangSyncPlugin method getBuildLanguageSpec.
@Nullable
private static LanguageSpecResult getBuildLanguageSpec(Project project, WorkspaceRoot workspace, ProjectViewSet projectViewSet, @Nullable SyncState previousSyncState, BlazeContext parentContext) {
LanguageSpecResult oldResult = previousSyncState != null ? previousSyncState.get(LanguageSpecResult.class) : null;
if (oldResult != null && !oldResult.shouldRecalculateSpec()) {
return oldResult;
}
LanguageSpecResult result = Scope.push(parentContext, (context) -> {
context.push(new TimingScope("BUILD language spec", EventType.BlazeInvocation));
BuildLanguageSpec spec = parseLanguageSpec(project, workspace, projectViewSet, context);
if (spec != null) {
return new LanguageSpecResult(spec, System.currentTimeMillis());
}
return null;
});
return result != null ? result : oldResult;
}
use of com.google.idea.blaze.base.lang.buildfile.language.semantics.BuildLanguageSpec 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)));
}
}
Aggregations