Search in sources :

Example 1 with JsonField

use of com.bluelinelabs.logansquare.annotation.JsonField in project LoganSquare by bluelinelabs.

the class JsonFieldProcessor method processJsonFieldAnnotation.

private void processJsonFieldAnnotation(Element element, Map<String, JsonObjectHolder> jsonObjectMap, Elements elements, Types types) {
    if (!isJsonFieldFieldAnnotationValid(element, elements)) {
        return;
    }
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
    JsonObjectHolder objectHolder = jsonObjectMap.get(TypeUtils.getInjectedFQCN(enclosingElement, elements));
    JsonFieldHolder fieldHolder = objectHolder.fieldMap.get(element.getSimpleName().toString());
    if (fieldHolder == null) {
        fieldHolder = new JsonFieldHolder();
        objectHolder.fieldMap.put(element.getSimpleName().toString(), fieldHolder);
    }
    JsonField annotation = element.getAnnotation(JsonField.class);
    TypeMirror typeConverterType;
    try {
        typeConverterType = mProcessingEnv.getElementUtils().getTypeElement(annotation.typeConverter().getCanonicalName()).asType();
    } catch (MirroredTypeException mte) {
        typeConverterType = mte.getTypeMirror();
    }
    String[] fieldName = annotation.name();
    JsonIgnore ignoreAnnotation = element.getAnnotation(JsonIgnore.class);
    boolean shouldParse = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.SERIALIZE_ONLY;
    boolean shouldSerialize = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.PARSE_ONLY;
    String error = fieldHolder.fill(element, elements, types, fieldName, typeConverterType, objectHolder, shouldParse, shouldSerialize);
    if (!TextUtils.isEmpty(error)) {
        error(element, error);
    }
    ensureTypeConverterClassValid(typeConverterType, elements, types);
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) JsonField(com.bluelinelabs.logansquare.annotation.JsonField) JsonIgnore(com.bluelinelabs.logansquare.annotation.JsonIgnore) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) JsonFieldHolder(com.bluelinelabs.logansquare.processor.JsonFieldHolder) JsonObjectHolder(com.bluelinelabs.logansquare.processor.JsonObjectHolder)

Aggregations

JsonField (com.bluelinelabs.logansquare.annotation.JsonField)1 JsonIgnore (com.bluelinelabs.logansquare.annotation.JsonIgnore)1 JsonFieldHolder (com.bluelinelabs.logansquare.processor.JsonFieldHolder)1 JsonObjectHolder (com.bluelinelabs.logansquare.processor.JsonObjectHolder)1 TypeElement (javax.lang.model.element.TypeElement)1 MirroredTypeException (javax.lang.model.type.MirroredTypeException)1 TypeMirror (javax.lang.model.type.TypeMirror)1