/** * Match all methods that <b>either</b> (or both) of the given pointcuts matches. * @param pc1 the first Pointcut * @param pc2 the second Pointcut * @return a distinct Pointcut that matches all methods that either * of the given Pointcuts matches */ public static Pointcut union(Pointcut pc1, Pointcut pc2) { return new ComposablePointcut(pc1).union(pc2); }
/** * Match all methods that <b>both</b> the given pointcuts match. * @param pc1 the first Pointcut * @param pc2 the second Pointcut * @return a distinct Pointcut that matches all methods that both * of the given Pointcuts match */ public static Pointcut intersection(Pointcut pc1, Pointcut pc2) { return new ComposablePointcut(pc1).intersection(pc2); }
protected Pointcut buildPointcut() { Pointcut cpc = new AnnotationMatchingPointcut(Stat.class, true); Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(Stat.class); ComposablePointcut result = new ComposablePointcut(cpc).union(mpc); return result; }
/** * 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); }
/** * Calculate a pointcut for the given async annotation types, if any. * @param asyncAnnotationTypes the async annotation types to introspect * @return the applicable Pointcut object, or {@code null} if none */ protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) { ComposablePointcut result = null; for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) { Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true); Pointcut mpc = new AnnotationMatchingPointcut(null, asyncAnnotationType, true); if (result == null) { result = new ComposablePointcut(cpc); } else { result.union(cpc); } result = result.union(mpc); } return (result != null ? result : Pointcut.TRUE); }
/** * Calculate a pointcut for the given retry annotation types, if any. * * @param retryAnnotationTypes the retry annotation types to introspect * @return the applicable Pointcut object, or {@code null} if none */ protected Pointcut buildPointcut(Set<Class<? extends Annotation>> retryAnnotationTypes) { ComposablePointcut result = null; for (Class<? extends Annotation> retryAnnotationType : retryAnnotationTypes) { Pointcut filter = new AnnotationClassOrMethodPointcut(retryAnnotationType); if (result == null) { result = new ComposablePointcut(filter); } else { result.union(filter); } } return result; }
@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)); }
/** * Calculate a pointcut for the given async annotation types, if any. * @param asyncAnnotationTypes the async annotation types to introspect * @return the applicable Pointcut object, or {@code null} if none */ protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) { ComposablePointcut result = null; for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) { Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true); Pointcut mpc = new AnnotationMatchingPointcut(null, asyncAnnotationType, true); if (result == null) { result = new ComposablePointcut(cpc); } else { result.union(cpc); } result = result.union(mpc); } return (result != null ? result : Pointcut.TRUE); }
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default:
@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 testEqualsAndHashCode() throws Exception { ComposablePointcut pc1 = new ComposablePointcut(); ComposablePointcut pc2 = new ComposablePointcut(); assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); pc1.intersection(GETTER_METHOD_MATCHER); assertFalse(pc1.equals(pc2)); assertFalse(pc1.hashCode() == pc2.hashCode()); pc2.intersection(GETTER_METHOD_MATCHER); assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); pc1.union(GET_AGE_METHOD_MATCHER); pc2.union(GET_AGE_METHOD_MATCHER); assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); }
private Pointcut buildPointcut() { ComposablePointcut result = null; for (Class<? extends Annotation> publisherAnnotationType : this.annotations) { Pointcut mpc = new MetaAnnotationMatchingPointcut(null, publisherAnnotationType); if (result == null) { result = new ComposablePointcut(mpc); } else { result.union(mpc); } } return result; }
@Test public void testUnionMethodMatcher() { // Matches the getAge() method in any class ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER); assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.union(GETTER_METHOD_MATCHER); // Should now match all getter methods assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.union(ABSQUATULATE_METHOD_MATCHER); // Should now match absquatulate() as well assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); // But it doesn't match everything assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class)); }
@Test public void testIntersectionMethodMatcher() { ComposablePointcut pc = new ComposablePointcut(); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.intersection(GETTER_METHOD_MATCHER); assertFalse(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.intersection(GET_AGE_METHOD_MATCHER); // Use the Pointcuts matches method assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); }
protected Pointcut buildPointcut() { Pointcut cpc = new AnnotationMatchingPointcut(Stat.class, true); Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(Stat.class); ComposablePointcut result = new ComposablePointcut(cpc).union(mpc); return result; }
@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)); }
private Pointcut buildPointcut() { ComposablePointcut result = null; for (Class<? extends Annotation> publisherAnnotationType : this.publisherAnnotationTypes) { Pointcut cpc = new MetaAnnotationMatchingPointcut(publisherAnnotationType, true); Pointcut mpc = new MetaAnnotationMatchingPointcut(null, publisherAnnotationType); if (result == null) { result = new ComposablePointcut(cpc).union(mpc); } else { result.union(cpc).union(mpc); } } return result; }
/** * Match all methods that <b>both</b> the given pointcuts match. * @param pc1 the first Pointcut * @param pc2 the second Pointcut * @return a distinct Pointcut that matches all methods that both * of the given Pointcuts match */ public static Pointcut intersection(Pointcut pc1, Pointcut pc2) { return new ComposablePointcut(pc1).intersection(pc2); }
private Pointcut buildPointcut() { ComposablePointcut result = null; for (Class<? extends Annotation> publisherAnnotationType : this.annotations) { Pointcut mpc = new MetaAnnotationMatchingPointcut(null, publisherAnnotationType); if (result == null) { result = new ComposablePointcut(mpc); } else { result.union(mpc); } } return result; }
public Pointcut getIntersectionPointcut() { ComposablePointcut cp = new ComposablePointcut(); Pointcut pt1 = new ControlFlowPointcut(WaiterDelegate.class, "service"); NameMatchMethodPointcut pt2 = new NameMatchMethodPointcut(); pt2.addMethodName("greetTo"); return cp.intersection(pt1).intersection((Pointcut) pt2); } }