diff --git a/processor/src/main/java/org/mapstruct/ap/services/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/services/DefaultAccessorNamingStrategy.java index 48bc2a471..d43210ab0 100644 --- a/processor/src/main/java/org/mapstruct/ap/services/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/services/DefaultAccessorNamingStrategy.java @@ -29,6 +29,10 @@ import org.mapstruct.spi.AccessorNamingStrategy; */ class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { + @Override + public void setDefaultAccessorNamingStrategy(AccessorNamingStrategy defaultAccessorNamingStrategy) { + } + @Override public boolean isNonBooleanGetterName(String methodName) { return methodName.startsWith( "get" ) && methodName.length() > 3; diff --git a/processor/src/main/java/org/mapstruct/ap/services/Services.java b/processor/src/main/java/org/mapstruct/ap/services/Services.java index 941dca0a1..0600d4d26 100644 --- a/processor/src/main/java/org/mapstruct/ap/services/Services.java +++ b/processor/src/main/java/org/mapstruct/ap/services/Services.java @@ -48,10 +48,12 @@ public class Services { } private static AccessorNamingStrategy findAccessorNamingStrategy() { + AccessorNamingStrategy defaultImpl = new DefaultAccessorNamingStrategy(); AccessorNamingStrategy impl = find( AccessorNamingStrategy.class ); if ( impl == null ) { - impl = new DefaultAccessorNamingStrategy(); + impl = defaultImpl; } + impl.setDefaultAccessorNamingStrategy( defaultImpl ); return impl; } diff --git a/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java b/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java index 41d3c92d9..f7291d19d 100644 --- a/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java +++ b/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java @@ -25,8 +25,20 @@ package org.mapstruct.spi; */ public interface AccessorNamingStrategy { + /** + * Set the default {@link AccessorNamingStrategy} implementation. Custom implementations may use it to + * keep parts of the default behavior. This method is invoked before any other method of the interface. + *
+ * Default implementation: Does nothing. + * + * @param defaultAccessorNamingStrategy The default implementation. + */ + void setDefaultAccessorNamingStrategy(AccessorNamingStrategy defaultAccessorNamingStrategy); + /** * Determine if a method name defines a getter with a non-boolean return type. + *
+ * Default implementation: Method name starts with "get" and is longer than 3 characters. * * @param methodName The method name. * @return {@code true} if the method name can be a non-boolean getter, {@code false} otherwise. @@ -35,6 +47,8 @@ public interface AccessorNamingStrategy { /** * Determine if a method name defines a getter with a boolean return type. + *
+ * Default implementation: Method name starts with "is" and is longer than 2 characters. * * @param methodName The method name. * @return {@code true} if the method name can be a boolean getter, {@code false} otherwise. @@ -43,6 +57,8 @@ public interface AccessorNamingStrategy { /** * Determine if a method name defines a setter. + *
+ * Default implementation: Method name starts with "set" and is longer than 3 characters. * * @param methodName The method name. * @return {@code true} if the method name can be a setter, {@code false} otherwise. @@ -51,6 +67,8 @@ public interface AccessorNamingStrategy { /** * Determine if a method name defines an adder. + *
+ * Default implementation: Method name starts with "add" and is longer than 3 characters. * * @param methodName The method name. * @return {@code true} if the method name can be an adder, {@code false} otherwise. @@ -60,6 +78,9 @@ public interface AccessorNamingStrategy { /** * Extract the property name from a method name for which {@link #isNonBooleanGetterName(String)} returned * {@code true}. + *
+ * Default implementation: Remove first 3 characters ("get") of the method name, and + * {@link java.beans.Introspector#decapitalize(String) decapitalize} the result. * * @param methodName The method name, guaranteed to be a non-boolean getter name. * @return The property name corresponding to the method name. @@ -69,6 +90,9 @@ public interface AccessorNamingStrategy { /** * Extract the property name from a method name for which {@link #isBooleanGetterName(String)} returned * {@code true}. + *
+ * Default implementation: Remove the first 2 characters ("is") of the method name, and + * {@link java.beans.Introspector#decapitalize(String) decapitalize} the result. * * @param methodName The method name, guaranteed to be a boolean getter name. * @return The property name corresponding to the method name. @@ -77,6 +101,9 @@ public interface AccessorNamingStrategy { /** * Extract the property name from a method name for which {@link #isSetterName(String)} returned {@code true}. + *
+ * Default implementation: Remove the first 3 characters ("set") of the method name, and + * {@link java.beans.Introspector#decapitalize(String) decapitalize} the result. * * @param methodName The method name, guaranteed to be a setter name. * @return The property name corresponding to the method name. @@ -86,6 +113,9 @@ public interface AccessorNamingStrategy { /** * Extract the element name (singular form of the collection's property name) from a method name for which * {@link #isAdderName(String)} returned {@code true}. + *
+ * Default implementation: Remove the first 3 characters ("add") of the method name, and + * {@link java.beans.Introspector#decapitalize(String) decapitalize} the result. * * @param methodName The method name, guaranteed to be an adder name. * @return The element name corresponding to the method name. @@ -94,6 +124,8 @@ public interface AccessorNamingStrategy { /** * Extract the non-boolean getter method name from the setter method name of the same property. + *
+ * Default implementation: Replace the first 3 characters ("get") of the method name with "set". * * @param methodName The method name, guaranteed to be a setter name. * @return The corresponding non-boolean getter method name.