Polishing

Issue: SPR-11344
This commit is contained in:
Juergen Hoeller 2014-01-22 18:23:59 +01:00
parent c406c56d57
commit d434ef9713
4 changed files with 36 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,9 +19,9 @@ package org.springframework.aop;
import java.lang.reflect.Method;
/**
* A specialized type of MethodMatcher that takes into account introductions when
* matching methods. If there are no introductions on the target class, a method
* matcher may be able to optimize matching more effectively for example.
* A specialized type of {@link MethodMatcher} that takes into account introductions
* when matching methods. If there are no introductions on the target class,
* a method matcher may be able to optimize matching more effectively for example.
*
* @author Adrian Colyer
* @since 2.0
@ -39,6 +39,6 @@ public interface IntroductionAwareMethodMatcher extends MethodMatcher {
* asking is the subject on one or more introductions; {@code false} otherwise
* @return whether or not this method matches statically
*/
boolean matches(Method method, Class targetClass, boolean hasIntroductions);
boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,8 +23,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* Static utility methods for composing
* {@link org.springframework.aop.ClassFilter ClassFilters}.
* Static utility methods for composing {@link ClassFilter ClassFilters}.
*
* @author Rod Johnson
* @author Rob Harrop
@ -96,9 +95,9 @@ public abstract class ClassFilters {
this.filters = filters;
}
public boolean matches(Class clazz) {
for (int i = 0; i < this.filters.length; i++) {
if (this.filters[i].matches(clazz)) {
public boolean matches(Class<?> clazz) {
for (ClassFilter filter : this.filters) {
if (filter.matches(clazz)) {
return true;
}
}
@ -130,9 +129,9 @@ public abstract class ClassFilters {
this.filters = filters;
}
public boolean matches(Class clazz) {
for (int i = 0; i < this.filters.length; i++) {
if (!this.filters[i].matches(clazz)) {
public boolean matches(Class<?> clazz) {
for (ClassFilter filter : this.filters) {
if (!filter.matches(clazz)) {
return false;
}
}

View File

@ -25,12 +25,11 @@ import org.springframework.aop.MethodMatcher;
import org.springframework.util.Assert;
/**
* Static utility methods for composing
* {@link org.springframework.aop.MethodMatcher MethodMatchers}.
* Static utility methods for composing {@link MethodMatcher MethodMatchers}.
*
* <p>A MethodMatcher may be evaluated statically (based on method
* and target class) or need further evaluation dynamically
* (based on arguments at the time of method invocation).
* <p>A MethodMatcher may be evaluated statically (based on method and target
* class) or need further evaluation dynamically (based on arguments at the
* time of method invocation).
*
* @author Rod Johnson
* @author Rob Harrop
@ -88,7 +87,7 @@ public abstract class MethodMatchers {
* asking is the subject on one or more introductions; {@code false} otherwise
* @return whether or not this method matches statically
*/
public static boolean matches(MethodMatcher mm, Method method, Class targetClass, boolean hasIntroductions) {
public static boolean matches(MethodMatcher mm, Method method, Class<?> targetClass, boolean hasIntroductions) {
Assert.notNull(mm, "MethodMatcher must not be null");
return ((mm instanceof IntroductionAwareMethodMatcher &&
((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions)) ||
@ -113,21 +112,21 @@ public abstract class MethodMatchers {
this.mm2 = mm2;
}
public boolean matches(Method method, Class targetClass, boolean hasIntroductions) {
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));
}
public boolean matches(Method method, Class targetClass) {
public boolean matches(Method method, Class<?> targetClass) {
return (matchesClass1(targetClass) && this.mm1.matches(method, targetClass)) ||
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
}
protected boolean matchesClass1(Class targetClass) {
protected boolean matchesClass1(Class<?> targetClass) {
return true;
}
protected boolean matchesClass2(Class targetClass) {
protected boolean matchesClass2(Class<?> targetClass) {
return true;
}
@ -135,7 +134,7 @@ public abstract class MethodMatchers {
return this.mm1.isRuntime() || this.mm2.isRuntime();
}
public boolean matches(Method method, Class targetClass, Object[] args) {
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
}
@ -179,12 +178,12 @@ public abstract class MethodMatchers {
}
@Override
protected boolean matchesClass1(Class targetClass) {
protected boolean matchesClass1(Class<?> targetClass) {
return this.cf1.matches(targetClass);
}
@Override
protected boolean matchesClass2(Class targetClass) {
protected boolean matchesClass2(Class<?> targetClass) {
return this.cf2.matches(targetClass);
}
@ -225,12 +224,12 @@ public abstract class MethodMatchers {
this.mm2 = mm2;
}
public boolean matches(Method method, Class targetClass, boolean hasIntroductions) {
public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) {
return MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) &&
MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions);
}
public boolean matches(Method method, Class targetClass) {
public boolean matches(Method method, Class<?> targetClass) {
return this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass);
}
@ -238,7 +237,7 @@ public abstract class MethodMatchers {
return this.mm1.isRuntime() || this.mm2.isRuntime();
}
public boolean matches(Method method, Class targetClass, Object[] args) {
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
// Because a dynamic intersection may be composed of a static and dynamic part,
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
// it will probably be an unsupported operation.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,16 +34,21 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public final class TargetPointcutSelectionTests {
public TestInterface testImpl1;
public TestInterface testImpl2;
public TestAspect testAspectForTestImpl1;
public TestAspect testAspectForAbstractTestImpl;
public TestInterceptor testInterceptor;
@Before
public void setUp() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
testImpl1 = (TestInterface) ctx.getBean("testImpl1");
testImpl2 = (TestInterface) ctx.getBean("testImpl2");
testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
@ -55,6 +60,7 @@ public final class TargetPointcutSelectionTests {
testInterceptor.count = 0;
}
@Test
public void testTargetSelectionForMatchedType() {
testImpl1.interfaceMethod();