mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2794 Compile error when condition expression used with constant or expression
This commit is contained in:
parent
03d44b5a87
commit
6604617730
@ -222,9 +222,15 @@ public class MappingOptions extends DelegatingOptions {
|
||||
else if ( gem.expression().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.expression().hasValue() && gem.conditionExpression().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONDITION_EXPRESSION_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.constant().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.constant().hasValue() && gem.conditionExpression().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_CONSTANT_AND_CONDITION_EXPRESSION_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.defaultValue().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||
}
|
||||
|
@ -59,7 +59,9 @@ public enum Message {
|
||||
PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED( "Expression and default value are both defined in @Mapping, either define a defaultValue or an expression." ),
|
||||
PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED( "Constant and default value are both defined in @Mapping, either define a defaultValue or a constant." ),
|
||||
PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Expression and default expression are both defined in @Mapping, either define an expression or a default expression." ),
|
||||
PROPERTYMAPPING_EXPRESSION_AND_CONDITION_EXPRESSION_BOTH_DEFINED( "Expression and condition expression are both defined in @Mapping, either define an expression or a condition expression." ),
|
||||
PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Constant and default expression are both defined in @Mapping, either define a constant or a default expression." ),
|
||||
PROPERTYMAPPING_CONSTANT_AND_CONDITION_EXPRESSION_BOTH_DEFINED( "Constant and condition expression are both defined in @Mapping, either define a constant or a condition expression." ),
|
||||
PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Default value and default expression are both defined in @Mapping, either define a default value or a default expression." ),
|
||||
PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS( "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultValue or an nullValuePropertyMappingStrategy." ),
|
||||
PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS( "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define an expression or an nullValuePropertyMappingStrategy." ),
|
||||
|
@ -111,6 +111,7 @@ public class ConditionalExpressionTest {
|
||||
|
||||
}
|
||||
|
||||
@IssueKey("2794")
|
||||
@ProcessorTest
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
@ -119,6 +120,18 @@ public class ConditionalExpressionTest {
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 19,
|
||||
message = "Value for condition expression must be given in the form \"java(<EXPRESSION>)\"."
|
||||
),
|
||||
@Diagnostic(type = ErroneousConditionExpressionMapper.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 22,
|
||||
message = "Constant and condition expression are both defined in @Mapping,"
|
||||
+ " either define a constant or a condition expression."
|
||||
),
|
||||
@Diagnostic(type = ErroneousConditionExpressionMapper.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 25,
|
||||
message = "Expression and condition expression are both defined in @Mapping,"
|
||||
+ " either define an expression or a condition expression."
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -18,4 +18,10 @@ public interface ErroneousConditionExpressionMapper {
|
||||
|
||||
@Mapping(target = "name", conditionExpression = "!employee.getName().isEmpty()")
|
||||
BasicEmployee map(EmployeeDto employee);
|
||||
|
||||
@Mapping(target = "name", conditionExpression = "java(true)", constant = "test")
|
||||
BasicEmployee mapConstant(EmployeeDto employee);
|
||||
|
||||
@Mapping(target = "name", conditionExpression = "java(true)", expression = "java(\"test\")")
|
||||
BasicEmployee mapExpression(EmployeeDto employee);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user