use of org.projectnessie.cel.common.types.Err.ErrType in project cel-java by projectnessie.
the class CheckerEnv method lookupIdent.
/**
* LookupIdent returns a Decl proto for typeName as an identifier in the Env. Returns nil if no
* such identifier is found in the Env.
*/
public Decl lookupIdent(String name) {
for (String candidate : container.resolveCandidateNames(name)) {
Decl ident = declarations.findIdent(candidate);
if (ident != null) {
return ident;
}
// Next try to import the name as a reference to a message type. If found,
// the declaration is added to the outest (global) scope of the
// environment, so next time we can access it faster.
Type t = provider.findType(candidate);
if (t != null) {
Decl decl = Decls.newVar(candidate, t);
declarations.addIdent(decl);
return decl;
}
// Next try to import this as an enum value by splitting the name in a type prefix and
// the enum inside.
Val enumValue = provider.enumValue(candidate);
if (enumValue.type() != ErrType) {
Decl decl = Decls.newIdent(candidate, Decls.Int, Constant.newBuilder().setInt64Value(enumValue.intValue()).build());
declarations.addIdent(decl);
return decl;
}
}
return null;
}
Aggregations