Package org.springframework.core
Class Conventions
- java.lang.Object
- org.springframework.core.Conventions
public abstract class Conventions extends Object
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
Constructor Summary
Constructors Constructor Description Conventions()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
attributeNameToPropertyName(String attributeName)
ConvertString
s in attribute name format (lowercase, hyphens separating words) into property name format (camel-cased).static String
getQualifiedAttributeName(Class<?> enclosingClass, String attributeName)
Return an attribute name qualified by the supplied 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 supplied 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 supplied 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 supplied method, taking the generic collection type (if any) into account, falling back to the given return value if the method declaration is not specific enough (i.e.static String
getVariableNameForReturnType(Method method, Object value)
Determine the conventional variable name for the return type of the supplied method, taking the generic collection type (if any) into account, falling back to the given return value if the method declaration is not specific enough (i.e.
Constructor Detail
Conventions
public Conventions()
Method Detail
getVariableName
public static String getVariableName(Object value)
Determine the conventional variable name for the suppliedObject
based on its concrete type. The convention used is to return the uncapitalized short name of theClass
, according to JavaBeans property naming rules: So,com.myapp.Product
becomesproduct
;com.myapp.MyProduct
becomesmyProduct
;com.myapp.UKProduct
becomesUKProduct
.For arrays, we use the pluralized version of the array component type. For
Collection
s we attempt to 'peek ahead' in theCollection
to determine the component type and return the pluralized version of that component type.- Parameters:
value
- the value to generate a variable name for- Returns:
- the generated variable name
getVariableNameForParameter
public static String getVariableNameForParameter(MethodParameter parameter)
Determine the conventional variable name for the supplied parameter, taking the generic collection type (if any) into account.- Parameters:
parameter
- the method or constructor parameter to generate a variable name for- Returns:
- the generated variable name
getVariableNameForReturnType
public static String getVariableNameForReturnType(Method method)
Determine the conventional variable name for the return type of the supplied 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
public static String getVariableNameForReturnType(Method method, Object value)
Determine the conventional variable name for the return type of the supplied method, taking the generic collection type (if any) into account, falling back to the given return value if the method declaration is not specific enough (i.e. in case of the return type being declared asObject
or as 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, Object value)
Determine the conventional variable name for the return type of the supplied method, taking the generic collection type (if any) into account, falling back to the given return value if the method declaration is not specific enough (i.e. in case of the return type being declared asObject
or as untyped collection).- 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
public static String attributeNameToPropertyName(String attributeName)
ConvertString
s in attribute name format (lowercase, hyphens separating words) into property name format (camel-cased). For example,transaction-manager
is converted intotransactionManager
.
getQualifiedAttributeName
public static String getQualifiedAttributeName(Class<?> enclosingClass, String attributeName)