use of com.google.api.expr.v1alpha1.Type.AbstractType in project cel-java by projectnessie.
the class Types method substitute.
/**
* substitute replaces all direct and indirect occurrences of bound type parameters. Unbound type
* parameters are replaced by DYN if typeParamToDyn is true.
*/
static Type substitute(Mapping m, Type t, boolean typeParamToDyn) {
Type tSub = m.find(t);
if (tSub != null) {
return substitute(m, tSub, typeParamToDyn);
}
Kind kind = kindOf(t);
if (typeParamToDyn && kind == Kind.kindTypeParam) {
return Decls.Dyn;
}
switch(kind) {
case kindAbstract:
// TODO: implement!
AbstractType at = t.getAbstractType();
List<Type> params = new ArrayList<>(at.getParameterTypesCount());
for (Type p : at.getParameterTypesList()) {
params.add(substitute(m, p, typeParamToDyn));
}
return Decls.newAbstractType(at.getName(), params);
case kindFunction:
FunctionType fn = t.getFunction();
Type rt = substitute(m, fn.getResultType(), typeParamToDyn);
List<Type> args = new ArrayList<>(fn.getArgTypesCount());
for (Type a : fn.getArgTypesList()) {
args.add(substitute(m, a, typeParamToDyn));
}
return Decls.newFunctionType(rt, args);
case kindList:
return Decls.newListType(substitute(m, t.getListType().getElemType(), typeParamToDyn));
case kindMap:
MapType mt = t.getMapType();
return Decls.newMapType(substitute(m, mt.getKeyType(), typeParamToDyn), substitute(m, mt.getValueType(), typeParamToDyn));
case kindType:
if (t.getType() != Type.getDefaultInstance()) {
return Decls.newTypeType(substitute(m, t.getType(), typeParamToDyn));
}
return t;
default:
return t;
}
}
Aggregations