/** * Apply an intersection with the given MethodMatcher. * @param other the MethodMatcher to apply an intersection with * @return this composable pointcut (for call chaining) */ public ComposablePointcut intersection(MethodMatcher other) { this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other); return this; }
/** * Apply a union with the given MethodMatcher. * @param other the MethodMatcher to apply a union with * @return this composable pointcut (for call chaining) */ public ComposablePointcut union(MethodMatcher other) { this.methodMatcher = MethodMatchers.union(this.methodMatcher, other); return this; }
/** * Apply an intersection with the given Pointcut. * @param other the Pointcut to apply an intersection with * @return this composable pointcut (for call chaining) */ public ComposablePointcut intersection(Pointcut other) { this.classFilter = ClassFilters.intersection(this.classFilter, other.getClassFilter()); this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other.getMethodMatcher()); return this; }
/** * Apply a union with the given Pointcut. * <p>Note that for a Pointcut union, methods will only match if their * original ClassFilter (from the originating Pointcut) matches as well. * MethodMatchers and ClassFilters from different Pointcuts will never * get interleaved with each other. * @param other the Pointcut to apply a union with * @return this composable pointcut (for call chaining) */ public ComposablePointcut union(Pointcut other) { this.methodMatcher = MethodMatchers.union( this.methodMatcher, this.classFilter, other.getMethodMatcher(), other.getClassFilter()); this.classFilter = ClassFilters.union(this.classFilter, other.getClassFilter()); return this; }
@Override public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) { return (matchesClass1(targetClass) && MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions)) || (matchesClass2(targetClass) && MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions)); } }
/** * Build a 'safe' pointcut that excludes the AspectJ advice method itself. * @return a composable pointcut that builds on the original AspectJ expression pointcut * @see #getPointcut() */ public final Pointcut buildSafePointcut() { Pointcut pc = getPointcut(); MethodMatcher safeMethodMatcher = MethodMatchers.intersection( new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher()); return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher); }
@Test public void testUnionEquals() { MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE); MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher(); assertTrue(first.equals(second)); assertTrue(second.equals(first)); }
@Override public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) { return (matchesClass1(targetClass) && MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions)) || (matchesClass2(targetClass) && MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions)); } }
@Test public void testDynamicAndStaticMethodMatcherIntersection() throws Exception { MethodMatcher mm1 = MethodMatcher.TRUE; MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches(); MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2); assertTrue("Intersection is a dynamic matcher", intersection.isRuntime()); assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class)); assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))); // Knock out dynamic part intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch()); assertTrue("Intersection is a dynamic matcher", intersection.isRuntime()); assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class)); assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))); }
@Test public void testStaticMethodMatcherUnion() throws Exception { MethodMatcher getterMatcher = new StartsWithMatcher("get"); MethodMatcher setterMatcher = new StartsWithMatcher("set"); MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher); assertFalse("Union is a static matcher", union.isRuntime()); assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class)); assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class)); assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class)); }
@Test public void testSingle() throws Exception { MethodMatcher defaultMm = MethodMatcher.TRUE; assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)); assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)); defaultMm = MethodMatchers.intersection(defaultMm, new StartsWithMatcher("get")); assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)); assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)); }
/** * Apply a union with the given MethodMatcher. * @param other the MethodMatcher to apply a union with * @return this composable pointcut (for call chaining) */ public ComposablePointcut union(MethodMatcher other) { this.methodMatcher = MethodMatchers.union(this.methodMatcher, other); return this; }
/** * Apply an intersection with the given MethodMatcher. * @param other the MethodMatcher to apply an intersection with * @return this composable pointcut (for call chaining) */ public ComposablePointcut intersection(MethodMatcher other) { this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other); return this; }
/** * Apply a union with the given MethodMatcher. * @param other the MethodMatcher to apply a union with * @return this composable pointcut (for call chaining) */ public ComposablePointcut union(MethodMatcher other) { this.methodMatcher = MethodMatchers.union(this.methodMatcher, other); return this; }
@Override public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) { return (matchesClass1(targetClass) && MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions)) || (matchesClass2(targetClass) && MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions)); }
/** * Apply an intersection with the given MethodMatcher. * @param other the MethodMatcher to apply an intersection with * @return this composable pointcut (for call chaining) */ public ComposablePointcut intersection(MethodMatcher other) { this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other); return this; }
public ComposablePointcut union(MethodMatcher mm) { this.methodMatcher = MethodMatchers.union(this.methodMatcher, mm); return this; }