@Override public boolean matches(Class<?> clazz) { for (ClassFilter filter : this.filters) { if (!filter.matches(clazz)) { return false; } } return true; }
@Override public boolean matches(Class<?> clazz) { for (ClassFilter filter : this.filters) { if (filter.matches(clazz)) { return true; } } return false; }
@Override protected boolean matchesClass1(Class<?> targetClass) { return this.cf1.matches(targetClass); }
@Override protected boolean matchesClass2(Class<?> targetClass) { return this.cf2.matches(targetClass); }
/** * Determine whether the Advisors contain matching introductions. */ private static boolean hasMatchingIntroductions(Advisor[] advisors, Class<?> actualClass) { for (Advisor advisor : advisors) { if (advisor instanceof IntroductionAdvisor) { IntroductionAdvisor ia = (IntroductionAdvisor) advisor; if (ia.getClassFilter().matches(actualClass)) { return true; } } } return false; }
private void assertMatchesTestBeanClass(ClassFilter classFilter) { assertTrue("Expression should match TestBean class", classFilter.matches(TestBean.class)); }
@Test public void testUnion() { assertTrue(exceptionFilter.matches(RuntimeException.class)); assertFalse(exceptionFilter.matches(TestBean.class)); assertFalse(itbFilter.matches(Exception.class)); assertTrue(itbFilter.matches(TestBean.class)); ClassFilter union = ClassFilters.union(exceptionFilter, itbFilter); assertTrue(union.matches(RuntimeException.class)); assertTrue(union.matches(TestBean.class)); }
@Test public void testIntersection() { assertTrue(exceptionFilter.matches(RuntimeException.class)); assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class)); ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter); assertFalse(intersection.matches(RuntimeException.class)); assertFalse(intersection.matches(TestBean.class)); assertTrue(intersection.matches(NestedRuntimeException.class)); }
/** * Can the given advisor apply at all on the given class? * <p>This is an important test as it can be used to optimize out a advisor for a class. * This version also takes into account introductions (for IntroductionAwareMethodMatchers). * @param advisor the advisor to check * @param targetClass class we're testing * @param hasIntroductions whether or not the advisor chain for this bean includes * any introductions * @return whether the pointcut can apply on any method */ public static boolean canApply(Advisor advisor, Class<?> targetClass, boolean hasIntroductions) { if (advisor instanceof IntroductionAdvisor) { return ((IntroductionAdvisor) advisor).getClassFilter().matches(targetClass); } else if (advisor instanceof PointcutAdvisor) { PointcutAdvisor pca = (PointcutAdvisor) advisor; return canApply(pca.getPointcut(), targetClass, hasIntroductions); } else { // It doesn't have a pointcut so we assume it applies. return true; } }
@Override public boolean matches(Method method, Class<?> targetClass) { return getClassFilter().matches(targetClass) || this.methodResolver.matches(method, targetClass); }
if (!pc.getClassFilter().matches(targetClass)) { return false;
/** * Perform the least expensive check for a pointcut match. * @param pointcut the pointcut to match * @param method the candidate method * @param targetClass the target class * @param args arguments to the method * @return whether there's a runtime match */ public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) { Assert.notNull(pointcut, "Pointcut must not be null"); if (pointcut == Pointcut.TRUE) { return true; } if (pointcut.getClassFilter().matches(targetClass)) { // Only check if it gets past first hurdle. MethodMatcher mm = pointcut.getMethodMatcher(); if (mm.matches(method, targetClass)) { // We may need additional runtime (argument) check. return (!mm.isRuntime() || mm.matches(method, targetClass, args)); } } return false; }
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) { MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); boolean match; if (config.isPreFiltered() || ia.getClassFilter().matches(actualClass)) { Interceptor[] interceptors = registry.getInterceptors(advisor); interceptorList.addAll(Arrays.asList(interceptors));
@Test public void testFilterByClass() throws NoSuchMethodException { ComposablePointcut pc = new ComposablePointcut(); assertTrue(pc.getClassFilter().matches(Object.class)); ClassFilter cf = new RootClassFilter(Exception.class); pc.intersection(cf); assertFalse(pc.getClassFilter().matches(Object.class)); assertTrue(pc.getClassFilter().matches(Exception.class)); pc.intersection(new RootClassFilter(NestedRuntimeException.class)); assertFalse(pc.getClassFilter().matches(Exception.class)); assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class)); assertFalse(pc.getClassFilter().matches(String.class)); pc.union(new RootClassFilter(String.class)); assertFalse(pc.getClassFilter().matches(Exception.class)); assertTrue(pc.getClassFilter().matches(String.class)); assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class)); }
@Test public void testMatchAll() throws NoSuchMethodException { Pointcut pc = new ComposablePointcut(); assertTrue(pc.getClassFilter().matches(Object.class)); assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class)); }
@Test public void testPerTarget() throws SecurityException, NoSuchMethodException { AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl( ajexp, TestBean.class.getMethod("getAge"), af, new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"), 1, "someBean"); assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut()); assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut); assertTrue(ajpa.isPerInstance()); assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class)); assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches( TestBean.class.getMethod("getAge"), TestBean.class)); assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches( TestBean.class.getMethod("getSpouse"), TestBean.class)); }
public boolean matches(Class clazz) { for (int i = 0; i < filters.length; i++) { if (filters[i].matches(clazz)) { return true; } } return false; } }
public boolean matches(Class clazz) { for (int i = 0; i < filters.length; i++) { if (!filters[i].matches(clazz)) { return false; } } return true; } }
@Override public boolean matches(Class<?> clazz) { for (ClassFilter filter : this.filters) { if (!filter.matches(clazz)) { return false; } } return true; }
@Override public boolean matches(Method method, Class<?> targetClass) { return getClassFilter().matches(targetClass) || this.methodResolver.matches(method, targetClass); }