#1012 rename new abstract builder and mapping methods; improve Javadoc

This commit is contained in:
Filip Hrisafov 2017-01-10 20:57:00 +01:00 committed by Gunnar Morling
parent 029368494b
commit 5cb80cbb97
6 changed files with 22 additions and 19 deletions

View File

@ -33,13 +33,13 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters;
import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.Strings;
/** /**
* A {@link MappingMethod} implemented by a {@link Mapper} class which does mapping of typed based methods. * A {@link MappingMethod} implemented by a {@link Mapper} class which does mapping of generic types.
* For example Iterable or Stream. * For example Iterable or Stream.
* The typed elements are mapped either by a {@link TypeConversion} or another mapping method. * The generic elements are mapped either by a {@link TypeConversion} or another mapping method.
* *
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
public abstract class WithElementMappingMethod extends MappingMethod { public abstract class ContainerMappingMethod extends MappingMethod {
private final Assignment elementAssignment; private final Assignment elementAssignment;
private final MethodReference factoryMethod; private final MethodReference factoryMethod;
private final boolean overridden; private final boolean overridden;
@ -47,7 +47,7 @@ public abstract class WithElementMappingMethod extends MappingMethod {
private final String loopVariableName; private final String loopVariableName;
private final SelectionParameters selectionParameters; private final SelectionParameters selectionParameters;
WithElementMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, ContainerMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod,
boolean mapNullToDefault, String loopVariableName, boolean mapNullToDefault, String loopVariableName,
List<LifecycleCallbackMethodReference> beforeMappingReferences, List<LifecycleCallbackMethodReference> beforeMappingReferences,
List<LifecycleCallbackMethodReference> afterMappingReferences, List<LifecycleCallbackMethodReference> afterMappingReferences,
@ -158,7 +158,7 @@ public abstract class WithElementMappingMethod extends MappingMethod {
if ( getClass() != obj.getClass() ) { if ( getClass() != obj.getClass() ) {
return false; return false;
} }
WithElementMappingMethod other = (WithElementMappingMethod) obj; ContainerMappingMethod other = (ContainerMappingMethod) obj;
if ( !getResultType().equals( other.getResultType() ) ) { if ( !getResultType().equals( other.getResultType() ) ) {
return false; return false;

View File

@ -36,12 +36,15 @@ import org.mapstruct.ap.internal.util.Strings;
import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.first;
/** /**
* Builder that can be used to build {@link WithElementMappingMethod}(s). * Builder that can be used to build {@link ContainerMappingMethod}(s).
*
* @param <B> the builder itself that needs to be used for chaining
* @param <M> the method that the builder builds
* *
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
public abstract class WithElementMappingMethodBuilder<B extends WithElementMappingMethodBuilder<B, M>, public abstract class ContainerMappingMethodBuilder<B extends ContainerMappingMethodBuilder<B, M>,
M extends WithElementMappingMethod> extends AbstractMappingMethodBuilder<B, M> { M extends ContainerMappingMethod> extends AbstractMappingMethodBuilder<B, M> {
private Method method; private Method method;
private SelectionParameters selectionParameters; private SelectionParameters selectionParameters;
@ -51,7 +54,7 @@ public abstract class WithElementMappingMethodBuilder<B extends WithElementMappi
private String errorMessagePart; private String errorMessagePart;
private String callingContextTargetPropertyName; private String callingContextTargetPropertyName;
WithElementMappingMethodBuilder(Class<B> selfType, String errorMessagePart) { ContainerMappingMethodBuilder(Class<B> selfType, String errorMessagePart) {
super( selfType ); super( selfType );
this.errorMessagePart = errorMessagePart; this.errorMessagePart = errorMessagePart;
} }

View File

@ -36,9 +36,9 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters;
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class IterableMappingMethod extends WithElementMappingMethod { public class IterableMappingMethod extends ContainerMappingMethod {
public static class Builder extends WithElementMappingMethodBuilder<Builder, IterableMappingMethod> { public static class Builder extends ContainerMappingMethodBuilder<Builder, IterableMappingMethod> {
public Builder() { public Builder() {
super( Builder.class, "collection element" ); super( Builder.class, "collection element" );

View File

@ -552,11 +552,11 @@ public class PropertyMapping extends ModelElement {
} }
private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source, private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source,
ExecutableElement element, WithElementMappingMethodBuilder<?, ? extends WithElementMappingMethod> builder) { ExecutableElement element, ContainerMappingMethodBuilder<?, ? extends ContainerMappingMethod> builder) {
ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element );
WithElementMappingMethod iterableMappingMethod = builder ContainerMappingMethod iterableMappingMethod = builder
.mappingContext( ctx ) .mappingContext( ctx )
.method( methodRef ) .method( methodRef )
.selectionParameters( selectionParameters ) .selectionParameters( selectionParameters )

View File

@ -40,11 +40,11 @@ import static org.mapstruct.ap.internal.util.Collections.first;
* *
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
public class StreamMappingMethod extends WithElementMappingMethod { public class StreamMappingMethod extends ContainerMappingMethod {
private final Set<Type> helperImports; private final Set<Type> helperImports;
public static class Builder extends WithElementMappingMethodBuilder<Builder, StreamMappingMethod> { public static class Builder extends ContainerMappingMethodBuilder<Builder, StreamMappingMethod> {
public Builder() { public Builder() {
super( Builder.class, "stream element" ); super( Builder.class, "stream element" );

View File

@ -36,6 +36,8 @@ import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; import javax.lang.model.util.Types;
import org.mapstruct.ap.internal.model.BeanMappingMethod; import org.mapstruct.ap.internal.model.BeanMappingMethod;
import org.mapstruct.ap.internal.model.ContainerMappingMethod;
import org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder;
import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.Decorator;
import org.mapstruct.ap.internal.model.DefaultMapperReference; import org.mapstruct.ap.internal.model.DefaultMapperReference;
import org.mapstruct.ap.internal.model.DelegatingMethod; import org.mapstruct.ap.internal.model.DelegatingMethod;
@ -48,8 +50,6 @@ import org.mapstruct.ap.internal.model.MappingBuilderContext;
import org.mapstruct.ap.internal.model.MappingMethod; import org.mapstruct.ap.internal.model.MappingMethod;
import org.mapstruct.ap.internal.model.StreamMappingMethod; import org.mapstruct.ap.internal.model.StreamMappingMethod;
import org.mapstruct.ap.internal.model.ValueMappingMethod; import org.mapstruct.ap.internal.model.ValueMappingMethod;
import org.mapstruct.ap.internal.model.WithElementMappingMethod;
import org.mapstruct.ap.internal.model.WithElementMappingMethodBuilder;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethod;
@ -446,8 +446,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
return mappingMethods; return mappingMethods;
} }
private <M extends WithElementMappingMethod> M createWithElementMappingMethod(SourceMethod method, private <M extends ContainerMappingMethod> M createWithElementMappingMethod(SourceMethod method,
MappingOptions mappingOptions, WithElementMappingMethodBuilder<?, M> builder) { MappingOptions mappingOptions, ContainerMappingMethodBuilder<?, M> builder) {
FormattingParameters formattingParameters = null; FormattingParameters formattingParameters = null;
SelectionParameters selectionParameters = null; SelectionParameters selectionParameters = null;