protected AnnotationInstance parseAnnotationDesc ( AnnotationDesc annotationDesc , String programElement ) { AnnotationInstance annotationInstanceNode = objectFactory . createAnnotationInstance ( ) ; try { AnnotationTypeDoc annotTypeInfo = annotationDesc . annotationType ( ) ; annotationInstanceNode . setName ( annotTypeInfo . name ( ) ) ; annotationInstanceNode . setQualified ( annotTypeInfo . qualifiedTypeName ( ) ) ; } catch ( ClassCastException castException ) { log . error ( "Unable to obtain type data about an annotation found on: " + programElement ) ; log . error ( "Add to the classpath the class/jar that defines this annotation." ) ; } for ( AnnotationDesc . ElementValuePair elementValuesPair : annotationDesc . elementValues ( ) ) { AnnotationArgument annotationArgumentNode = objectFactory . createAnnotationArgument ( ) ; annotationArgumentNode . setName ( elementValuesPair . element ( ) . name ( ) ) ; Type annotationArgumentType = elementValuesPair . element ( ) . returnType ( ) ; annotationArgumentNode . setType ( parseTypeInfo ( annotationArgumentType ) ) ; annotationArgumentNode . setPrimitive ( annotationArgumentType . isPrimitive ( ) ) ; annotationArgumentNode . setArray ( annotationArgumentType . dimension ( ) . length ( ) > 0 ) ; Object objValue = elementValuesPair . value ( ) . value ( ) ; if ( objValue instanceof AnnotationValue [ ] ) { for ( AnnotationValue annotationValue : ( AnnotationValue [ ] ) objValue ) { if ( annotationValue . value ( ) instanceof AnnotationDesc ) { AnnotationDesc annoDesc = ( AnnotationDesc ) annotationValue . value ( ) ; annotationArgumentNode . getAnnotation ( ) . add ( parseAnnotationDesc ( annoDesc , programElement ) ) ; } else { annotationArgumentNode . getValue ( ) . add ( annotationValue . value ( ) . toString ( ) ) ; } } } else if ( objValue instanceof FieldDoc ) { annotationArgumentNode . getValue ( ) . add ( ( ( FieldDoc ) objValue ) . name ( ) ) ; } else if ( objValue instanceof ClassDoc ) { annotationArgumentNode . getValue ( ) . add ( ( ( ClassDoc ) objValue ) . qualifiedTypeName ( ) ) ; } else { annotationArgumentNode . getValue ( ) . add ( objValue . toString ( ) ) ; } annotationInstanceNode . getArgument ( ) . add ( annotationArgumentNode ) ; } return annotationInstanceNode ; }
Parses annotation instances of an annotable program element