Java Reflection Method Get from Object getMethodsAnnotatedWith(Object target, Class annotation)

Here you can find the source of getMethodsAnnotatedWith(Object target, Class annotation)

Description

get Methods Annotated With

License

Open Source License

Declaration

public static Collection<Method> getMethodsAnnotatedWith(Object target,
            Class<? extends Annotation> annotation) 

Method Source Code

//package com.java2s;
/**//from   ww  w .j  a  va2  s .  c  o m
 * This file is part of Semtinel (http://www.semtinel.org).
 * Copyright (c) 2007-2010 Kai Eckert (http://www.kaiec.org).
 *
 * Semtinel is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Semtinel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Semtinel. If not, see <http://www.gnu.org/licenses/>.
 */

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static Collection<Method> getMethodsAnnotatedWith(Object target,
            Class<? extends Annotation> annotation) {
        Set<Method> methods = new HashSet<Method>();

        for (Method method : target.getClass().getDeclaredMethods()) {
            if (method.isAnnotationPresent(annotation)) {
                methods.add(method);
            }
        }

        return methods;
    }
}

Related

  1. getMethods(Class objectClass, Class annotationClass)
  2. getMethods(Object instance, String name, Class[] arguments, boolean isPrefix)
  3. getMethods(Object obj, boolean hasParent)
  4. getMethods(Object obj, int cmpModifier, String prefix)
  5. getMethodsAnnotatedWith(Class ann, Object o)
  6. getMethodsAnnotatedWithValue(Class anno, Object o, String name, Object value)
  7. getMethodsByStartsWithName(String name, Object o)
  8. getMethodsForObject(Object o2, String[] passedMethods)
  9. getMethodsIncludingHierarchy(Object comp, Class annotation)