@Override
public String getValidator(Named<?> named) {
if (named instanceof Parameter) {
Parameter param = (Parameter) named;
TypeRef type = param.type();
if (type.isBuiltin())
return String.format("EtchValidator%s::Get(runtime, %d, tmpValue)",
this.getValidatorStringForParam(param), type.dim());
Named<?> n = type.getNamed(type.intf());
if (n.isBuiltin()) {
Builtin b = (Builtin) n;
String cn = b.className();
if (n.efqname(this).equals("EtchHashTable")) {
cn += "<EtchObjectPtr, EtchObjectPtr>";
}
if (n.efqname(this).equals("EtchHashSet")) {
cn += "<EtchObjectPtr>";
}
if (n.efqname(this).equals("EtchList")) {
cn += "<EtchObjectPtr>";
}
/*
* int i = cn.indexOf( '<' ); if (i >= 0) cn = cn.substring( 0, i );
*/
return String.format(
"EtchValidatorCustom::Get(runtime, %d, %s::TYPE(), %s, tmpValue);",
type.dim(), cn, b.allowSubclass());
}
// Allow subclassing for etch defined structs and externs.
if (n.isStruct() || n.isExcept()) {
if (n.isStruct()) {
Struct s = (Struct) n;
return String.format(
"EtchValidatorCustom::Get(runtime, %d, %s::TYPE(), true, tmpValue);",
type.dim(), s
.service().name() + "::" + n.efqname(this));
}
Except e = (Except) n;
return String.format(
"EtchValidatorCustom::Get(runtime, %d, %s::TYPE(), true, tmpValue);", type.dim(), e
.service().name() + "::" + n.efqname(this));
}
// Don't allow subclassing for externs or etch defined enums.
if (!(n.isExtern() || n.isEnumx()))
Assertion.check(n.isExtern() || n.isEnumx(),
"n.isExtern() || n.isEnumx(): " + n);
Enumx e = (Enumx) n;
return String.format(
"EtchValidatorCustom::Get(runtime, %d, %s::TYPE(), false, tmpValue);",
type.dim(), n.efqname(this));
}
if (named instanceof Thrown) {
Thrown thrown = (Thrown) named;
Except e = (Except) thrown.getNamed();