use of com.abubusoft.kripton.processor.sharedprefs.transform.PrefsTransform in project kripton by xcesco.
the class BindSharedPreferencesBuilder method generateWriteMethod.
/**
* @param entity
*/
private static void generateWriteMethod(PrefsEntity entity) {
// write method
MethodSpec.Builder method = MethodSpec.methodBuilder("write").addJavadoc("write bean entirely\n\n").addJavadoc("@param bean bean to entirely write\n").addModifiers(Modifier.PUBLIC).addParameter(typeName(entity.getName()), "bean").returns(Void.TYPE);
method.addStatement("$T editor=prefs.edit()", SharedPreferences.Editor.class);
PrefsTransform transform;
for (PrefsProperty item : entity.getCollection()) {
if (item.hasTypeAdapter()) {
transform = PrefsTransformer.lookup(item.typeAdapter.getDataTypeTypename());
} else {
transform = PrefsTransformer.lookup(item);
}
transform.generateWriteProperty(method, "editor", typeName(entity.getElement()), "bean", item);
method.addCode("\n");
}
method.addCode("\n");
method.addStatement("editor.commit()");
builder.addMethod(method.build());
}
use of com.abubusoft.kripton.processor.sharedprefs.transform.PrefsTransform in project kripton by xcesco.
the class BindSharedPreferencesBuilder method generateReadMethod.
private static void generateReadMethod(PrefsEntity entity) {
// read method
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("read").addModifiers(Modifier.PUBLIC).addJavadoc("read bean entirely\n\n").addJavadoc("@return read bean\n").returns(typeName(entity.getName()));
methodBuilder.addStatement("$T bean=new $T()", typeName(entity.getName()), typeName(entity.getName()));
PrefsTransform transform;
for (PrefsProperty item : entity.getCollection()) {
if (item.hasTypeAdapter()) {
transform = PrefsTransformer.lookup(item.typeAdapter.getDataTypeTypename());
} else {
transform = PrefsTransformer.lookup(item);
}
transform.generateReadProperty(methodBuilder, "prefs", typeName(item.getElement().asType()), "bean", item, true);
methodBuilder.addCode("\n");
}
methodBuilder.addCode("\n");
methodBuilder.addStatement("return bean");
builder.addMethod(methodBuilder.build());
}
use of com.abubusoft.kripton.processor.sharedprefs.transform.PrefsTransform in project kripton by xcesco.
the class BindSharedPreferencesBuilder method generateSingleReadMethod.
private static void generateSingleReadMethod(PrefsEntity entity) {
// read method
PrefsTransform transform;
for (PrefsProperty item : entity.getCollection()) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(item.getName()).addModifiers(Modifier.PUBLIC).addJavadoc("read property $L\n\n", item.getName()).addJavadoc("@return property $L value\n", item.getName()).returns(item.getPropertyType().getTypeName());
if (item.hasTypeAdapter()) {
transform = PrefsTransformer.lookup(item.typeAdapter.getDataTypeTypename());
} else {
transform = PrefsTransformer.lookup(item);
}
transform.generateReadProperty(methodBuilder, "prefs", typeName(item.getElement().asType()), "defaultBean", item, false);
methodBuilder.addCode("\n");
builder.addMethod(methodBuilder.build());
}
}
use of com.abubusoft.kripton.processor.sharedprefs.transform.PrefsTransform 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