Search in sources :

Example 6 with PrefsProperty

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());
}
Also used : TypeName(com.squareup.javapoet.TypeName) PrefsProperty(com.abubusoft.kripton.processor.sharedprefs.model.PrefsProperty) MethodSpec(com.squareup.javapoet.MethodSpec) Builder(com.squareup.javapoet.TypeSpec.Builder) PrefsTransform(com.abubusoft.kripton.processor.sharedprefs.transform.PrefsTransform)

Aggregations

PrefsProperty (com.abubusoft.kripton.processor.sharedprefs.model.PrefsProperty)6 PrefsTransform (com.abubusoft.kripton.processor.sharedprefs.transform.PrefsTransform)4 MethodSpec (com.squareup.javapoet.MethodSpec)4 ModelAnnotation (com.abubusoft.kripton.processor.core.ModelAnnotation)2 Builder (com.squareup.javapoet.TypeSpec.Builder)2 SharedPreferences (android.content.SharedPreferences)1 BindPreference (com.abubusoft.kripton.android.annotation.BindPreference)1 BindSharedPreferences (com.abubusoft.kripton.android.annotation.BindSharedPreferences)1 AbstractSharedPreference (com.abubusoft.kripton.android.sharedprefs.AbstractSharedPreference)1 BindDisabled (com.abubusoft.kripton.annotation.BindDisabled)1 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)1 BindTypeContext (com.abubusoft.kripton.processor.bind.BindTypeContext)1 BindEntity (com.abubusoft.kripton.processor.bind.model.BindEntity)1 BindProperty (com.abubusoft.kripton.processor.bind.model.BindProperty)1 InvalidDefinition (com.abubusoft.kripton.processor.exceptions.InvalidDefinition)1 PrefsEntity (com.abubusoft.kripton.processor.sharedprefs.model.PrefsEntity)1 TypeName (com.squareup.javapoet.TypeName)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 ArrayList (java.util.ArrayList)1 Element (javax.lang.model.element.Element)1