package nl.hsac.fitnesse.slim.interaction;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ReflectionHelper {
    private ReflectionHelper() {}

    public static Set<String> validateMethodNames(Class<?> clazz, String... names) {
        HashSet<String> result = new HashSet<String>(Arrays.asList(names));
        Method[] allMethods = clazz.getMethods();
        List<String> methodsNotMentioned = new ArrayList<String>(allMethods.length);
        for (Method method : allMethods) {
            methodsNotMentioned.add(method.getName());
        }
        List<String> notFound = new ArrayList<String>(0);
        for (String methodName : result) {
            if (!methodsNotMentioned.contains(methodName)) {
                notFound.add(methodName);
            } else {
                methodsNotMentioned.remove(methodName);
            }
        }
        if (!notFound.isEmpty()) {
            throw new RuntimeException("Unable to locate methods: " + notFound);
        }
        return result;
    }
}

@@ -37,16 +37,56 @@
 ction;%0A%0A
+import java.lang.annotation.Annotation;%0A
 import j
@@ -1166,10 +1166,615 @@
 ;%0A    %7D%0A
+%09%0A%09public static List%3CMethod%3E getMethodsAnnotatedWith(final Class%3C?%3E type, final Class%3C? extends Annotation%3E annotation) %7B%0A%09    final List%3CMethod%3E methods = new ArrayList%3CMethod%3E();%0A%09    Class%3C?%3E klass = type;%0A%09    while (klass != Object.class) %7B%0A%09        final List%3CMethod%3E allMethods = new ArrayList%3CMethod%3E(Arrays.asList(klass.getDeclaredMethods()));       %0A%09        for (final Method method : allMethods) %7B%0A%09            if (method.isAnnotationPresent(annotation)) %7B%0A%09                methods.add(method);%0A%09            %7D%0A%09        %7D%0A%09        klass = klass.getSuperclass();%0A%09    %7D%0A%09    return methods;%0A%09%7D%0A
 %7D%0A

Add helper method getMethodsAnnotatedWith