public static Annotation cloneAnnotation ( ConstPool constPool , java . lang . annotation . Annotation annotation ) throws IllegalArgumentException , IllegalAccessException , InvocationTargetException { Class < ? > clazz = annotation . annotationType ( ) ; Annotation annot = new Annotation ( clazz . getName ( ) , constPool ) ; for ( Method method : clazz . getDeclaredMethods ( ) ) { MemberValue memberVal = null ; if ( method . getReturnType ( ) . isArray ( ) ) { List < MemberValue > memberVals = new LinkedList < MemberValue > ( ) ; for ( Object val : ( Object [ ] ) method . invoke ( annotation ) ) { memberVals . add ( createMemberValue ( constPool , val ) ) ; } memberVal = new ArrayMemberValue ( constPool ) ; ( ( ArrayMemberValue ) memberVal ) . setValue ( memberVals . toArray ( new MemberValue [ ] { } ) ) ; } else { memberVal = createMemberValue ( constPool , method . invoke ( annotation ) ) ; } annot . addMemberValue ( method . getName ( ) , memberVal ) ; } return annot ; }
Clone an annotation and all of it s methods