Here you can find the source of getMethodsAnnotatedWith(Object target, Class extends Annotation> annotation)
public static Collection<Method> getMethodsAnnotatedWith(Object target, Class<? extends Annotation> annotation)
//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; } }