use of com.abubusoft.kripton.processor.sharedprefs.model.PrefsProperty in project kripton by xcesco.
the class BindSharedPreferencesBuilder method generateEditor.
/**
* create editor
*
* @param entity
*/
private static void generateEditor(PrefsEntity entity) {
com.abubusoft.kripton.common.Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_CAMEL);
Builder innerClassBuilder = TypeSpec.classBuilder("BindEditor").addModifiers(Modifier.PUBLIC).addJavadoc("editor class for shared preferences\n").superclass(typeName("AbstractEditor"));
innerClassBuilder.addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).build());
PrefsTransform transform;
// write method
for (PrefsProperty item : entity.getCollection()) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("put" + converter.convert(item.getName())).addModifiers(Modifier.PUBLIC).addParameter(typeName(item.getElement()), "value").addJavadoc("modifier for property $L\n", item.getName()).returns(typeName("BindEditor"));
TypeName type;
if (item.hasTypeAdapter()) {
type = typeName(item.typeAdapter.dataType);
} else {
type = TypeUtility.typeName(item.getElement());
}
transform = PrefsTransformer.lookup(type);
transform.generateWriteProperty(builder, "editor", null, "value", item);
builder.addCode("\n");
builder.addStatement("return this");
innerClassBuilder.addMethod(builder.build());
}
builder.addType(innerClassBuilder.build());
}
Aggregations