Package org.mapstruct.ap.spi
Class DefaultAccessorNamingStrategy
- java.lang.Object
-
- org.mapstruct.ap.spi.DefaultAccessorNamingStrategy
-
- All Implemented Interfaces:
AccessorNamingStrategy
- Direct Known Subclasses:
FreeBuilderAccessorNamingStrategy,ImmutablesAccessorNamingStrategy
public class DefaultAccessorNamingStrategy extends Object implements AccessorNamingStrategy
The default JavaBeans-compliant implementation of theAccessorNamingStrategyservice provider interface.- Author:
- Christian Schuster, Sjaak Derken
-
-
Field Summary
Fields Modifier and Type Field Description protected ElementselementUtilsprotected TypestypeUtils
-
Constructor Summary
Constructors Constructor Description DefaultAccessorNamingStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetCollectionGetterName(String property)Returns the getter name of the given collection property.StringgetElementName(ExecutableElement adderMethod)Adder methods are used to add elements to collections on a target bean.MethodTypegetMethodType(ExecutableElement method)Returns the type of the given method.StringgetPropertyName(ExecutableElement getterOrSetterMethod)Analyzes the method (getter or setter) and derives the property name.protected static StringgetQualifiedName(TypeMirror type)Helper method, to obtain the fully qualified name of a type.voidinit(MapStructProcessingEnvironment processingEnvironment)Initializes the accessor naming strategy with the MapStruct processing environment.booleanisAdderMethod(ExecutableElement method)Returnstruewhen theExecutableElementis an adder method.protected booleanisFluentSetter(ExecutableElement method)booleanisGetterMethod(ExecutableElement method)Returnstruewhen theExecutableElementis a getter method.booleanisPresenceCheckMethod(ExecutableElement method)Returnstruewhen theExecutableElementis a presence check method that checks if the corresponding property is present (e.g. not null, not nil, ..).booleanisSetterMethod(ExecutableElement method)Returnstruewhen theExecutableElementis a setter method.
-
-
-
Method Detail
-
init
public void init(MapStructProcessingEnvironment processingEnvironment)
Description copied from interface:AccessorNamingStrategyInitializes the accessor naming strategy with the MapStruct processing environment.- Specified by:
initin interfaceAccessorNamingStrategy- Parameters:
processingEnvironment- environment for facilities
-
getMethodType
public MethodType getMethodType(ExecutableElement method)
Description copied from interface:AccessorNamingStrategyReturns the type of the given method.- Specified by:
getMethodTypein interfaceAccessorNamingStrategy- Parameters:
method- to be analyzed.- Returns:
- the method type.
-
isGetterMethod
public boolean isGetterMethod(ExecutableElement method)
Returnstruewhen theExecutableElementis a getter method. A method is a getter when it has no parameters, starts with 'get' and the return type is any type other thanvoid, OR the getter starts with 'is' and the type returned is a primitive or the wrapper forboolean. 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.
- Parameters:
method- to be analyzed- Returns:
truewhen the method is a getter.
-
isSetterMethod
public boolean isSetterMethod(ExecutableElement method)
Returnstruewhen theExecutableElementis 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.
- Parameters:
method- to be analyzed- Returns:
truewhen the method is a setter.
-
isFluentSetter
protected boolean isFluentSetter(ExecutableElement method)
-
isAdderMethod
public boolean isAdderMethod(ExecutableElement method)
Returnstruewhen theExecutableElementis 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 alsogetElementName(ExecutableElement).The calling MapStruct code guarantees there's only one argument.
- Parameters:
method- to be analyzed- Returns:
truewhen the method is an adder method.
-
isPresenceCheckMethod
public boolean isPresenceCheckMethod(ExecutableElement method)
Returnstruewhen theExecutableElementis 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- Parameters:
method- to be analyzed- Returns:
truewhen the method is a presence check method.
-
getPropertyName
public String getPropertyName(ExecutableElement getterOrSetterMethod)
Analyzes the method (getter or setter) and derives the property name. SeeisGetterMethod(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.- Specified by:
getPropertyNamein interfaceAccessorNamingStrategy- Parameters:
getterOrSetterMethod- getter or setter method.- Returns:
- the property name.
-
getElementName
public String getElementName(ExecutableElement adderMethod)
Adder methods are used to add elements to collections on a target bean. A typical use case is JPA. The convention is that the element name will be equal to the remainder of the add method. Example: 'addElement' element name will be 'element'.- Specified by:
getElementNamein interfaceAccessorNamingStrategy- Parameters:
adderMethod- getter or setter method.- Returns:
- the property name.
-
getQualifiedName
protected static String getQualifiedName(TypeMirror type)
Helper method, to obtain the fully qualified name of a type.- Parameters:
type- input type- Returns:
- fully qualified name of type when the type is a
DeclaredType, null when otherwise.
-
getCollectionGetterName
public String getCollectionGetterName(String property)
Description copied from interface:AccessorNamingStrategyReturns the getter name of the given collection property.The default implementation will e.g. return "getItems" for "items".
- Specified by:
getCollectionGetterNamein interfaceAccessorNamingStrategy- Parameters:
property- to be getterOrSetterMethod.- Returns:
- getter name for collection properties
-
-