for ( String key : annotationDescr.getValueMap().keySet() ) {
try {
Method m = annotationClass.getMethod( key );
Object val = annotationDescr.getValue( key );
if ( val instanceof Object[] && ! m.getReturnType().isArray() ) {
addBuilderResult( new AnnotationDeclarationError( annotationDescr,
"Wrong cardinality on property " + key ) );
return annotationDescr;
}
if ( m.getReturnType().isArray() && ! (val instanceof Object[]) ) {
val = new Object[] { val };
annotationDescr.setKeyValue( key, val );
}
if ( m.getReturnType().isArray() ) {
int n = Array.getLength(val);
for ( int j = 0; j < n; j++ ) {
if ( Class.class.equals( m.getReturnType().getComponentType() ) ) {
String className = Array.get( val, j ).toString().replace( ".class", "" );
Array.set( val, j, typeResolver.resolveType( className ).getName() + ".class" );
} else if ( m.getReturnType().getComponentType().isAnnotation() ) {
Array.set( val, j, normalizeAnnotation( typeResolver,
(AnnotationDescr) Array.get( val, j ) ) );
}
}
} else {
if ( Class.class.equals( m.getReturnType() ) ) {
String className = annotationDescr.getValueAsString(key).replace( ".class", "" );
annotationDescr.setKeyValue( key, typeResolver.resolveType( className ).getName() + ".class" );
} else if ( m.getReturnType().isAnnotation() ) {
annotationDescr.setKeyValue( key,
normalizeAnnotation( typeResolver,
(AnnotationDescr) annotationDescr.getValue( key ) ) );
}
}
} catch ( NoSuchMethodException e ) {
addBuilderResult( new AnnotationDeclarationError( annotationDescr,
"Unknown annotation property " + key ) );
} catch ( ClassNotFoundException e ) {
addBuilderResult( new AnnotationDeclarationError( annotationDescr,
"Unknown class " + annotationDescr.getValue( key ) + " used in property " + key +
" of annotation " + annotationDescr.getName() ) );
} catch ( NoClassDefFoundError e ) {
addBuilderResult( new AnnotationDeclarationError( annotationDescr,
"Unknown class " + annotationDescr.getValue( key ) + " used in property " + key +
" of annotation " + annotationDescr.getName() ) );
}
}