public class DefaultAccessorNamingStrategy extends Object implements AccessorNamingStrategy
AccessorNamingStrategy
service provider interface.Modifier and Type | Field and Description |
---|---|
protected Elements |
elementUtils |
protected Types |
typeUtils |
Constructor and Description |
---|
DefaultAccessorNamingStrategy() |
Modifier and Type | Method and Description |
---|---|
String |
getCollectionGetterName(String property)
Returns the getter name of the given collection property.
|
String |
getElementName(ExecutableElement adderMethod)
Adder methods are used to add elements to collections on a target bean.
|
MethodType |
getMethodType(ExecutableElement method)
Returns the type of the given method.
|
String |
getPropertyName(ExecutableElement getterOrSetterMethod)
Analyzes the method (getter or setter) and derives the property name.
|
protected static String |
getQualifiedName(TypeMirror type)
Helper method, to obtain the fully qualified name of a type.
|
void |
init(MapStructProcessingEnvironment processingEnvironment)
Initializes the accessor naming strategy with the MapStruct processing environment.
|
boolean |
isAdderMethod(ExecutableElement method)
Returns
true when the ExecutableElement is an adder method. |
protected boolean |
isFluentSetter(ExecutableElement method) |
boolean |
isGetterMethod(ExecutableElement method)
Returns
true when the ExecutableElement is a getter method. |
boolean |
isPresenceCheckMethod(ExecutableElement method)
Returns
true when the ExecutableElement is a presence check method that checks if the
corresponding property is present (e.g. not null, not nil, ..). |
boolean |
isSetterMethod(ExecutableElement method)
Returns
true when the ExecutableElement is a setter method. |
public void init(MapStructProcessingEnvironment processingEnvironment)
AccessorNamingStrategy
init
in interface AccessorNamingStrategy
processingEnvironment
- environment for facilitiespublic MethodType getMethodType(ExecutableElement method)
AccessorNamingStrategy
getMethodType
in interface AccessorNamingStrategy
method
- to be analyzed.public boolean isGetterMethod(ExecutableElement method)
true
when the ExecutableElement
is a getter method. A method is a getter when it
has no parameters, starts
with 'get' and the return type is any type other than void
, OR the getter starts with 'is' and the type
returned is a primitive or the wrapper for boolean
. NOTE: the latter does strictly not comply to the bean
convention. The remainder of the name is supposed to reflect the property name.
The calling MapStruct code guarantees that the given method has no arguments.
method
- to be analyzedtrue
when the method is a getter.public boolean isSetterMethod(ExecutableElement method)
true
when the ExecutableElement
is a setter method. A setter starts with 'set'. The
remainder of the name is supposed to reflect the property name.
The calling MapStruct code guarantees that there's only one argument.
method
- to be analyzedtrue
when the method is a setter.protected boolean isFluentSetter(ExecutableElement method)
public boolean isAdderMethod(ExecutableElement method)
true
when the ExecutableElement
is an adder method. An adder method starts with 'add'.
The remainder of the name is supposed to reflect the singular property name (as opposed to plural) of
its corresponding property. For example: property "children", but "addChild". See also
getElementName(ExecutableElement)
.
The calling MapStruct code guarantees there's only one argument.
method
- to be analyzedtrue
when the method is an adder method.public boolean isPresenceCheckMethod(ExecutableElement method)
true
when the ExecutableElement
is a presence check method that checks if the
corresponding property is present (e.g. not null, not nil, ..). A presence check method method starts with
'has'. The remainder of the name is supposed to reflect the property name.
The calling MapStruct code guarantees there's no argument and that the return type is boolean or a
Boolean
method
- to be analyzedtrue
when the method is a presence check method.public String getPropertyName(ExecutableElement getterOrSetterMethod)
isGetterMethod(ExecutableElement)
isSetterMethod(ExecutableElement)
. The first three
('get' / 'set' scenario) characters are removed from the simple name, or the first 2 characters ('is' scenario).
From the remainder the first character is made into small case (to counter camel casing) and the result forms
the property name.getPropertyName
in interface AccessorNamingStrategy
getterOrSetterMethod
- getter or setter method.public String getElementName(ExecutableElement adderMethod)
getElementName
in interface AccessorNamingStrategy
adderMethod
- getter or setter method.protected static String getQualifiedName(TypeMirror type)
type
- input typeDeclaredType
, null when otherwise.public String getCollectionGetterName(String property)
AccessorNamingStrategy
The default implementation will e.g. return "getItems" for "items".
getCollectionGetterName
in interface AccessorNamingStrategy
property
- to be getterOrSetterMethod.Copyright © 2012-2021 MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.