@SuppressWarnings("unchecked") // for cast of newProxyInstance() to A private <A extends Annotation> A[] getAnnotations(AnnotationBinding[] annoInstances, Class<A> annotationClass, boolean justTheFirst) { if(annoInstances == null || annoInstances.length == 0 || annotationClass == null ) return null; String annoTypeName = annotationClass.getName(); if(annoTypeName == null ) return null; List<A> list = new ArrayList<>(annoInstances.length); for(AnnotationBinding annoInstance : annoInstances) { if (annoInstance == null) continue; AnnotationMirrorImpl annoMirror = createAnnotationMirror(annoTypeName, annoInstance); if (annoMirror != null) { list.add((A)Proxy.newProxyInstance(annotationClass.getClassLoader(), new Class[]{ annotationClass }, annoMirror)); if (justTheFirst) break; } } A [] result = (A[]) Array.newInstance(annotationClass, list.size()); return list.size() > 0 ? (A[]) list.toArray(result) : null; }
@SuppressWarnings("unchecked") // for cast of newProxyInstance() to A private <A extends Annotation> A[] getAnnotations(AnnotationBinding[] annoInstances, Class<A> annotationClass, boolean justTheFirst) { if(annoInstances == null || annoInstances.length == 0 || annotationClass == null ) return null; String annoTypeName = annotationClass.getName(); if(annoTypeName == null ) return null; List<A> list = new ArrayList<>(annoInstances.length); for(AnnotationBinding annoInstance : annoInstances) { if (annoInstance == null) continue; AnnotationMirrorImpl annoMirror = createAnnotationMirror(annoTypeName, annoInstance); if (annoMirror != null) { list.add((A)Proxy.newProxyInstance(annotationClass.getClassLoader(), new Class[]{ annotationClass }, annoMirror)); if (justTheFirst) break; } } A [] result = (A[]) Array.newInstance(annotationClass, list.size()); return list.size() > 0 ? (A[]) list.toArray(result) : null; }
@SuppressWarnings("unchecked") // for cast of newProxyInstance() to A private <A extends Annotation> A[] getAnnotations(AnnotationBinding[] annoInstances, Class<A> annotationClass, boolean justTheFirst) { if(annoInstances == null || annoInstances.length == 0 || annotationClass == null ) return null; String annoTypeName = annotationClass.getName(); if(annoTypeName == null ) return null; List<A> list = new ArrayList<>(annoInstances.length); for(AnnotationBinding annoInstance : annoInstances) { if (annoInstance == null) continue; AnnotationMirrorImpl annoMirror = createAnnotationMirror(annoTypeName, annoInstance); if (annoMirror != null) { list.add((A)Proxy.newProxyInstance(annotationClass.getClassLoader(), new Class[]{ annotationClass }, annoMirror)); if (justTheFirst) break; } } A [] result = (A[]) Array.newInstance(annotationClass, list.size()); return list.size() > 0 ? (A[]) list.toArray(result) : null; }