initial version

This commit is contained in:
2021-05-01 15:12:14 +02:00
parent 725a438479
commit fa0de02716
6 changed files with 199 additions and 69 deletions

View File

@ -0,0 +1,26 @@
package de.muehlencord.mapstruct.support;
import javax.lang.model.element.ExecutableElement;
import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy;
/**
* MapStruct naming strategy to to support fluent API withXYZ setters. When this strategy is applied, the wither are
* ignored so just the normal setter are used.
*
* @author Joern Muehlencord, 2021-05-01
* @since 1.4.2
*/
public class WitherAccessorNamingStrategy extends DefaultAccessorNamingStrategy {
@Override
protected boolean isFluentSetter(ExecutableElement method) {
return !isWitherMethod(method) && super.isFluentSetter(method);
}
protected boolean isWitherMethod(ExecutableElement method) {
String methodName = method.getSimpleName().toString();
return methodName.length() > 4 && methodName.startsWith("with") && Character.isUpperCase(methodName.charAt(4));
}
}

View File

@ -0,0 +1 @@
de.muehlencord.mapstruct.support.WitherAccessorNamingStrategy