get Annotated Methods - Android java.lang.reflect

Android examples for java.lang.reflect:Annotation

Description

get Annotated Methods

Demo Code

/* /*from ww  w.  j  a v  a2s . c  o  m*/
 * Cleandroid Framework 
 * @author: Douraid Arfaoui <douraid.arfaoui@gmail.com>
 *
 * Copyright (c) 2015, Douraid Arfaoui, or third-party contributors as 
 * indicated by the @author tags or express copyright attribution 
 * statements applied by the authors. 
 * 
 * This copyrighted material is made available to anyone wishing to use, modify, 
 * copy, or redistribute it subject to the terms and conditions of the Apache 2 
 * License, as published by the Apache Software Foundation.  
 * 
 */
//package com.java2s;
import java.lang.annotation.Annotation;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Method> getAnnotatedMethods(Class<?> targetClass,
            Class<? extends Annotation> annotationType) {
        List<Method> methods = new ArrayList<Method>();
        for (Method m : targetClass.getDeclaredMethods()) {
            if (m.isAnnotationPresent(annotationType))
                methods.add(m);
        }
        return methods;
    }
}

Related Tutorials