Java Method Call invokeDeclaredMethodWithAnnotation(Class annotationClass, Object target)

Here you can find the source of invokeDeclaredMethodWithAnnotation(Class annotationClass, Object target)

Description

invoke Declared Method With Annotation

License

Open Source License

Declaration

public static void invokeDeclaredMethodWithAnnotation(Class<? extends Annotation> annotationClass,
            Object target) throws InvocationTargetException, IllegalAccessException 

Method Source Code

//package com.java2s;
/*// www  . j  a  v  a 2s  .  com
 * Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved.
 * ELEGA9T PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved.
 */

import java.lang.annotation.Annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    public static void invokeDeclaredMethodWithAnnotation(Class<? extends Annotation> annotationClass,
            Object target) throws InvocationTargetException, IllegalAccessException {
        Method[] declaredMethods = target.getClass().getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            Annotation annotation = declaredMethod.getAnnotation(annotationClass);
            if (annotation != null) {
                invokeMethod(declaredMethod, target, new Object[] {});
            }
        }
    }

    public static Object invokeMethod(Method method, Object target, Object[] parameters)
            throws InvocationTargetException, IllegalAccessException {
        method.setAccessible(true);
        return method.invoke(target, parameters);
    }
}

Related

  1. invokeCmd(String className, String[] args)
  2. invokeDeclared(Class c, Object obj, String method, Class[] paramClasses, Object[] params)
  3. invokeDeclared(Class c, Object obj, String method, Class[] paramClasses, Object[] params)
  4. invokeDeclaredMethod(Object object, String methodName, Object... parameters)
  5. invokeDeclaredMethod(String methodName, Object target, Class[] parameterTypes, Object[] parameters)
  6. invokeDefaultMethod(final Method method, final Object[] args, final Object proxy)
  7. invokedMethod(java.lang.Object closure, java.lang.Class targetClass, java.lang.String targetMethod)
  8. invokeExactField(Object object, String fieldName)
  9. invokeExactMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)