Search in sources :

Example 1 with GeneratedAnnotationValue

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

the class ExternalAnnotationInjector method generateAnnotationField.

private AnnotationField generateAnnotationField(Annotation annotation, AnnotationFieldType type, String name, String value) {
    AnnotationField field = new AnnotationField();
    if (type instanceof BasicAFT) {
        Class<?> enclosedType = ((BasicAFT) type).type;
        if (String.class.isAssignableFrom(enclosedType)) {
            field.element = GeneratedExecutableElement.newMethodWithSelector(name, typeUtil.getJavaString().asType(), null);
            field.value = new GeneratedAnnotationValue(value);
        } else {
            ErrorUtil.error("ExternalAnnotationInjector: unsupported field type " + type);
        }
    } else if (type instanceof EnumAFT) {
        String enumTypeString = annotation.def.name + "." + ((EnumAFT) type).typeName;
        TypeMirror enumType = typeUtil.resolveJavaType(enumTypeString).asType();
        field.element = GeneratedExecutableElement.newMethodWithSelector(name, enumType, /* enclosingElement = */
        null);
        field.value = new GeneratedAnnotationValue(GeneratedVariableElement.newParameter(value, enumType, /* enclosingElement = */
        null));
    } else {
        ErrorUtil.error("ExternalAnnotationInjector: unsupported field type " + type);
    }
    return field;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) GeneratedAnnotationValue(com.google.devtools.j2objc.types.GeneratedAnnotationValue) EnumAFT(scenelib.annotations.field.EnumAFT) BasicAFT(scenelib.annotations.field.BasicAFT)

Aggregations

GeneratedAnnotationValue (com.google.devtools.j2objc.types.GeneratedAnnotationValue)1 TypeMirror (javax.lang.model.type.TypeMirror)1 BasicAFT (scenelib.annotations.field.BasicAFT)1 EnumAFT (scenelib.annotations.field.EnumAFT)1