Top Description Fields Constructors Methods
org.springframework.core

public final Class Conventions

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, .Proxy, java.util.Collection, .Iterator, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils

Provides methods to support various naming and other conventions used throughout the framework. Mainly for internal use within the framework.
Authors
Rob Harrop, Juergen Hoeller, Rossen Stoyanchev
Since
2.0

Field Summary

Modifier and TypeField and Description
private static final String
PLURAL_SUFFIX

Suffix added to names when using arrays.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String
attributeNameToPropertyName(String attributeName)

Convert Strings in attribute name format (e.g. lowercase, hyphens separating words) into property name format (camel-case).

private static Class<?>

Returns:

the class to use for naming a variable
getClassForValue
(Object
the value to check
value
)

Determine the class to use for naming a variable containing the given value.

public static String
getQualifiedAttributeName(Class<?> enclosingClass, String attributeName)

Return an attribute name qualified by the given enclosing Class.

public static String

Returns:

the generated variable name
getVariableName
(Object
the value to generate a variable name for
value
)

Determine the conventional variable name for the supplied Object based on its concrete type.

public static String

Returns:

the generated variable name
getVariableNameForParameter
(MethodParameter
the method or constructor parameter
parameter
)

Determine the conventional variable name for the given parameter taking the generic collection type, if any, into account.

public static String

Returns:

the generated variable name
getVariableNameForReturnType
(Method
the method to generate a variable name for
method
)

Determine the conventional variable name for the return type of the given method, taking the generic collection type, if any, into account.

public static String

Returns:

the generated variable name
getVariableNameForReturnType
(Method
the method to generate a variable name for
method
,
Object
the return value (may be null if not available)
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, e.g. Object return type or untyped collection.

public static String

Returns:

the generated variable name
getVariableNameForReturnType
(Method
the method to generate a variable name for
method
,
Class<?>
the resolved return type of the method
resolvedType
,
Object
the return value (may be null if not available)
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, e.g. Object return type or untyped collection.

private static <E> E
peekAhead(Collection<E> collection)

Retrieve the Class of an element in the Collection.

private static String
pluralize(String name)

Pluralize the given name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PLURAL_SUFFIXback to summary
private static final String PLURAL_SUFFIX

Suffix added to names when using arrays.

Constructor Detail

Conventionsback to summary
private Conventions()

Method Detail

attributeNameToPropertyNameback to summary
public static String attributeNameToPropertyName(String attributeName)

Convert Strings in attribute name format (e.g. lowercase, hyphens separating words) into property name format (camel-case). For example transaction-manager becomes "transactionManager".

getClassForValueback to summary
private static Class<?> getClassForValue(Object value)

Determine the class to use for naming a variable containing the given value.

Will return the class of the given value, except when encountering a JDK proxy, in which case it will determine the 'primary' interface implemented by that proxy.

Parameters
value:Object

the value to check

Returns:Class<?>

the class to use for naming a variable

getQualifiedAttributeNameback to summary
public static String getQualifiedAttributeName(Class<?> enclosingClass, String attributeName)

Return an attribute name qualified by the given enclosing Class. For example the attribute name 'foo' qualified by Class 'com.myapp.SomeClass' would be 'com.myapp.SomeClass.foo'

getVariableNameback to summary
public static String getVariableName(Object value)

Determine the conventional variable name for the supplied Object based on its concrete type. The convention used is to return the un-capitalized short name of the Class, 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 Collections an attempt is made to 'peek ahead' to determine the component type and return its pluralized version.

Parameters
value:Object

the value to generate a variable name for

Returns:String

the generated variable name

getVariableNameForParameterback to summary
public static String getVariableNameForParameter(MethodParameter parameter)

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:MethodParameter

the method or constructor parameter

Returns:String

the generated variable name

getVariableNameForReturnTypeback to summary
public 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.

Parameters
method:Method

the method to generate a variable name for

Returns:String

the generated variable name

getVariableNameForReturnTypeback to summary
public 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, e.g. Object return type or untyped collection.

Parameters
method:Method

the method to generate a variable name for

value:Object

the return value (may be null if not available)

Returns:String

the generated variable name

getVariableNameForReturnTypeback to summary
public 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, e.g. 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:Method

the method to generate a variable name for

resolvedType:Class<?>

the resolved return type of the method

value:Object

the return value (may be null if not available)

Returns:String

the generated variable name

peekAheadback to summary
private static <E> E peekAhead(Collection<E> collection)

Retrieve the Class of an element in the Collection. The exact element for which the Class is retrieved will depend on the concrete Collection implementation.

pluralizeback to summary
private static String pluralize(String name)

Pluralize the given name.