Package org.springframework.core
Class Conventions
java.lang.Object
org.springframework.core.Conventions
Provides methods to support various naming and other conventions used
throughout the framework. Mainly for internal use within the framework.
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Rossen Stoyanchev
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
attributeNameToPropertyName
(String attributeName) ConvertString
s in attribute name format (for example, lowercase, hyphens separating words) into property name format (camel-case).static String
getQualifiedAttributeName
(Class<?> enclosingClass, String attributeName) Return an attribute name qualified by the given enclosingClass
.static String
getVariableName
(Object value) Determine the conventional variable name for the suppliedObject
based on its concrete type.static String
getVariableNameForParameter
(MethodParameter parameter) Determine the conventional variable name for the given parameter taking the generic collection type, if any, into account.static String
getVariableNameForReturnType
(Method method) Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account.static String
getVariableNameForReturnType
(Method method, Class<?> resolvedType, Object value) Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account, falling back on the given return value if the method declaration is not specific enough, for example,Object
return type or untyped collection.static String
getVariableNameForReturnType
(Method method, Object value) Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account, falling back on the given actual return value if the method declaration is not specific enough, for example,Object
return type or untyped collection.
-
Method Details
-
getVariableName
Determine the conventional variable name for the suppliedObject
based on its concrete type. The convention used is to return the un-capitalized short name of theClass
, according to JavaBeans property naming rules.For example:
com.myapp.Product
becomes"product"
com.myapp.MyProduct
becomes"myProduct"
com.myapp.UKProduct
becomes"UKProduct"
For arrays the pluralized version of the array component type is used. For
Collection
s an attempt is made to 'peek ahead' to determine the component type and return its pluralized version.- Parameters:
value
- the value to generate a variable name for- Returns:
- the generated variable name
-
getVariableNameForParameter
Determine the conventional variable name for the given parameter taking the generic collection type, if any, into account.As of 5.0 this method supports reactive types:
Mono<com.myapp.Product>
becomes"productMono"
Flux<com.myapp.MyProduct>
becomes"myProductFlux"
Observable<com.myapp.MyProduct>
becomes"myProductObservable"
- Parameters:
parameter
- the method or constructor parameter- Returns:
- the generated variable name
-
getVariableNameForReturnType
Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account.- Parameters:
method
- the method to generate a variable name for- Returns:
- the generated variable name
-
getVariableNameForReturnType
Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account, falling back on the given actual return value if the method declaration is not specific enough, for example,Object
return type or untyped collection.- Parameters:
method
- the method to generate a variable name forvalue
- the return value (may benull
if not available)- Returns:
- the generated variable name
-
getVariableNameForReturnType
public static String getVariableNameForReturnType(Method method, Class<?> resolvedType, @Nullable Object value) Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account, falling back on the given return value if the method declaration is not specific enough, for example,Object
return type or untyped collection.As of 5.0 this method supports reactive types:
Mono<com.myapp.Product>
becomes"productMono"
Flux<com.myapp.MyProduct>
becomes"myProductFlux"
Observable<com.myapp.MyProduct>
becomes"myProductObservable"
- Parameters:
method
- the method to generate a variable name forresolvedType
- the resolved return type of the methodvalue
- the return value (may benull
if not available)- Returns:
- the generated variable name
-
attributeNameToPropertyName
ConvertString
s in attribute name format (for example, lowercase, hyphens separating words) into property name format (camel-case). For exampletransaction-manager
becomes"transactionManager"
. -
getQualifiedAttributeName
-