Search in sources :

Example 1 with StorIOContentResolverColumn

use of com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverColumn in project storio by pushtorefresh.

the class StorIOContentResolverProcessor method processAnnotatedFieldOrMethod.

/**
     * Processes annotated field and returns result of processing or throws exception
     *
     * @param annotatedField field that was annotated with {@link StorIOContentResolverColumn}
     * @return non-null {@link StorIOContentResolverColumnMeta} with meta information about field
     */
@NotNull
@Override
protected StorIOContentResolverColumnMeta 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 " + StorIOContentResolverColumn.class.getSimpleName() + " annotation, if you need to serialize/deserialize field of that type " + "-> please write your own resolver: " + e.getMessage());
    }
    final StorIOContentResolverColumn storIOContentResolverColumn = annotatedField.getAnnotation(StorIOContentResolverColumn.class);
    if (storIOContentResolverColumn.ignoreNull() && annotatedField.asType().getKind().isPrimitive()) {
        throw new ProcessingException(annotatedField, "ignoreNull should not be used for primitive type: " + annotatedField.getSimpleName());
    }
    final String columnName = storIOContentResolverColumn.name();
    if (columnName.length() == 0) {
        throw new ProcessingException(annotatedField, "Column name is empty: " + annotatedField.getSimpleName());
    }
    return new StorIOContentResolverColumnMeta(annotatedField.getEnclosingElement(), annotatedField, annotatedField.getSimpleName().toString(), javaType, storIOContentResolverColumn);
}
Also used : StorIOContentResolverColumn(com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverColumn) JavaType(com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType) StorIOContentResolverColumnMeta(com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta) 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 StorIOContentResolverColumn (com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverColumn)1 StorIOContentResolverColumnMeta (com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta)1 NotNull (org.jetbrains.annotations.NotNull)1