Example usage for java.lang Class getDeclaredMethods

List of usage examples for java.lang Class getDeclaredMethods

Introduction

In this page you can find the example usage for java.lang Class getDeclaredMethods.

Prototype

@CallerSensitive
public Method[] getDeclaredMethods() throws SecurityException 

Source Link

Document

Returns an array containing Method objects reflecting all the declared methods of the class or interface represented by this Class object, including public, protected, default (package) access, and private methods, but excluding inherited methods.

Usage

From source file:com.ez.gallery.permission.EasyPermissions.java

private static void runAnnotatedMethods(Object object, int requestCode) {
    Class clazz = object.getClass();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(AfterPermissionGranted.class)) {
            // Check for annotated methods with matching request code.
            AfterPermissionGranted ann = method.getAnnotation(AfterPermissionGranted.class);
            if (ann.value() == requestCode) {
                // Method must be void so that we can invoke it
                if (method.getParameterTypes().length > 0) {
                    throw new RuntimeException("Cannot execute non-void method " + method.getName());
                }/*from w w w  .j  av  a2 s. com*/

                try {
                    // Make method accessible if private
                    if (!method.isAccessible()) {
                        method.setAccessible(true);
                    }
                    method.invoke(object);
                } catch (IllegalAccessException e) {
                } catch (InvocationTargetException e) {
                }
            }
        }
    }
}

From source file:com.ag.common.permission.EasyPermissions.java

private static void runAnnotatedMethods(Object object, int requestCode) {
    Class clazz = object.getClass();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(AfterPermissionGranted.class)) {
            // Check for annotated methods with matching request code.
            AfterPermissionGranted ann = method.getAnnotation(AfterPermissionGranted.class);
            if (ann.value() == requestCode) {
                // Method must be void so that we can invoke it
                if (method.getParameterTypes().length > 0) {
                    throw new RuntimeException("Cannot execute non-void method " + method.getName());
                }//  w w w.  j ava2s  .co  m

                try {
                    // Make method accessible if private
                    if (!method.isAccessible()) {
                        method.setAccessible(true);
                    }
                    method.invoke(object);
                } catch (IllegalAccessException e) {
                    Log.e(TAG, "runDefaultMethod:IllegalAccessException", e);
                } catch (InvocationTargetException e) {
                    Log.e(TAG, "runDefaultMethod:InvocationTargetException", e);
                }
            }
        }
    }
}

From source file:io.cess.core.gallery.permission.EasyPermissions.java

private static void runAnnotatedMethods(Object object, int requestCode) {
    Class clazz = object.getClass();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(AfterPermissionGranted.class)) {
            // Check for annotated methods with matching request code.
            AfterPermissionGranted ann = method.getAnnotation(AfterPermissionGranted.class);
            if (ann.value() == requestCode) {
                // Method must be void so that we can invoke it
                if (method.getParameterTypes().length > 0) {
                    throw new RuntimeException("Cannot execute non-void method " + method.getName());
                }/*from  w w w.  j a  va  2s  .  c o  m*/

                try {
                    // Make method accessible if private
                    if (!method.isAccessible()) {
                        method.setAccessible(true);
                    }
                    method.invoke(object);
                } catch (IllegalAccessException e) {
                    //ILogger.e(TAG, "runDefaultMethod:IllegalAccessException", e);
                } catch (InvocationTargetException e) {
                    //ILogger.e(TAG, "runDefaultMethod:InvocationTargetException", e);
                }
            }
        }
    }
}

From source file:cn.finalteam.galleryfinal.permission.EasyPermissions.java

private static void runAnnotatedMethods(Object object, int requestCode) {
    Class clazz = object.getClass();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(AfterPermissionGranted.class)) {
            // Check for annotated methods with matching request code.
            AfterPermissionGranted ann = method.getAnnotation(AfterPermissionGranted.class);
            if (ann.value() == requestCode) {
                // Method must be void so that we can invoke it
                if (method.getParameterTypes().length > 0) {
                    throw new RuntimeException("Cannot execute non-void method " + method.getName());
                }/*from w w w  . ja  v a  2  s . c  om*/

                try {
                    // Make method accessible if private
                    if (!method.isAccessible()) {
                        method.setAccessible(true);
                    }
                    method.invoke(object);
                } catch (IllegalAccessException e) {
                    ILogger.e(TAG, "runDefaultMethod:IllegalAccessException", e);
                } catch (InvocationTargetException e) {
                    ILogger.e(TAG, "runDefaultMethod:InvocationTargetException", e);
                }
            }
        }
    }
}

From source file:com.ybg.rp.assistant.permission.EasyPermissions.java

private static void runAnnotatedMethods(Object object, int requestCode) {
    Class clazz = object.getClass();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(AfterPermissionGranted.class)) {
            // Check for annotated methods with matching request code.
            AfterPermissionGranted ann = method.getAnnotation(AfterPermissionGranted.class);
            if (ann.value() == requestCode) {
                // Method must be void so that we can invoke it
                if (method.getParameterTypes().length > 0) {
                    throw new RuntimeException("Cannot execute non-void method " + method.getName());
                }/*from   w w  w  .  ja  v a 2 s. c  o m*/

                try {
                    // Make method accessible if private
                    if (!method.isAccessible()) {
                        method.setAccessible(true);
                    }
                    method.invoke(object);
                } catch (IllegalAccessException e) {
                    TbLog.e("---EasyPermissions/ runDefaultMethod:IllegalAccessException:", e);
                } catch (InvocationTargetException e) {
                    TbLog.e("---EasyPermissions/ runDefaultMethod:InvocationTargetException", e);
                }
            }
        }
    }
}

