#1383 Invalid @Mapping values should be reported on the @Mapping annotation

This commit is contained in:
dvfeinblum 2018-04-15 02:33:00 -04:00 committed by Filip Hrisafov
parent 18fa0a5b1a
commit 075d2c4113
4 changed files with 40 additions and 16 deletions

View File

@ -110,35 +110,59 @@ public class Mapping {
} }
if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) { if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) {
messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED );
return null; return null;
} }
else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) { else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) {
messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED );
return null; return null;
} }
else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) { else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) {
messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED );
return null; return null;
} }
else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) { else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) {
messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED );
return null; return null;
} }
else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) { else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) {
messager.printMessage( element, Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED );
return null; return null;
} }
else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null) { else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null) {
messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED );
return null; return null;
} }
else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null) { else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null) {
messager.printMessage( element, Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED );
return null; return null;
} }
else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null) { else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null) {
messager.printMessage( element, Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); messager.printMessage(
element,
mappingPrism.mirror,
Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED );
return null; return null;
} }

View File

@ -138,7 +138,7 @@ public class DefaultValueTest {
diagnostics = { diagnostics = {
@Diagnostic( type = ErroneousMapper.class, @Diagnostic( type = ErroneousMapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 33, line = 31,
messageRegExp = "Constant and default value are both defined in @Mapping," messageRegExp = "Constant and default value are both defined in @Mapping,"
+ " either define a defaultValue or a constant." ), + " either define a defaultValue or a constant." ),
@Diagnostic(type = ErroneousMapper.class, @Diagnostic(type = ErroneousMapper.class,
@ -160,7 +160,7 @@ public class DefaultValueTest {
diagnostics = { diagnostics = {
@Diagnostic( type = ErroneousMapper2.class, @Diagnostic( type = ErroneousMapper2.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 33, line = 31,
messageRegExp = "Expression and default value are both defined in @Mapping," messageRegExp = "Expression and default value are both defined in @Mapping,"
+ " either define a defaultValue or an expression." ), + " either define a defaultValue or an expression." ),
@Diagnostic(type = ErroneousMapper2.class, @Diagnostic(type = ErroneousMapper2.class,

View File

@ -103,7 +103,7 @@ public class SourceConstantsTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousMapper1.class, @Diagnostic(type = ErroneousMapper1.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 43, line = 37,
messageRegExp = "Source and constant are both defined in @Mapping, either define a source or a " messageRegExp = "Source and constant are both defined in @Mapping, either define a source or a "
+ "constant"), + "constant"),
@Diagnostic(type = ErroneousMapper1.class, @Diagnostic(type = ErroneousMapper1.class,
@ -129,7 +129,7 @@ public class SourceConstantsTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousMapper3.class, @Diagnostic(type = ErroneousMapper3.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 43, line = 37,
messageRegExp = messageRegExp =
"Expression and constant are both defined in @Mapping, either define an expression or a " "Expression and constant are both defined in @Mapping, either define an expression or a "
+ "constant"), + "constant"),
@ -156,7 +156,7 @@ public class SourceConstantsTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousMapper4.class, @Diagnostic(type = ErroneousMapper4.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 43, line = 37,
messageRegExp = "Source and expression are both defined in @Mapping, either define a source or an " messageRegExp = "Source and expression are both defined in @Mapping, either define a source or an "
+ "expression"), + "expression"),
@Diagnostic(type = ErroneousMapper4.class, @Diagnostic(type = ErroneousMapper4.class,

View File

@ -68,7 +68,7 @@ public class JavaDefaultExpressionTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 39, line = 35,
messageRegExp = "Expression and default expression are both defined in @Mapping," messageRegExp = "Expression and default expression are both defined in @Mapping,"
+ " either define an expression or a default expression." + " either define an expression or a default expression."
), ),
@ -89,7 +89,7 @@ public class JavaDefaultExpressionTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 38, line = 35,
messageRegExp = "Constant and default expression are both defined in @Mapping," messageRegExp = "Constant and default expression are both defined in @Mapping,"
+ " either define a constant or a default expression." + " either define a constant or a default expression."
), ),
@ -110,7 +110,7 @@ public class JavaDefaultExpressionTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 38, line = 35,
messageRegExp = "Default value and default expression are both defined in @Mapping," messageRegExp = "Default value and default expression are both defined in @Mapping,"
+ " either define a default value or a default expression." + " either define a default value or a default expression."
), ),