Minor optimizations in factory method handling

Optimized getTypeForFactoryMethod's implementation for non-generic factory methods, and reduced calls to getResolvedFactoryMethod in order to avoid repeated synchronization. Derived from work around SPR-11034.
This commit is contained in:
Juergen Hoeller
2013-10-27 00:55:02 +02:00
parent 6021822ce4
commit ff9c695599
5 changed files with 39 additions and 54 deletions

View File

@@ -49,9 +49,6 @@ public class AutowireUtilsTests {
Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy",
new Class[] { String.class, Object.class });
// one argument to few
assertNull(
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[]{"enigma"}, getClass().getClassLoader()));
assertEquals(Long.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[] { "enigma", 99L }, getClass().getClassLoader()));

View File

@@ -654,17 +654,13 @@ public class BeanFactoryGenericsTests {
/**
* Tests support for parameterized static {@code factory-method} declarations such as
* Mockito's {@code mock()} method which has the following signature.
*
* <pre>
* {@code
* public static <T> T mock(Class<T> classToMock)
* }
* </pre>
*
* <p>
* See SPR-9493
*
* @since 3.2
*/
@Test
public void parameterizedStaticFactoryMethod() {
@@ -701,7 +697,6 @@ public class BeanFactoryGenericsTests {
rbd.setFactoryBeanName("mocksControl");
rbd.setFactoryMethodName("createMock");
rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class);
bf.registerBeanDefinition("mock", rbd);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
@@ -719,7 +714,6 @@ public class BeanFactoryGenericsTests {
rbd.setFactoryBeanName("mocksControl");
rbd.setFactoryMethodName("createMock");
rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class.getName());
bf.registerBeanDefinition("mock", rbd);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
@@ -737,7 +731,6 @@ public class BeanFactoryGenericsTests {
rbd.setFactoryBeanName("mocksControl");
rbd.setFactoryMethodName("createMock");
rbd.getConstructorArgumentValues().addIndexedArgumentValue(0, Runnable.class);
bf.registerBeanDefinition("mock", rbd);
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
@@ -788,6 +781,7 @@ public class BeanFactoryGenericsTests {
}
}
/**
* Pseudo-implementation of EasyMock's {@code MocksControl} class.
*/
@@ -795,14 +789,10 @@ public class BeanFactoryGenericsTests {
@SuppressWarnings("unchecked")
public <T> T createMock(Class<T> toMock) {
return (T) Proxy.newProxyInstance(
BeanFactoryGenericsTests.class.getClassLoader(),
new Class[] { toMock }, new InvocationHandler() {
return (T) Proxy.newProxyInstance(BeanFactoryGenericsTests.class.getClassLoader(), new Class<?>[] {toMock},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
throw new UnsupportedOperationException("mocked!");
}
});