Autowiring of generic types

Includes revisions of MethodParameter and DependencyDescriptor (in particular towards a reference to the containing class). Also refines several ResolvableType method signatures.

Issue: SPR-9965
This commit is contained in:
Juergen Hoeller
2013-10-15 00:11:23 +02:00
parent 74794190a5
commit 3bd6dfe047
19 changed files with 874 additions and 351 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.
@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.MethodParameter;
@@ -72,15 +73,6 @@ public class HandlerMethod {
this.parameters = initMethodParameters();
}
private MethodParameter[] initMethodParameters() {
int count = this.bridgedMethod.getParameterTypes().length;
MethodParameter[] result = new MethodParameter[count];
for (int i = 0; i < count; i++) {
result[i] = new HandlerMethodParameter(i);
}
return result;
}
/**
* Create an instance from a bean instance, method name, and parameter types.
* @throws NoSuchMethodException when the method cannot be found
@@ -138,6 +130,16 @@ public class HandlerMethod {
this.parameters = handlerMethod.parameters;
}
private MethodParameter[] initMethodParameters() {
int count = this.bridgedMethod.getParameterTypes().length;
MethodParameter[] result = new MethodParameter[count];
for (int i = 0; i < count; i++) {
result[i] = new HandlerMethodParameter(i);
}
return result;
}
/**
* Returns the bean for this handler method.
*/
@@ -157,9 +159,8 @@ public class HandlerMethod {
* Note that if the bean type is a CGLIB-generated class, the original, user-defined class is returned.
*/
public Class<?> getBeanType() {
Class<?> clazz = (this.bean instanceof String)
? this.beanFactory.getType((String) this.bean) : this.bean.getClass();
Class<?> clazz = (this.bean instanceof String ?
this.beanFactory.getType((String) this.bean) : this.bean.getClass());
return ClassUtils.getUserClass(clazz);
}
@@ -223,12 +224,12 @@ public class HandlerMethod {
}
@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o != null && o instanceof HandlerMethod) {
HandlerMethod other = (HandlerMethod) o;
if (obj != null && obj instanceof HandlerMethod) {
HandlerMethod other = (HandlerMethod) obj;
return this.bean.equals(other.bean) && this.method.equals(other.method);
}
return false;
@@ -236,25 +237,26 @@ public class HandlerMethod {
@Override
public int hashCode() {
return 31 * this.bean.hashCode() + this.method.hashCode();
return this.bean.hashCode() * 31 + this.method.hashCode();
}
@Override
public String toString() {
return method.toGenericString();
return this.method.toGenericString();
}
/**
* A MethodParameter with HandlerMethod-specific behavior.
*/
private class HandlerMethodParameter extends MethodParameter {
protected HandlerMethodParameter(int index) {
public HandlerMethodParameter(int index) {
super(HandlerMethod.this.bridgedMethod, index);
}
@Override
public Class<?> getDeclaringClass() {
public Class<?> getContainingClass() {
return HandlerMethod.this.getBeanType();
}
@@ -264,6 +266,7 @@ public class HandlerMethod {
}
}
/**
* A MethodParameter for a HandlerMethod return type based on an actual return value.
*/
@@ -278,7 +281,7 @@ public class HandlerMethod {
@Override
public Class<?> getParameterType() {
return (this.returnValue != null) ? this.returnValue.getClass() : super.getParameterType();
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
}
}