use of org.motechproject.mds.exception.object.PropertyCreationException in project motech by motech.
the class EntityBuilderImpl method addProperty.
private void addProperty(CtClass declaring, String typeClassName, String propertyName, String defaultValue) {
try {
String name = uncapitalize(propertyName);
JavassistUtil.removeFieldIfExists(declaring, propertyName);
CtClass type = classPool.getOrNull(typeClassName);
CtField field = JavassistBuilder.createField(declaring, type, propertyName, null);
if (isBlank(defaultValue)) {
declaring.addField(field);
} else {
CtField.Initializer initializer = JavassistBuilder.createInitializer(typeClassName, defaultValue);
declaring.addField(field, initializer);
}
createGetter(declaring, name, field);
createSetter(declaring, name, field);
} catch (CannotCompileException e) {
throw new PropertyCreationException("Error while creating property " + propertyName, e);
}
}
Aggregations