Search in sources :

Example 1 with PropertyCreationException

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);
    }
}
Also used : CtClass(javassist.CtClass) PropertyCreationException(org.motechproject.mds.exception.object.PropertyCreationException) CtField(javassist.CtField) CannotCompileException(javassist.CannotCompileException)

Aggregations

CannotCompileException (javassist.CannotCompileException)1 CtClass (javassist.CtClass)1 CtField (javassist.CtField)1 PropertyCreationException (org.motechproject.mds.exception.object.PropertyCreationException)1