Search in sources :

Example 1 with StorIOSQLiteColumn

use of com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn in project storio by pushtorefresh.

the class StorIOSQLiteProcessor method processAnnotatedFieldOrMethod.

/**
     * Processes annotated field and returns result of processing or throws exception.
     *
     * @param annotatedField field that was annotated with {@link StorIOSQLiteColumn}
     * @return non-null {@link StorIOSQLiteColumnMeta} with meta information about field
     */
@NotNull
@Override
protected StorIOSQLiteColumnMeta processAnnotatedFieldOrMethod(@NotNull final Element annotatedField) {
    final JavaType javaType;
    try {
        javaType = JavaType.from(annotatedField.getKind() == ElementKind.FIELD ? annotatedField.asType() : ((ExecutableElement) annotatedField).getReturnType());
    } catch (Exception e) {
        throw new ProcessingException(annotatedField, "Unsupported type of field or method for " + StorIOSQLiteColumn.class.getSimpleName() + " annotation, if you need to serialize/deserialize field of that type " + "-> please write your own resolver: " + e.getMessage());
    }
    final StorIOSQLiteColumn storIOSQLiteColumn = annotatedField.getAnnotation(StorIOSQLiteColumn.class);
    if (storIOSQLiteColumn.ignoreNull() && annotatedField.asType().getKind().isPrimitive()) {
        throw new ProcessingException(annotatedField, "ignoreNull should not be used for primitive type: " + annotatedField.getSimpleName());
    }
    final String columnName = storIOSQLiteColumn.name();
    if (columnName.length() == 0) {
        throw new ProcessingException(annotatedField, "Column name is empty: " + annotatedField.getSimpleName());
    }
    return new StorIOSQLiteColumnMeta(annotatedField.getEnclosingElement(), annotatedField, annotatedField.getSimpleName().toString(), javaType, storIOSQLiteColumn);
}
Also used : StorIOSQLiteColumn(com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn) StorIOSQLiteColumnMeta(com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteColumnMeta) JavaType(com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType) ProcessingException(com.pushtorefresh.storio.common.annotations.processor.ProcessingException) SkipNotAnnotatedClassWithAnnotatedParentException(com.pushtorefresh.storio.common.annotations.processor.SkipNotAnnotatedClassWithAnnotatedParentException) ProcessingException(com.pushtorefresh.storio.common.annotations.processor.ProcessingException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProcessingException (com.pushtorefresh.storio.common.annotations.processor.ProcessingException)1 SkipNotAnnotatedClassWithAnnotatedParentException (com.pushtorefresh.storio.common.annotations.processor.SkipNotAnnotatedClassWithAnnotatedParentException)1 JavaType (com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType)1 StorIOSQLiteColumn (com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn)1 StorIOSQLiteColumnMeta (com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteColumnMeta)1 NotNull (org.jetbrains.annotations.NotNull)1