package org.javasimon.spring;

import org.javasimon.aop.Monitored;
import org.springframework.aop.Pointcut;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;

import java.lang.reflect.Method;

/**
 * Pointcut that identifies methods/classes with the {@link Monitored} annotation.
 *
 * @author Erik van Oosten
 */
public final class MonitoredMeasuringPointcut implements Pointcut {
	/**
	 * @return a class filter that lets all class through.
	 */
	public ClassFilter getClassFilter() {
		return ClassFilter.TRUE;
	}

	/**
	 * @return a method matcher that matches any method that has the {@link Monitored} annotation,
	 *         or is in a class with the {@link Monitored} annotation
	 */
	public MethodMatcher getMethodMatcher() {
		return MonitoredMethodMatcher.INSTANCE;
	}

	private enum MonitoredMethodMatcher implements MethodMatcher {
		INSTANCE;

		public boolean matches(Method method, Class targetClass) {
			return targetClass.isAnnotationPresent(Monitored.class) || method.isAnnotationPresent(Monitored.class);
		}

		public boolean isRuntime() {
			return false;
		}

		public boolean matches(Method method, Class targetClass, Object[] args) {
			throw new UnsupportedOperationException("This is not a runtime method matcher");
		}
	}
}

@@ -35,37 +35,35 @@
 ort 
-org.javasimon.aop.Monitore
+java.lang.reflect.Metho
 d;%0A
+%0A
 impo
@@ -73,36 +73,31 @@
 org.
-springframework.aop.Pointcut
+javasimon.aop.Monitored
 ;%0Aim
@@ -188,40 +188,107 @@
 er;%0A
-%0A
 import 
-java.lang.reflect.Method
+org.springframework.aop.Pointcut;%0Aimport org.springframework.core.annotation.AnnotationUtils
 ;%0A%0A/
@@ -1018,110 +1018,258 @@
 %0A%09%09%09
-return targetClass.isAnnotationPresent(Monitored.class) %7C%7C method.isAnnotationPresent(Monitored.class)
+if (AnnotationUtils.findAnnotation(targetClass, Monitored.class) != null) %7B%0A%09%09%09%09return true;%0A%09%09%09%7D else if (AnnotationUtils.findAnnotation(method, Monitored.class) != null) %7B%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%0A%09%09%09// if nothing matches return false%0A%09%09%09return false
 ;%0A%09%09

fix http://code.google.com/p/javasimon/issues/detail?id=42