use of com.google.api.expr.v1alpha1.Decl.IdentDecl in project cel-java by projectnessie.
the class Checker method checkCreateMessage.
void checkCreateMessage(Expr.Builder e) {
CreateStruct.Builder msgVal = e.getStructExprBuilder();
// Determine the type of the message.
Type messageType = Decls.Error;
Decl decl = env.lookupIdent(msgVal.getMessageName());
if (decl == null) {
errors.undeclaredReference(location(e), env.container.name(), msgVal.getMessageName());
return;
}
// Ensure the type name is fully qualified in the AST.
msgVal.setMessageName(decl.getName());
setReference(e, newIdentReference(decl.getName(), null));
IdentDecl ident = decl.getIdent();
Types.Kind identKind = kindOf(ident.getType());
if (identKind != Kind.kindError) {
if (identKind != Kind.kindType) {
errors.notAType(location(e), ident.getType());
} else {
messageType = ident.getType().getType();
if (kindOf(messageType) != Kind.kindObject) {
errors.notAMessageType(location(e), messageType);
messageType = Decls.Error;
}
}
}
if (isObjectWellKnownType(messageType)) {
setType(e, getObjectWellKnownType(messageType));
} else {
setType(e, messageType);
}
// Check the field initializers.
for (Entry.Builder ent : msgVal.getEntriesBuilderList()) {
String field = ent.getFieldKey();
Expr.Builder value = ent.getValueBuilder();
check(value);
Type fieldType = Decls.Error;
FieldType t = lookupFieldType(locationByID(ent.getId()), messageType.getMessageType(), field);
if (t != null) {
fieldType = t.type;
}
if (!isAssignable(fieldType, getType(value))) {
errors.fieldTypeMismatch(locationByID(ent.getId()), field, fieldType, getType(value));
}
}
}
use of com.google.api.expr.v1alpha1.Decl.IdentDecl in project cel-java by projectnessie.
the class CheckerEnv method sanitizeIdent.
/**
* sanitizeIdent replaces the identifier's well-known types referenced by message name with
* references to CEL built-in type instances.
*/
Decl sanitizeIdent(Decl decl) {
IdentDecl id = decl.getIdent();
Type t = id.getType();
if (!isObjectWellKnownType(t)) {
return decl;
}
return Decls.newIdent(decl.getName(), getObjectWellKnownType(t), id.getValue());
}
Aggregations