From source file:Main.java

/**
 * getMethodNameList/*from ww  w.  ja va 2s. c o m*/
 * @param theClass
 * @return
 */
public final static HashMap<String, Integer> getMethodNameList(Class<?> theClass) {
    // Method - Number of params
    HashMap<String, Integer> methodsAndParams = new HashMap<String, Integer>();
    // Get the class name
    String className = theClass.getCanonicalName();

    Method[] classMethods = theClass.getDeclaredMethods();
    String currMethodCanonicalName = "";
    String currMethodName = "";
    int currMethodNumberParams = 0;
    for (int i = 0; i < classMethods.length; i++) {
        currMethodCanonicalName = classMethods[i].toString();

        // Get method name only
        String methodString = currMethodCanonicalName.substring(currMethodCanonicalName.lastIndexOf(className),
                currMethodCanonicalName.indexOf('('));
        currMethodName = methodString.substring(methodString.lastIndexOf('.') + 1, methodString.length());

        // Get method number of params
        String params = currMethodCanonicalName.substring(currMethodCanonicalName.indexOf('(') + 1,
                currMethodCanonicalName.lastIndexOf(')'));
        String theParams[] = params.split(",");
        currMethodNumberParams = theParams.length;

        methodsAndParams.put(currMethodName, currMethodNumberParams);
    }

    /**
    for (String name: methodsAndParams.keySet()){
       String key =name.toString();
       String value = methodsAndParams.get(name).toString();  
       System.out.println(key + " " + value);  
    } 
     */

    return methodsAndParams;

}

From source file:lite.flow.util.ActivityInspector.java

/**
 *  Component can have multiple Entry methods.
 * @param clazz//from w  ww  . ja  v  a 2  s .  c o m
 * @return
 */
static public ArrayList<Method> getEntryMethods(Class<?> clazz) {

    ArrayList<Method> methods = new ArrayList<>();

    for (Method method : clazz.getDeclaredMethods()) {
        if (Modifier.isPublic(method.getModifiers())) {
            methods.add(method);
        }
    }

    return methods;
}

From source file:com.nridge.core.base.field.data.DataBeanBag.java

/**
 * Accepts a POJO containing one or more public annotated get
 * methods and creates a DataBag from them.  The DataBeanObject2
 * test class provides a reference example.
 *
 * @param anObject POJO instance.//ww w .j av  a  2 s.c o m
 *
 * @return Data bag instance populated with field information.
 *
 * @throws NSException Thrown if object is null.
 * @throws IllegalAccessException Thrown if access is illegal.
 * @throws InvocationTargetException Thrown if target execution fails.
 */
public static DataBag fromMethodsToBag(Object anObject)
        throws NSException, IllegalAccessException, InvocationTargetException {
    DataField dataField;
    BeanField beanField;
    boolean isPublicAccess, isAnnotationPresent;

    if (anObject == null)
        throw new NSException("Object is null");

    DataBag dataBag = new DataBag(anObject.toString());
    Class<?> objClass = anObject.getClass();
    Method[] methodArray = objClass.getDeclaredMethods();
    for (Method objMethod : methodArray) {
        isPublicAccess = Modifier.isPublic(objMethod.getModifiers());
        isAnnotationPresent = objMethod.isAnnotationPresent(BeanField.class);
        if ((isAnnotationPresent) && (isPublicAccess)) {
            beanField = objMethod.getAnnotation(BeanField.class);
            dataField = reflectMethod(anObject, beanField, objMethod);
            dataBag.add(dataField);
        }
    }

    return dataBag;
}

From source file:com.opensymphony.xwork2.util.AnnotationUtils.java

/**
 * Adds all methods with the specified Annotation of class clazz and its superclasses to allFields
 *
 * @param annotationClass the {@link Annotation}s to find
 * @param clazz The {@link Class} to inspect
 * @param allMethods list of all methods
 *//*from   w  w w.j a  v a2  s. c  o  m*/
public static void addAllMethods(Class<? extends Annotation> annotationClass, Class clazz,
        List<Method> allMethods) {

    if (clazz == null) {
        return;
    }

    Method[] methods = clazz.getDeclaredMethods();

    for (Method method : methods) {
        Annotation ann = method.getAnnotation(annotationClass);
        if (ann != null) {
            allMethods.add(method);
        }
    }
    addAllMethods(annotationClass, clazz.getSuperclass(), allMethods);
}

From source file:com.github.itoshige.testrail.store.SyncManager.java

/**
 * add new test method in testrail and caseStore.
 * //  w ww .j  a v  a  2s. co m
 * @param sectionId
 * @param testClass
 */
private static void addNewTestMethod(String sectionId, final Class<?> testClass) {
    for (final Method method : TestRailUnitUtil.getDeclaredTestMethods(testClass.getDeclaredMethods())) {
        String caseId = "";
        try {
            caseId = CaseStore.getIns().getCaseId(new CaseStoreKey(sectionId, method.getName()));
        } catch (TestRailUnitException e) {
        }

        if (needToAddTestMethod(caseId, method)) {
            String title = method.getName();
            JSONObject createdCase = TestRailClient.addCase(sectionId, new CaseModel(title));
            CaseStore.getIns().add(createdCase, sectionId, title);
        }
    }
}