use of core.framework.internal.asm.CodeBuilder in project core-ng-project by neowu.
the class BeanValidatorBuilder method validateMethod.
private String validateMethod(Class<?> beanClass, String parentPath) {
String methodName = "validate" + beanClass.getSimpleName() + (index++);
var builder = new CodeBuilder().append("private void {}({} bean, {} errors, boolean partial) {\n", methodName, type(beanClass), type(ValidationErrors.class));
for (Field field : Classes.instanceFields(beanClass)) {
if (!hasValidationAnnotation(field))
continue;
Type fieldType = field.getGenericType();
Class<?> fieldClass = GenericTypes.rawClass(fieldType);
String pathLiteral = variable(path(field, parentPath));
builder.indent(1).append("if (bean.{} == null) {\n", field.getName());
NotNull notNull = field.getDeclaredAnnotation(NotNull.class);
if (notNull != null)
builder.indent(2).append("if (!partial) errors.add({}, {}, null);\n", pathLiteral, variable(notNull.message()));
builder.indent(1).append("} else {\n");
if (String.class.equals(fieldClass)) {
buildStringValidation(builder, field, pathLiteral);
} else if (GenericTypes.isList(fieldType)) {
buildListValidation(builder, field, pathLiteral, parentPath);
} else if (GenericTypes.isMap(fieldType)) {
buildMapValidation(builder, field, pathLiteral, parentPath);
} else if (Number.class.isAssignableFrom(fieldClass)) {
buildNumberValidation(builder, field, pathLiteral);
} else if (!isValueClass(fieldClass)) {
String method = validateMethod(fieldClass, path(field, parentPath));
builder.indent(2).append("{}(bean.{}, errors, partial);\n", method, field.getName());
}
builder.indent(1).append("}\n");
}
builder.append('}');
this.builder.addMethod(builder.build());
return methodName;
}
use of core.framework.internal.asm.CodeBuilder in project core-ng-project by neowu.
the class ElasticSearchTypeImpl method validate.
private void validate(BulkResponse response) {
if (!response.errors())
return;
var builder = new CodeBuilder();
builder.append("bulk operation failed, errors=[\n");
for (BulkResponseItem item : response.items()) {
ErrorCause error = item.error();
if (error != null) {
builder.append("id={}, error={}, stackTrace={}\n", item.id(), error.reason(), error.stackTrace());
}
}
builder.append("]");
throw new SearchException(builder.build());
}
Aggregations