/** * Private constructor to share common code between impl-based delegate and reference-based delegate * (cannot use method such as init() to share common code, due the use of final fields). * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param interceptor the delegation advice as {@link IntroductionInterceptor} */ private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { this.advice = interceptor; this.introducedInterface = interfaceType; // Excludes methods implemented. ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); ClassFilter exclusion = (clazz -> !this.introducedInterface.isAssignableFrom(clazz)); this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); }
/** * Set the AspectJ type pattern to match. * <p>Examples include: * <code class="code"> * org.springframework.beans.* * </code> * This will match any class or interface in the given package. * <code class="code"> * org.springframework.beans.ITestBean+ * </code> * This will match the {@code ITestBean} interface and any class * that implements it. * <p>These conventions are established by AspectJ, not Spring AOP. * @param typePattern the type pattern that AspectJ weaver should parse */ public void setTypePattern(String typePattern) { Assert.notNull(typePattern, "Type pattern must not be null"); this.typePattern = typePattern; this.aspectJTypePatternMatcher = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution(). parseTypePattern(replaceBooleanOperators(typePattern)); }
/** * Create a fully configured {@link TypePatternClassFilter} using the * given type pattern. * @param typePattern the type pattern that AspectJ weaver should parse */ public TypePatternClassFilter(String typePattern) { setTypePattern(typePattern); }
@Test(expected = IllegalStateException.class) public void testInvocationOfMatchesMethodBlowsUpWhenNoTypePatternHasBeenSet() throws Exception { new TypePatternClassFilter().matches(String.class); }
@Test public void testAndOrNotReplacement() { TypePatternClassFilter tpcf = new TypePatternClassFilter("java.lang.Object or java.lang.String"); assertFalse("matches Number",tpcf.matches(Number.class)); assertTrue("matches Object",tpcf.matches(Object.class)); assertTrue("matchesString",tpcf.matches(String.class)); tpcf = new TypePatternClassFilter("java.lang.Number+ and java.lang.Float"); assertTrue("matches Float",tpcf.matches(Float.class)); assertFalse("matches Double",tpcf.matches(Double.class)); tpcf = new TypePatternClassFilter("java.lang.Number+ and not java.lang.Float"); assertFalse("matches Float",tpcf.matches(Float.class)); assertTrue("matches Double",tpcf.matches(Double.class)); }
@Test(expected = IllegalArgumentException.class) public void testInvalidPattern() { // should throw - pattern must be recognized as invalid new TypePatternClassFilter("-"); }
@Test public void testSubclassMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class)); }
/** * Create a fully configured {@link TypePatternClassFilter} using the * given type pattern. * @param typePattern the type pattern that AspectJ weaver should parse * @throws IllegalArgumentException if the supplied {@code typePattern} is {@code null} * or is recognized as invalid */ public TypePatternClassFilter(String typePattern) { setTypePattern(typePattern); }
/** * Set the AspectJ type pattern to match. * <p>Examples include: * <code class="code"> * org.springframework.beans.* * </code> * This will match any class or interface in the given package. * <code class="code"> * org.springframework.beans.ITestBean+ * </code> * This will match the {@code ITestBean} interface and any class * that implements it. * <p>These conventions are established by AspectJ, not Spring AOP. * @param typePattern the type pattern that AspectJ weaver should parse * @throws IllegalArgumentException if the supplied {@code typePattern} is {@code null} * or is recognized as invalid */ public void setTypePattern(String typePattern) { Assert.notNull(typePattern, "Type pattern must not be null"); this.typePattern = typePattern; this.aspectJTypePatternMatcher = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution(). parseTypePattern(replaceBooleanOperators(typePattern)); }
@Test(expected = IllegalArgumentException.class) public void testSetTypePatternWithNullArgument() throws Exception { new TypePatternClassFilter(null); }
@Test public void testValidPatternMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(IOther.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class)); }
/** * Create a fully configured {@link TypePatternClassFilter} using the * given type pattern. * @param typePattern the type pattern that AspectJ weaver should parse */ public TypePatternClassFilter(String typePattern) { setTypePattern(typePattern); }
/** * Set the AspectJ type pattern to match. * <p>Examples include: * <code class="code"> * org.springframework.beans.* * </code> * This will match any class or interface in the given package. * <code class="code"> * org.springframework.beans.ITestBean+ * </code> * This will match the {@code ITestBean} interface and any class * that implements it. * <p>These conventions are established by AspectJ, not Spring AOP. * @param typePattern the type pattern that AspectJ weaver should parse */ public void setTypePattern(String typePattern) { Assert.notNull(typePattern, "Type pattern must not be null"); this.typePattern = typePattern; this.aspectJTypePatternMatcher = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution(). parseTypePattern(replaceBooleanOperators(typePattern)); }
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default:
/** * Private constructor to share common code between impl-based delegate and reference-based delegate * (cannot use method such as init() to share common code, due the use of final fields). * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param interceptor the delegation advice as {@link IntroductionInterceptor} */ private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { this.advice = interceptor; this.introducedInterface = interfaceType; // Excludes methods implemented. ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); ClassFilter exclusion = (clazz -> !this.introducedInterface.isAssignableFrom(clazz)); this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); }
/** * Private constructor to share common code between impl-based delegate and reference-based delegate * (cannot use method such as init() to share common code, due the use of final fields) * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param interceptor the delegation advice as {@link IntroductionInterceptor} */ private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { this.advice = interceptor; this.introducedInterface = interfaceType; // Excludes methods implemented. ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); ClassFilter exclusion = new ClassFilter() { @Override public boolean matches(Class<?> clazz) { return !introducedInterface.isAssignableFrom(clazz); } }; this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); }
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default:
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default: