public final class Conventions
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
PLURAL_SUFFIX
Suffix added to names when using arrays.
|
Modifier | Constructor and Description |
---|---|
private |
Conventions() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
attributeNameToPropertyName(java.lang.String attributeName)
Convert
String s in attribute name format (e.g. |
private static java.lang.Class<?> |
getClassForValue(java.lang.Object value)
Determine the class to use for naming a variable containing the given value.
|
static java.lang.String |
getQualifiedAttributeName(java.lang.Class<?> enclosingClass,
java.lang.String attributeName)
Return an attribute name qualified by the given enclosing
Class . |
static java.lang.String |
getVariableName(java.lang.Object value)
Determine the conventional variable name for the supplied
Object
based on its concrete type. |
static java.lang.String |
getVariableNameForParameter(MethodParameter parameter)
Determine the conventional variable name for the given parameter taking
the generic collection type, if any, into account.
|
static java.lang.String |
getVariableNameForReturnType(java.lang.reflect.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 java.lang.String |
getVariableNameForReturnType(java.lang.reflect.Method method,
java.lang.Class<?> resolvedType,
java.lang.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.
|
static java.lang.String |
getVariableNameForReturnType(java.lang.reflect.Method method,
java.lang.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.
|
private static <E> E |
peekAhead(java.util.Collection<E> collection)
Retrieve the
Class of an element in the Collection . |
private static java.lang.String |
pluralize(java.lang.String name)
Pluralize the given name.
|
private static final java.lang.String PLURAL_SUFFIX
public static java.lang.String getVariableName(java.lang.Object value)
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 Collection
s an attempt is made to 'peek ahead' to determine
the component type and return its pluralized version.
value
- the value to generate a variable name forpublic static java.lang.String getVariableNameForParameter(MethodParameter parameter)
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"
parameter
- the method or constructor parameterpublic static java.lang.String getVariableNameForReturnType(java.lang.reflect.Method method)
method
- the method to generate a variable name forpublic static java.lang.String getVariableNameForReturnType(java.lang.reflect.Method method, @Nullable java.lang.Object value)
Object
return type or untyped collection.method
- the method to generate a variable name forvalue
- the return value (may be null
if not available)public static java.lang.String getVariableNameForReturnType(java.lang.reflect.Method method, java.lang.Class<?> resolvedType, @Nullable java.lang.Object value)
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"
method
- the method to generate a variable name forresolvedType
- the resolved return type of the methodvalue
- the return value (may be null
if not available)public static java.lang.String attributeNameToPropertyName(java.lang.String attributeName)
String
s in attribute name format (e.g. lowercase, hyphens
separating words) into property name format (camel-case). For example
transaction-manager
becomes "transactionManager"
.public static java.lang.String getQualifiedAttributeName(java.lang.Class<?> enclosingClass, java.lang.String attributeName)
Class
.
For example the attribute name 'foo
' qualified by Class
'com.myapp.SomeClass
' would be 'com.myapp.SomeClass.foo
'private static java.lang.Class<?> getClassForValue(java.lang.Object 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.
value
- the value to checkprivate static java.lang.String pluralize(java.lang.String name)
private static <E> E peekAhead(java.util.Collection<E> collection)
Class
of an element in the Collection
.
The exact element for which the Class
is retrieved will depend
on the concrete Collection
implementation.