Search in sources :

Example 1 with GeneratedAnnotationMirror

use of com.google.devtools.j2objc.types.GeneratedAnnotationMirror in project j2objc by google.

the class ExternalAnnotationInjector method generateAnnotationMirror.

private GeneratedAnnotationMirror generateAnnotationMirror(Annotation annotation) {
    TypeElement element = typeUtil.resolveJavaType(annotation.def.name);
    if (element == null) {
        reportNoSuchClass(annotation);
        return null;
    }
    DeclaredType type = (DeclaredType) element.asType();
    GeneratedAnnotationMirror annotationMirror = new GeneratedAnnotationMirror(type);
    for (Map.Entry<String, Object> entry : annotation.fieldValues.entrySet()) {
        String fieldName = entry.getKey();
        // For our uses cases, the scenelib library encodes the annotation value as a string.
        String fieldValue = (String) entry.getValue();
        AnnotationFieldType fieldType = annotation.def.fieldTypes.get(fieldName);
        AnnotationField field = generateAnnotationField(annotation, fieldType, fieldName, fieldValue);
        annotationMirror.addElementValue(field.element, field.value);
    }
    return annotationMirror;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) AnnotationFieldType(scenelib.annotations.field.AnnotationFieldType) GeneratedAnnotationMirror(com.google.devtools.j2objc.types.GeneratedAnnotationMirror) Map(java.util.Map) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

GeneratedAnnotationMirror (com.google.devtools.j2objc.types.GeneratedAnnotationMirror)1 Map (java.util.Map)1 TypeElement (javax.lang.model.element.TypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 AnnotationFieldType (scenelib.annotations.field.AnnotationFieldType)1