mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#610 remove unmapped source policy processor option
This commit is contained in:
parent
92fe1093e4
commit
a3e7b0a20a
@ -257,18 +257,6 @@ Supported values are:
|
||||
|
||||
If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence.
|
||||
|`WARN`
|
||||
|
||||
|`mapstruct.unmappedSourcePolicy`
|
||||
|The default reporting policy to be applied in case an attribute of the source object of a mapping method is not populating an attribute of the target object.
|
||||
|
||||
Supported values are:
|
||||
|
||||
* `ERROR`: any unmapped source property will cause the mapping code generation to fail
|
||||
* `WARN`: any unmapped source property will cause a warning at build time
|
||||
* `IGNORE`: unmapped source properties are ignored
|
||||
|
||||
If a policy is given for a specific mapper via `@Mapper#unmappedSourcePolicy()`, the value from the annotation takes precedence.
|
||||
|`IGNORE`
|
||||
|===
|
||||
|
||||
=== Using MapStruct on Java 9
|
||||
|
@ -91,7 +91,6 @@ import org.mapstruct.ap.internal.util.TypeHierarchyErroneousException;
|
||||
MappingProcessor.SUPPRESS_GENERATOR_TIMESTAMP,
|
||||
MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT,
|
||||
MappingProcessor.UNMAPPED_TARGET_POLICY,
|
||||
MappingProcessor.UNMAPPED_SOURCE_POLICY,
|
||||
MappingProcessor.DEFAULT_COMPONENT_MODEL
|
||||
})
|
||||
public class MappingProcessor extends AbstractProcessor {
|
||||
@ -105,7 +104,6 @@ public class MappingProcessor extends AbstractProcessor {
|
||||
protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT =
|
||||
"mapstruct.suppressGeneratorVersionInfoComment";
|
||||
protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy";
|
||||
protected static final String UNMAPPED_SOURCE_POLICY = "mapstruct.unmappedSourcePolicy";
|
||||
protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel";
|
||||
protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile";
|
||||
|
||||
@ -134,13 +132,11 @@ public class MappingProcessor extends AbstractProcessor {
|
||||
|
||||
private Options createOptions() {
|
||||
String unmappedTargetPolicy = processingEnv.getOptions().get( UNMAPPED_TARGET_POLICY );
|
||||
String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY );
|
||||
|
||||
return new Options(
|
||||
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ),
|
||||
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ),
|
||||
unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null,
|
||||
unmappedSourcePolicy != null ? ReportingPolicyPrism.valueOf( unmappedSourcePolicy.toUpperCase() ) : null,
|
||||
processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ),
|
||||
Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) )
|
||||
);
|
||||
|
@ -752,7 +752,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
private ReportingPolicyPrism getUnmappedSourcePolicy() {
|
||||
MapperConfiguration mapperSettings = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() );
|
||||
|
||||
return mapperSettings.unmappedSourcePolicy( ctx.getOptions() );
|
||||
return mapperSettings.unmappedSourcePolicy();
|
||||
}
|
||||
|
||||
private void reportErrorForUnmappedSourcePropertiesIfRequired() {
|
||||
|
@ -30,18 +30,15 @@ public class Options {
|
||||
private final boolean suppressGeneratorTimestamp;
|
||||
private final boolean suppressGeneratorVersionComment;
|
||||
private final ReportingPolicyPrism unmappedTargetPolicy;
|
||||
private final ReportingPolicyPrism unmappedSourcePolicy;
|
||||
private final boolean alwaysGenerateSpi;
|
||||
private final String defaultComponentModel;
|
||||
|
||||
public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment,
|
||||
ReportingPolicyPrism unmappedTargetPolicy,
|
||||
ReportingPolicyPrism unmappedSourcePolicy,
|
||||
String defaultComponentModel, boolean alwaysGenerateSpi) {
|
||||
this.suppressGeneratorTimestamp = suppressGeneratorTimestamp;
|
||||
this.suppressGeneratorVersionComment = suppressGeneratorVersionComment;
|
||||
this.unmappedTargetPolicy = unmappedTargetPolicy;
|
||||
this.unmappedSourcePolicy = unmappedSourcePolicy;
|
||||
this.defaultComponentModel = defaultComponentModel;
|
||||
this.alwaysGenerateSpi = alwaysGenerateSpi;
|
||||
}
|
||||
@ -58,10 +55,6 @@ public class Options {
|
||||
return unmappedTargetPolicy;
|
||||
}
|
||||
|
||||
public ReportingPolicyPrism getUnmappedSourcePolicy() {
|
||||
return unmappedSourcePolicy;
|
||||
}
|
||||
|
||||
public String getDefaultComponentModel() {
|
||||
return defaultComponentModel;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class MapperConfiguration {
|
||||
return ReportingPolicyPrism.valueOf( mapperPrism.unmappedTargetPolicy() );
|
||||
}
|
||||
|
||||
public ReportingPolicyPrism unmappedSourcePolicy(Options options) {
|
||||
public ReportingPolicyPrism unmappedSourcePolicy() {
|
||||
if ( mapperPrism.values.unmappedSourcePolicy() != null ) {
|
||||
return ReportingPolicyPrism.valueOf( mapperPrism.unmappedSourcePolicy() );
|
||||
}
|
||||
@ -138,10 +138,6 @@ public class MapperConfiguration {
|
||||
return ReportingPolicyPrism.valueOf( mapperConfigPrism.unmappedSourcePolicy() );
|
||||
}
|
||||
|
||||
if ( options.getUnmappedSourcePolicy() != null ) {
|
||||
return options.getUnmappedSourcePolicy();
|
||||
}
|
||||
|
||||
// fall back to default defined in the annotation
|
||||
return ReportingPolicyPrism.valueOf( mapperPrism.unmappedSourcePolicy() );
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
import org.mapstruct.ap.test.unmappedtarget.Source;
|
||||
import org.mapstruct.ap.test.unmappedtarget.Target;
|
||||
@ -84,51 +83,4 @@ public class UnmappedSourceTest {
|
||||
)
|
||||
public void shouldRaiseErrorDueToUnsetSourceProperty() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ Source.class, Target.class, org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class })
|
||||
@ProcessorOption(name = "mapstruct.unmappedSourcePolicy", value = "ERROR")
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 29,
|
||||
messageRegExp = "Unmapped source property: \"qux\""),
|
||||
@Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 29,
|
||||
messageRegExp = "Unmapped target property: \"bar\""),
|
||||
@Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 31,
|
||||
messageRegExp = "Unmapped source property: \"bar\""),
|
||||
@Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 31,
|
||||
messageRegExp = "Unmapped target property: \"qux\"")
|
||||
}
|
||||
)
|
||||
public void shouldRaiseErrorDueToUnsetSourcePropertyWithPolicySetViaProcessorOption() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ Source.class, Target.class, UsesConfigFromAnnotationMapper.class, Config.class })
|
||||
@ProcessorOption(name = "mapstruct.unmappedSourcePolicy", value = "ERROR")
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.SUCCEEDED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = UsesConfigFromAnnotationMapper.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 33,
|
||||
messageRegExp = "Unmapped source property: \"qux\""),
|
||||
@Diagnostic(type = UsesConfigFromAnnotationMapper.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 35,
|
||||
messageRegExp = "Unmapped source property: \"bar\"")
|
||||
}
|
||||
)
|
||||
public void shouldRaiseErrorBecauseConfiguredByAnnotation() {
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user