mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1911 Change return type MapperConfiguration.getBuilderPrism from Optional<BuilderPrism> to BuilderPrism (#1912)
This commit is contained in:
parent
ade4f4d7e2
commit
70de843bea
@ -58,7 +58,7 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
|
||||
return createForgedAssignment(
|
||||
sourceRHS,
|
||||
ctx.getTypeFactory()
|
||||
.builderTypeFor( targetType, BeanMapping.builderPrismFor( method ).orElse( null ) ),
|
||||
.builderTypeFor( targetType, BeanMapping.builderPrismFor( method ) ),
|
||||
forgedMethod
|
||||
);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
package org.mapstruct.ap.internal.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
|
||||
import org.mapstruct.ap.internal.model.common.BuilderType;
|
||||
@ -36,14 +35,14 @@ public class BuilderFinisherMethodResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
Optional<BuilderPrism> builderMapping = BeanMapping.builderPrismFor( method );
|
||||
if ( !builderMapping.isPresent() && buildMethods.size() == 1 ) {
|
||||
BuilderPrism builderMapping = BeanMapping.builderPrismFor( method );
|
||||
if ( builderMapping == null && buildMethods.size() == 1 ) {
|
||||
return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() );
|
||||
}
|
||||
else {
|
||||
String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME;
|
||||
if ( builderMapping.isPresent() ) {
|
||||
buildMethodPattern = builderMapping.get().buildMethod();
|
||||
if ( builderMapping != null ) {
|
||||
buildMethodPattern = builderMapping.buildMethod();
|
||||
}
|
||||
for ( ExecutableElement buildMethod : buildMethods ) {
|
||||
String methodName = buildMethod.getSimpleName().toString();
|
||||
@ -52,7 +51,7 @@ public class BuilderFinisherMethodResolver {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !builderMapping.isPresent() ) {
|
||||
if ( builderMapping == null ) {
|
||||
ctx.getMessager().printMessage(
|
||||
method.getExecutable(),
|
||||
Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT,
|
||||
@ -65,7 +64,7 @@ public class BuilderFinisherMethodResolver {
|
||||
else {
|
||||
ctx.getMessager().printMessage(
|
||||
method.getExecutable(),
|
||||
builderMapping.get().mirror,
|
||||
builderMapping.mirror,
|
||||
Message.BUILDER_NO_BUILD_METHOD_FOUND,
|
||||
buildMethodPattern,
|
||||
builderType.getBuilder(),
|
||||
|
@ -110,7 +110,7 @@ public class PropertyMapping extends ModelElement {
|
||||
public T targetWriteAccessor(Accessor targetWriteAccessor) {
|
||||
this.targetWriteAccessor = targetWriteAccessor;
|
||||
this.targetType = ctx.getTypeFactory().getType( targetWriteAccessor.getAccessedType() );
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null );
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method );
|
||||
this.targetBuilderType = ctx.getTypeFactory().builderTypeFor( this.targetType, builderPrism );
|
||||
this.targetWriteAccessorType = targetWriteAccessor.getAccessorType();
|
||||
return (T) this;
|
||||
@ -278,7 +278,7 @@ public class PropertyMapping extends ModelElement {
|
||||
criteria,
|
||||
rightHandSide,
|
||||
positionHint,
|
||||
() -> forge( )
|
||||
this::forge
|
||||
);
|
||||
}
|
||||
else {
|
||||
@ -504,7 +504,7 @@ public class PropertyMapping extends ModelElement {
|
||||
private Assignment assignToArray(Type targetType, Assignment rightHandSide) {
|
||||
|
||||
Type arrayType = ctx.getTypeFactory().getType( Arrays.class );
|
||||
Assignment assignment = new ArrayCopyWrapper(
|
||||
return new ArrayCopyWrapper(
|
||||
rightHandSide,
|
||||
targetPropertyName,
|
||||
arrayType,
|
||||
@ -512,7 +512,6 @@ public class PropertyMapping extends ModelElement {
|
||||
isFieldAssignment(),
|
||||
nvpms == SET_TO_NULL && !targetType.isPrimitive(),
|
||||
nvpms == SET_TO_DEFAULT );
|
||||
return assignment;
|
||||
}
|
||||
|
||||
private SourceRHS getSourceRHS( SourceReference sourceReference ) {
|
||||
|
@ -203,7 +203,7 @@ public class TargetReference extends AbstractReference {
|
||||
);
|
||||
}
|
||||
else {
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null );
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method );
|
||||
builderType = typeFactory.builderTypeFor( nextType, builderPrism );
|
||||
propertyEntry = PropertyEntry.forTargetReference( fullName,
|
||||
targetReadAccessor,
|
||||
@ -271,7 +271,7 @@ public class TargetReference extends AbstractReference {
|
||||
return type;
|
||||
}
|
||||
else {
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null );
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method );
|
||||
return typeFactory.effectiveResultTypeFor( type, builderPrism );
|
||||
}
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ public class BeanMapping {
|
||||
/**
|
||||
* derives the builder prism given the options and configuration
|
||||
* @param method containing mandatory configuration and the mapping options (optionally containing a beanmapping)
|
||||
* @return a BuilderPrism as optional
|
||||
* @return null if BuilderPrism not exist
|
||||
*/
|
||||
public static Optional<BuilderPrism> builderPrismFor(Method method) {
|
||||
public static BuilderPrism builderPrismFor(Method method) {
|
||||
return method.getMapperConfiguration()
|
||||
.getBuilderPrism( Optional.ofNullable( method.getMappingOptions().getBeanMapping() )
|
||||
.map( b -> b.builder )
|
||||
|
@ -179,7 +179,7 @@ public class MappingOptions {
|
||||
if ( !method.isUpdateMethod() ) {
|
||||
writeType = typeFactory.effectiveResultTypeFor(
|
||||
writeType,
|
||||
BeanMapping.builderPrismFor( method ).orElse( null )
|
||||
BeanMapping.builderPrismFor( method )
|
||||
);
|
||||
}
|
||||
Map<String, Accessor> writeAccessors = writeType.getPropertyWriteAccessors( cms );
|
||||
|
@ -360,7 +360,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
}
|
||||
else {
|
||||
this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method );
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null );
|
||||
BuilderPrism builderPrism = BeanMapping.builderPrismFor( method );
|
||||
BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder();
|
||||
BeanMappingMethod beanMappingMethod = builder
|
||||
.mappingContext( mappingContext )
|
||||
|
@ -8,7 +8,6 @@ package org.mapstruct.ap.internal.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
@ -279,18 +278,18 @@ public class MapperConfiguration {
|
||||
return mapperPrism.disableSubMappingMethodsGeneration(); // fall back to default defined in the annotation
|
||||
}
|
||||
|
||||
public Optional<BuilderPrism> getBuilderPrism(BuilderPrism beanMappingBuilderPrism) {
|
||||
public BuilderPrism getBuilderPrism(BuilderPrism beanMappingBuilderPrism) {
|
||||
if ( beanMappingBuilderPrism != null ) {
|
||||
return Optional.ofNullable( beanMappingBuilderPrism );
|
||||
return beanMappingBuilderPrism;
|
||||
}
|
||||
else if ( mapperPrism.values.builder() != null ) {
|
||||
return Optional.ofNullable( mapperPrism.builder() );
|
||||
return mapperPrism.builder();
|
||||
}
|
||||
else if ( mapperConfigPrism != null && mapperConfigPrism.values.builder() != null ) {
|
||||
return Optional.ofNullable( mapperConfigPrism.builder() );
|
||||
return mapperConfigPrism.builder();
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user