1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import org .springframework .beans .factory .BeanFactory ;
29
29
import org .springframework .beans .factory .InjectionPoint ;
30
30
import org .springframework .beans .factory .NoUniqueBeanDefinitionException ;
31
- import org .springframework .core .GenericCollectionTypeResolver ;
32
31
import org .springframework .core .GenericTypeResolver ;
33
32
import org .springframework .core .MethodParameter ;
34
33
import org .springframework .core .ParameterNameDiscoverer ;
@@ -63,6 +62,8 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
63
62
64
63
private Class <?> containingClass ;
65
64
65
+ private volatile ResolvableType resolvableType ;
66
+
66
67
67
68
/**
68
69
* Create a new descriptor for a method or constructor parameter.
@@ -214,6 +215,7 @@ public Object resolveCandidate(String beanName, Class<?> requiredType, BeanFacto
214
215
*/
215
216
public void increaseNestingLevel () {
216
217
this .nestingLevel ++;
218
+ this .resolvableType = null ;
217
219
if (this .methodParameter != null ) {
218
220
this .methodParameter .increaseNestingLevel ();
219
221
}
@@ -227,6 +229,7 @@ public void increaseNestingLevel() {
227
229
*/
228
230
public void setContainingClass (Class <?> containingClass ) {
229
231
this .containingClass = containingClass ;
232
+ this .resolvableType = null ;
230
233
if (this .methodParameter != null ) {
231
234
GenericTypeResolver .resolveParameterType (this .methodParameter , containingClass );
232
235
}
@@ -237,8 +240,12 @@ public void setContainingClass(Class<?> containingClass) {
237
240
* @since 4.0
238
241
*/
239
242
public ResolvableType getResolvableType () {
240
- return (this .field != null ? ResolvableType .forField (this .field , this .nestingLevel , this .containingClass ) :
241
- ResolvableType .forMethodParameter (this .methodParameter ));
243
+ if (this .resolvableType == null ) {
244
+ this .resolvableType = (this .field != null ?
245
+ ResolvableType .forField (this .field , this .nestingLevel , this .containingClass ) :
246
+ ResolvableType .forMethodParameter (this .methodParameter ));
247
+ }
248
+ return this .resolvableType ;
242
249
}
243
250
244
251
/**
@@ -324,31 +331,37 @@ else if (type instanceof ParameterizedType) {
324
331
/**
325
332
* Determine the generic element type of the wrapped Collection parameter/field, if any.
326
333
* @return the generic type, or {@code null} if none
334
+ * @deprecated as of 4.3.6, in favor of direct {@link ResolvableType} usage
327
335
*/
336
+ @ Deprecated
328
337
public Class <?> getCollectionType () {
329
338
return (this .field != null ?
330
- GenericCollectionTypeResolver .getCollectionFieldType (this .field , this .nestingLevel ) :
331
- GenericCollectionTypeResolver .getCollectionParameterType (this .methodParameter ));
339
+ org . springframework . core . GenericCollectionTypeResolver .getCollectionFieldType (this .field , this .nestingLevel ) :
340
+ org . springframework . core . GenericCollectionTypeResolver .getCollectionParameterType (this .methodParameter ));
332
341
}
333
342
334
343
/**
335
344
* Determine the generic key type of the wrapped Map parameter/field, if any.
336
345
* @return the generic type, or {@code null} if none
346
+ * @deprecated as of 4.3.6, in favor of direct {@link ResolvableType} usage
337
347
*/
348
+ @ Deprecated
338
349
public Class <?> getMapKeyType () {
339
350
return (this .field != null ?
340
- GenericCollectionTypeResolver .getMapKeyFieldType (this .field , this .nestingLevel ) :
341
- GenericCollectionTypeResolver .getMapKeyParameterType (this .methodParameter ));
351
+ org . springframework . core . GenericCollectionTypeResolver .getMapKeyFieldType (this .field , this .nestingLevel ) :
352
+ org . springframework . core . GenericCollectionTypeResolver .getMapKeyParameterType (this .methodParameter ));
342
353
}
343
354
344
355
/**
345
356
* Determine the generic value type of the wrapped Map parameter/field, if any.
346
357
* @return the generic type, or {@code null} if none
358
+ * @deprecated as of 4.3.6, in favor of direct {@link ResolvableType} usage
347
359
*/
360
+ @ Deprecated
348
361
public Class <?> getMapValueType () {
349
362
return (this .field != null ?
350
- GenericCollectionTypeResolver .getMapValueFieldType (this .field , this .nestingLevel ) :
351
- GenericCollectionTypeResolver .getMapValueParameterType (this .methodParameter ));
363
+ org . springframework . core . GenericCollectionTypeResolver .getMapValueFieldType (this .field , this .nestingLevel ) :
364
+ org . springframework . core . GenericCollectionTypeResolver .getMapValueParameterType (this .methodParameter ));
352
365
}
353
366
354
367
0 commit comments