I'm trying to convert this ControllerAnnotationHelper into a service, and I'm getting weird issues.
No signature of method AnnotationScannerService.findAnnotatedClosures() is applicable for argument types:
(java.lang.Class, java.lang.Class) values: [class MyController, interface MyAnnotationRequired]
Here's the original method:
private static Map<String, List<Class>> findAnnotatedClosures(
Class clazz, Class... annotationClasses) {
def map = [:]
for (field in clazz.declaredFields) {
def fieldAnnotations = []
for (annotationClass in annotationClasses) {
if (field.isAnnotationPresent(annotationClass)) {
fieldAnnotations << annotationClass
}
}
if (fieldAnnotations) {
map[field.name] = fieldAnnotations
}
}
return map
}
and mine:
protected Map<String, List<Class>> findAnnotatedClosures(Class clazz, Class... annotationClasses) {
def map = [:]
for (field in clazz.declaredFields) {
def fieldAnnotations = []
for (annotationClass in annotationClasses) {
if (field.isAnnotationPresent(annotationClass)) {
fieldAnnotations << annotationClass
}
}
if (fieldAnnotations) {
map[field.name] = fieldAnnotations
}
}
return map
}
With invocation:
public void test_findAnnotatedClosures() {
Map<String, List<Class>> annotatedClosures =
annotationScannerService.findAnnotatedClosures(MyController, MyRequiredAnnotation)
}
How can I declare this method such that I can call it with a controller class and the class of various annotation interfaces?
grails clean
, but it wasprotected
so I could hit it from integration/unit tests. I'll try removing the static modifier/cleaning/public access tomorrow. It may be worth noting that I'm running 1.3.7, so perhaps this is a 1.7.x issue. – Stefan Kendall Sep 9 '11 at 3:07