mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Simplify consistent checks in class Mapping
This commit is contained in:
parent
ee8f9283f2
commit
55048ab045
@ -116,10 +116,10 @@ public class GraphAnalyzer {
|
|||||||
private final Map<String, Node> nodes = new LinkedHashMap<>();
|
private final Map<String, Node> nodes = new LinkedHashMap<>();
|
||||||
|
|
||||||
public GraphAnalyzerBuilder withNode(String name, Set<String> descendants) {
|
public GraphAnalyzerBuilder withNode(String name, Set<String> descendants) {
|
||||||
Node node = getNode( name );
|
Node node = nodes.computeIfAbsent( name, Node::new );
|
||||||
|
|
||||||
for ( String descendant : descendants ) {
|
for ( String descendant : descendants ) {
|
||||||
node.addDescendant( getNode( descendant ) );
|
node.addDescendant( nodes.computeIfAbsent( descendant, Node::new ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -140,16 +140,5 @@ public class GraphAnalyzer {
|
|||||||
graphAnalyzer.analyze();
|
graphAnalyzer.analyze();
|
||||||
return graphAnalyzer;
|
return graphAnalyzer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getNode(String name) {
|
|
||||||
Node node = nodes.get( name );
|
|
||||||
|
|
||||||
if ( node == null ) {
|
|
||||||
node = new Node( name );
|
|
||||||
nodes.put( name, node );
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class BeanMapping {
|
|||||||
null,
|
null,
|
||||||
ReportingPolicyPrism.IGNORE,
|
ReportingPolicyPrism.IGNORE,
|
||||||
false,
|
false,
|
||||||
Collections.<String>emptyList(),
|
Collections.emptyList(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public class Mapping {
|
|||||||
boolean resultTypeIsDefined = mappingPrism.values.resultType() != null;
|
boolean resultTypeIsDefined = mappingPrism.values.resultType() != null;
|
||||||
Set<String> dependsOn = mappingPrism.dependsOn() != null ?
|
Set<String> dependsOn = mappingPrism.dependsOn() != null ?
|
||||||
new LinkedHashSet( mappingPrism.dependsOn() ) :
|
new LinkedHashSet( mappingPrism.dependsOn() ) :
|
||||||
Collections.<String>emptySet();
|
Collections.emptySet();
|
||||||
|
|
||||||
FormattingParameters formattingParam = new FormattingParameters(
|
FormattingParameters formattingParam = new FormattingParameters(
|
||||||
dateFormat,
|
dateFormat,
|
||||||
@ -214,116 +214,59 @@ public class Mapping {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message message = null;
|
||||||
if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) {
|
if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) {
|
else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) {
|
else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) {
|
else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) {
|
else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null ) {
|
else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null ) {
|
else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null ) {
|
else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
||||||
&& mappingPrism.values.defaultValue() != null ) {
|
&& mappingPrism.values.defaultValue() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
||||||
&& mappingPrism.values.constant() != null ) {
|
&& mappingPrism.values.constant() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
||||||
&& mappingPrism.values.expression() != null ) {
|
&& mappingPrism.values.expression() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
||||||
&& mappingPrism.values.defaultExpression() != null ) {
|
&& mappingPrism.values.defaultExpression() != null ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS;
|
||||||
element,
|
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null
|
||||||
&& mappingPrism.ignore() != null && mappingPrism.ignore() ) {
|
&& mappingPrism.ignore() != null && mappingPrism.ignore() ) {
|
||||||
messager.printMessage(
|
message = Message.PROPERTYMAPPING_IGNORE_AND_NVPMS;
|
||||||
element,
|
}
|
||||||
mappingPrism.mirror,
|
|
||||||
Message.PROPERTYMAPPING_IGNORE_AND_NVPMS
|
if ( message == null ) {
|
||||||
);
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
messager.printMessage( element, mappingPrism.mirror, message );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:parameternumber")
|
@SuppressWarnings("checkstyle:parameternumber")
|
||||||
@ -576,7 +519,7 @@ public class Mapping {
|
|||||||
formattingParameters,
|
formattingParameters,
|
||||||
selectionParameters,
|
selectionParameters,
|
||||||
dependsOnAnnotationValue,
|
dependsOnAnnotationValue,
|
||||||
Collections.<String>emptySet(),
|
Collections.emptySet(),
|
||||||
nullValueCheckStrategy,
|
nullValueCheckStrategy,
|
||||||
nullValuePropertyMappingStrategy,
|
nullValuePropertyMappingStrategy,
|
||||||
new InheritContext( true, false, method )
|
new InheritContext( true, false, method )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user