The list of methods to do Reflection Method Annotation are organized into topic(s).
List
getMethodAnnotatedWith(Class> toIntrospect, Class extends Annotation> c)
get Method Annotated With
ArrayList<Method> result = new ArrayList<Method>();
Map<String, Method> allM = new HashMap<String, Method>();
Class<?> currentToIntrospect = toIntrospect;
while (currentToIntrospect != null) {
for (Method me : currentToIntrospect.getMethods()) {
if (Modifier.isPublic(me.getModifiers())) {
if (allM.containsKey(me.getName()) == false)
allM.put(me.getName(), me);
...
T
getMethodAnnotation(Class a, Method m) Returns the specified annotation on the specified method.
T t = m.getAnnotation(a);
if (t != null)
return t;
Class<?> pc = m.getDeclaringClass().getSuperclass();
if (pc != null) {
for (Method m2 : pc.getDeclaredMethods()) {
if (isSameMethod(m, m2)) {
t = getMethodAnnotation(a, m2);
...
Annotation
getMethodAnnotation(final Method method, final Class annoClass) get Method Annotation
final Set<Class> visited = new HashSet<Class>();
final LinkedList<Class> stack = new LinkedList<Class>();
stack.add(method.getDeclaringClass());
while (!stack.isEmpty()) {
Class classToChk = stack.pop();
if (classToChk == null || visited.contains(classToChk)) {
continue;
visited.add(classToChk);
Method m = getMethod(classToChk, method.getName(), method.getParameterTypes());
if (m == null) {
continue;
Annotation a = m.getAnnotation(annoClass);
if (a != null) {
return a;
stack.push(classToChk.getSuperclass());
addInterfaces(method.getDeclaringClass(), stack);
return null;
T
getMethodAnnotation(Method method, Class annotationType) get Method Annotation
T ann = method.getAnnotation(annotationType);
if (ann == null) {
for (Class iface : method.getDeclaringClass().getInterfaces()) {
for (Method otherMethod : iface.getMethods()) {
if (isMatchingMethodSignatures(method, otherMethod)) {
return getMethodAnnotation(otherMethod, annotationType);
return ann;
Map
,Annotation> getMethodAnnotationMap(Method method, Collection> annotationClasses)
get Method Annotation Map
Annotation[] methodAnnotations = method.getAnnotations();
Map<Class<? extends Annotation>, Annotation> methodAnnotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
for (Annotation methodAnnotation : methodAnnotations) {
methodAnnotationMap.put(methodAnnotation.annotationType(), methodAnnotation);
methodAnnotationMap.keySet().retainAll(annotationClasses);
return methodAnnotationMap;