From b83c4307586a171b4dceab5a4d794e23d9ba71bf Mon Sep 17 00:00:00 2001 From: sjaakd Date: Wed, 4 Feb 2015 21:46:10 +0100 Subject: [PATCH] #339 Uppercase for ENUM in messages, moving Diagnostic.Kind to Message --- .../mapstruct/ap/model/BeanMappingMethod.java | 28 ++-- .../mapstruct/ap/model/EnumMappingMethod.java | 31 ++-- .../ap/model/IterableMappingMethod.java | 4 +- .../mapstruct/ap/model/MapMappingMethod.java | 7 +- .../mapstruct/ap/model/PropertyMapping.java | 11 +- .../common/DateFormatValidationResult.java | 3 +- .../common/DateFormatValidatorFactory.java | 6 +- .../ap/model/source/BeanMapping.java | 3 +- .../ap/model/source/IterableMapping.java | 3 +- .../mapstruct/ap/model/source/MapMapping.java | 3 +- .../mapstruct/ap/model/source/Mapping.java | 43 ++---- .../ap/model/source/SourceReference.java | 23 +-- .../DefaultModelElementProcessorContext.java | 24 ++-- .../ap/processor/MapperCreationProcessor.java | 78 ++++------ .../processor/MethodRetrievalProcessor.java | 23 ++- .../creation/MappingResolverImpl.java | 11 +- .../mapstruct/ap/util/FormattingMessager.java | 14 +- .../java/org/mapstruct/ap/util/Message.java | 136 ++++++++++-------- .../common/DefaultConversionContextTest.java | 11 +- 19 files changed, 195 insertions(+), 267 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java index ceb329b36..9d8dfa1d5 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java @@ -120,10 +120,9 @@ public class BeanMappingMethod extends MappingMethod { if ( beanMapping != null && beanMapping.getResultType() != null ) { resultType = ctx.getTypeFactory().getType( beanMapping.getResultType() ); if ( !resultType.isAssignableTo( method.getResultType() ) ) { - ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), + ctx.getMessager().printMessage( method.getExecutable(), beanMappingPrism.mirror, - Message.beanmapping_notassignable, resultType, method.getResultType()); + Message.BEANMAPPING_NOT_ASSIGNABLE, resultType, method.getResultType()); } } } @@ -154,11 +153,10 @@ public class BeanMappingMethod extends MappingMethod { // fetch the target property ExecutableElement targetProperty = unprocessedTargetProperties.get( mapping.getTargetName() ); if ( targetProperty == null ) { - ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), + ctx.getMessager().printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), - Message.beanmapping_unknownpropertyinreturntype, + Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE, mapping.getTargetName() ); errorOccurred = true; @@ -310,9 +308,8 @@ public class BeanMappingMethod extends MappingMethod { if ( propertyMapping != null && newPropertyMapping != null ) { // TODO improve error message - ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), - Message.beanmapping_severalpossiblesources, + ctx.getMessager().printMessage( method.getExecutable(), + Message.BEANMAPPING_SEVERAL_POSSIBLE_SOURCES, targetProperty.getKey() ); break; @@ -389,9 +386,8 @@ public class BeanMappingMethod extends MappingMethod { } // Should never really happen else { - ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), - Message.beanmapping_severalpossibletargetaccessors, + ctx.getMessager().printMessage( method.getExecutable(), + Message.BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS, sourcePropertyName ); @@ -430,9 +426,11 @@ public class BeanMappingMethod extends MappingMethod { if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { - ctx.getMessager().printMessage( unmappedTargetPolicy.getDiagnosticKind(), - method.getExecutable(), - Message.beanmapping_unmappedtargets, + Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? + Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING; + + ctx.getMessager().printMessage( method.getExecutable(), + msg, MessageFormat.format( "{0,choice,1#property|1 1 && !isEnumType( method.getReturnType() ) ) { - messager.printMessage( Kind.ERROR, - method, - Message.propertymapping_duplicatetargets, - mappingPrism.target() - ); + messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, mappingPrism.target() ); } } } @@ -98,34 +92,24 @@ public class Mapping { FormattingMessager messager) { if ( mappingPrism.target().isEmpty() ) { - messager.printMessage( Diagnostic.Kind.ERROR, - element, + messager.printMessage( element, mappingPrism.mirror, mappingPrism.values.target(), - Message.propertymapping_emptytarget + Message.PROPERTYMAPPING_EMPTY_TARGET ); return null; } if ( !mappingPrism.source().isEmpty() && !mappingPrism.constant().isEmpty() ) { - messager.printMessage( Diagnostic.Kind.ERROR, - element, - Message.propertymapping_sourceandconstantbothdefined - ); + messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED ); return null; } else if ( !mappingPrism.source().isEmpty() && !mappingPrism.expression().isEmpty() ) { - messager.printMessage( Diagnostic.Kind.ERROR, - element, - Message.propertymapping_sourceandexpressionbothdefined - ); + messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED ); return null; } else if ( !mappingPrism.expression().isEmpty() && !mappingPrism.constant().isEmpty() ) { - messager.printMessage( Diagnostic.Kind.ERROR, - element, - Message.propertymapping_expressionandconstantbothdefined - ); + messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED ); return null; } @@ -180,12 +164,8 @@ public class Mapping { Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.expression() ); if ( !javaExpressionMatcher.matches() ) { - messager.printMessage( Diagnostic.Kind.ERROR, - element, - mappingPrism.mirror, - mappingPrism.values.expression(), - Message.propertymapping_invalidexpression - ); + messager.printMessage( element, mappingPrism.mirror, mappingPrism.values.expression(), + Message.PROPERTYMAPPING_INVALID_EXPRESSION ); return null; } @@ -295,11 +275,8 @@ public class Mapping { if ( sourceReference != null && sourceReference.getPropertyEntries().isEmpty() ) { // parameter mapping only, apparently the @InheritReverseConfiguration is intentional // but erroneous. Lets raise an error to warn. - messager.printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), - Message.propertymapping_reversalproblem, - sourceReference.getParameter() - ); + messager.printMessage( method.getExecutable(), Message.PROPERTYMAPPING_REVERSAL_PROBLEM, + sourceReference.getParameter() ); return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/model/source/SourceReference.java index 53186ce0b..fd91e26df 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/SourceReference.java @@ -24,7 +24,6 @@ import java.util.List; import org.mapstruct.ap.util.FormattingMessager; import javax.lang.model.element.ExecutableElement; -import javax.tools.Diagnostic; import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Type; @@ -115,7 +114,7 @@ public class SourceReference { String sourceParameterName = segments[0]; parameter = method.getSourceParameter( sourceParameterName ); if ( parameter == null ) { - reportMappingError( Message.propertymapping_invalidparametername, sourceParameterName ); + reportMappingError( Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, sourceParameterName ); isValid = false; } } @@ -155,15 +154,11 @@ public class SourceReference { if ( !foundEntryMatch ) { if ( parameter != null ) { - reportMappingError( Message.propertymapping_nopropertyinparameter, - parameter.getName(), - Strings.join( Arrays.asList( sourcePropertyNames ), "." ) - ); + reportMappingError( Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER, parameter.getName(), + Strings.join( Arrays.asList( sourcePropertyNames ), "." ) ); } else { - reportMappingError( Message.propertymapping_invalidpropertyname, - mapping.getSourceName() - ); + reportMappingError( Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName() ); } isValid = false; } @@ -193,14 +188,8 @@ public class SourceReference { } private void reportMappingError(Message msg, Object... objects) { - messager.printMessage( - Diagnostic.Kind.ERROR, - method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), - msg, - objects - ); + messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), + msg, objects ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/processor/DefaultModelElementProcessorContext.java index 1acda1597..82ee43b47 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/DefaultModelElementProcessorContext.java @@ -109,38 +109,38 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { } @Override - public void printMessage( Kind kind, Message msg, Object... args) { + public void printMessage(Message msg, Object... args) { String message = String.format( msg.getDescription(), args ); - delegate.printMessage( kind, message); - if ( kind == Kind.ERROR ) { + delegate.printMessage( msg.getDiagnosticKind(), message); + if ( msg.getDiagnosticKind() == Kind.ERROR ) { isErroneous = true; } } @Override - public void printMessage( Kind kind, Element e, Message msg, Object... args) { + public void printMessage(Element e, Message msg, Object... args) { String message = String.format( msg.getDescription(), args ); - delegate.printMessage( kind, message, e ); - if ( kind == Kind.ERROR ) { + delegate.printMessage( msg.getDiagnosticKind(), message, e ); + if ( msg.getDiagnosticKind() == Kind.ERROR ) { isErroneous = true; } } @Override - public void printMessage( Kind kind, Element e, AnnotationMirror a, Message msg, Object... args) { + public void printMessage(Element e, AnnotationMirror a, Message msg, Object... args) { String message = String.format( msg.getDescription(), args ); - delegate.printMessage( kind, message, e, a ); - if ( kind == Kind.ERROR ) { + delegate.printMessage( msg.getDiagnosticKind(), message, e, a ); + if ( msg.getDiagnosticKind() == Kind.ERROR ) { isErroneous = true; } } @Override - public void printMessage( Kind kind, Element e, AnnotationMirror a, AnnotationValue v, Message msg, + public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Message msg, Object... args) { String message = String.format( msg.getDescription(), args ); - delegate.printMessage( kind, message, e, a, v ); - if ( kind == Kind.ERROR ) { + delegate.printMessage( msg.getDiagnosticKind(), message, e, a, v ); + if ( msg.getDiagnosticKind() == Kind.ERROR ) { isErroneous = true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index 2e9c055b4..35a489748 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -32,8 +32,6 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import javax.tools.Diagnostic; -import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.model.BeanMappingMethod; import org.mapstruct.ap.model.Decorator; @@ -166,7 +164,7 @@ public class MapperCreationProcessor implements ModelElementProcessor mappingMethods = new ArrayList( methods.size() ); @@ -204,7 +202,7 @@ public class MapperCreationProcessor implements ModelElementProcessor candidates, SourceMethod method, InheritInverseConfigurationPrism reversePrism) { - messager.printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), + messager.printMessage( method.getExecutable(), reversePrism.mirror, - Message.inheritinverseconfiguration_duplicatematches, + Message.INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES, reversePrism.name(), Strings.join( candidates, "(), " ) @@ -591,10 +576,9 @@ public class MapperCreationProcessor implements ModelElementProcessor candidates, SourceMethod method, InheritConfigurationPrism prism) { - messager.printMessage( Diagnostic.Kind.ERROR, - method.getExecutable(), + messager.printMessage( method.getExecutable(), prism.mirror, - Message.inheritconfiguration_duplicatematches, + Message.INHERITCONFIGURATION_DUPLICATE_MATCHES, prism.name(), Strings.join( candidates, "(), " ) ); @@ -674,10 +653,9 @@ public class MapperCreationProcessor implements ModelElementProcessor 1 ) { if ( mappedElement != null ) { - messager.printMessage( Diagnostic.Kind.ERROR, - mappingMethod.getExecutable(), - Message.general_ambigiousmappingmethod, + messager.printMessage( mappingMethod.getExecutable(), + Message.GENERAL_AMBIGIOUS_MAPPING_METHOD, mappedElement, returnType, Strings.join( candidates, ", " ) ); } else { - messager.printMessage( Diagnostic.Kind.ERROR, - mappingMethod.getExecutable(), - Message.general_ambigiousfactorymethod, + messager.printMessage( mappingMethod.getExecutable(), + Message.GENERAL_AMBIGIOUSFACTORY_METHOD, returnType, Strings.join( candidates, ", " ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/util/FormattingMessager.java b/processor/src/main/java/org/mapstruct/ap/util/FormattingMessager.java index 4e21c794f..48f9749e0 100644 --- a/processor/src/main/java/org/mapstruct/ap/util/FormattingMessager.java +++ b/processor/src/main/java/org/mapstruct/ap/util/FormattingMessager.java @@ -21,37 +21,33 @@ package org.mapstruct.ap.util; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; -import javax.tools.Diagnostic; public interface FormattingMessager { /** * Prints a message of the specified kind. * - * @param kind the kind of message * @param msg the message * @param args Arguments referenced by the format specifiers in the format string. If there are more arguments * than format specifiers, the extra arguments are ignored */ - void printMessage( Diagnostic.Kind kind, Message msg, Object... args); + void printMessage(Message msg, Object... args); /** * Prints a message of the specified kind at the location of the * element. * - * @param kind the kind of message * @param e the element to use as a position hint * @param msg the message * @param args Arguments referenced by the format specifiers in the format string. If there are more arguments * than format specifiers, the extra arguments are ignored */ - void printMessage( Diagnostic.Kind kind, Element e, Message msg, Object... args); + void printMessage(Element e, Message msg, Object... args); /** * Prints a message of the specified kind at the location of the * annotation mirror of the annotated element. * - * @param kind the kind of message * @param e the annotated element * @param a the annotation to use as a position hint * @param msg the message @@ -59,14 +55,13 @@ public interface FormattingMessager { * than format specifiers, the extra arguments are ignored * */ - void printMessage( Diagnostic.Kind kind, Element e, AnnotationMirror a, Message msg, Object... args); + void printMessage(Element e, AnnotationMirror a, Message msg, Object... args); /** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * - * @param kind the kind of message * @param e the annotated element * @param a the annotation containing the annotation value * @param v the annotation value to use as a position hint @@ -74,8 +69,7 @@ public interface FormattingMessager { * @param args Arguments referenced by the format specifiers in the format string. If there are more arguments * than format specifiers, the extra arguments are ignored */ - void printMessage( Diagnostic.Kind kind, - Element e, + void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Message msg, diff --git a/processor/src/main/java/org/mapstruct/ap/util/Message.java b/processor/src/main/java/org/mapstruct/ap/util/Message.java index 0d2f71e0d..5836b70d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/util/Message.java @@ -18,83 +18,99 @@ */ package org.mapstruct.ap.util; +import javax.tools.Diagnostic; + /** * * @author Sjaak Derksen */ public enum Message { + // CHECKSTYLE:OFF - beanmapping_noelements( "'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), - beanmapping_notassignable( "%s not assignable to: %s." ), - beanmapping_unknownpropertyinreturntype( "Unknown property \"%s\" in return type." ), - beanmapping_severalpossiblesources( "Several possible source properties for target property \"%s\"." ), - beanmapping_severalpossibletargetaccessors( "Found several matching getters for property \"%s\"." ), - beanmapping_unmappedtargets( "Unmapped target %s." ), - propertymapping_mappingnotfound( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), - propertymapping_duplicatetargets( "Target property \"%s\" must not be mapped more than once." ), - propertymapping_emptytarget( "Target must not be empty in @Mapping." ), - propertymapping_sourceandconstantbothdefined( "Source and constant are both defined in @Mapping, either define a source or a constant." ), - propertymapping_sourceandexpressionbothdefined( "Source and expression are both defined in @Mapping, either define a source or an expression." ), - propertymapping_expressionandconstantbothdefined( "Expression and constant are both defined in @Mapping, either define an expression or a constant." ), - propertymapping_invalidexpression( "Value must be given in the form \"java()\"." ), - propertymapping_reversalproblem( "Parameter %s cannot be reversed." ), - propertymapping_invalidparametername( "Method has no parameter named \"%s\"." ), - propertymapping_nopropertyinparameter( "The type of parameter \"%s\" has no property named \"%s\"." ), - propertymapping_invalidpropertyname( "No property named \"%s\" exists in source parameter(s)." ), - constantmapping_mappingnotfound( "Can't map \"%s %s\" to \"%s %s\"." ), - mapmapping_key_mappingnotfound( "Can't create implementation of method %s. Found no method nor built-in conversion for mapping source key type to target key type." ), - mapmapping_value_mappingnotfound( "Can't create implementation of method %s. Found no method nor built-in conversion for mapping source value type to target value type." ), - mapmapping_noelements( "'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', 'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, define at least one of them." ), - iterablemapping_mappingnotfound( "Can't create implementation of method %s. Found no method nor built-in conversion for mapping source element type into target element type." ), - iterablemapping_noelements( "'dateformat', 'qualifiedBy' and 'elementTargetType' are undefined in @IterableMapping, define at least one of them." ), - enummapping_multipletargets( "One enum constant must not be mapped to more than one target constant, but constant %s is mapped to %s." ), - enummapping_undefinedsource( "A source constant must be specified for mappings of an enum mapping method." ), - enummapping_nonexistingconstant( "Constant %s doesn't exist in enum type %s." ), - enummapping_undefinedtarget( "A target constant must be specified for mappings of an enum mapping method." ), - enummapping_unmappedtargets( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via @Mapping: %s." ), - decorator_nosubtype( "Specified decorator type is no subtype of the annotated mapper type." ), - decorator_constructor( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), - general_noimplementation( "No implementation type is registered for return type %s." ), - general_ambigiousmappingmethod( "Ambiguous mapping methods found for mapping %s to %s: %s." ), - general_ambigiousfactorymethod( "Ambiguous mapping methods found for factorizing %s: %s." ), - general_unsupporteddateformatcheck( "No dateFormat check is supported for types %s, %s" ), - general_validdate( "given date format \"%s\" is valid." ), - general_invaliddate( "given date format \"%s\" is invalid. Message: \"%s\"." ), - retrieval_noinputargs( "Can't generate mapping method with no input arguments." ), - retrieval_duplicatemappingtargets( "Can't generate mapping method with more than one @MappingTarget parameter." ), - retrieval_voidmappingmethod( "Can't generate mapping method with return type void." ), - retrieval_nonassignableresulttype( "The result type is not assignable to the the return type." ), - retrieval_iterabletononiterable( "Can't generate mapping method from iterable type to non-iterable type." ), - retrieval_mappinghastargettypeparameter( "Can't generate mapping method that has a parameter annotated with @TargetType." ), - retrieval_noniterabletoiterable( "Can't generate mapping method from non-iterable type to iterable type." ), - retrieval_primitiveparameter( "Can't generate mapping method with primitive parameter type." ), - retrieval_primitivereturn( "Can't generate mapping method with primitive return type." ), - retrieval_enumtononenum( "Can't generate mapping method from enum type to non-enum type." ), - retrieval_nonenumtoenum( "Can't generate mapping method from non-enum type to enum type." ), - inheritconfiguration_both( "Method cannot be annotated with both a @InheritConfiguration and @InheritInverseConfiguration." ), - inheritinverseconfiguration_referencehasinverse( "Resolved inverse mapping method %s() should not carry the @InheritInverseConfiguration annotation itself." ), - inheritinverseconfiguration_referencehasforward( "Resolved inverse mapping method %s() should not carry the @InheritConfiguration annotation." ), - inheritinverseconfiguration_duplicates( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), - inheritinverseconfiguration_invalidname( "None of the candidates %s() matches given name: \"%s\"." ), - inheritinverseconfiguration_duplicatematches( "Given name \"%s\" matches several candidate methods: %s()." ), - inheritinverseconfiguration_nonamematch( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ), - inheritconfiguration_referencehasforward( "Resolved mapping method %s() should not carry the @InheritConfiguration annotation itself." ), - inheritconfiguration_referencehasinverse( "Resolved mapping method %s() should not carry the @InheritInverseConfiguration annotation." ), - inheritconfiguration_duplicates( "Several matching methods exist: %s(). Specify a name explicitly." ), - inheritconfiguration_invalidname( "None of the candidates %s() matches given name: \"%s\"." ), - inheritconfiguration_duplicatematches( "Given name \"%s\" matches several candidate methods: %s()." ), - inheritconfiguration_nonamematch( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ); +// CHECKSTYLE:OFF + BEANMAPPING_NO_ELEMENTS( "'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), + BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), + BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE( "Unknown property \"%s\" in return type." ), + BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ), + BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS( "Found several matching getters for property \"%s\"." ), + BEANMAPPING_UNMAPPED_TARGETS_WARNING( "Unmapped target %s.", Diagnostic.Kind.WARNING ), + BEANMAPPING_UNMAPPED_TARGETS_ERROR( "Unmapped target %s." ), + PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), + PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ), + PROPERTYMAPPING_EMPTY_TARGET( "Target must not be empty in @Mapping." ), + PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED( "Source and constant are both defined in @Mapping, either define a source or a constant." ), + PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED( "Source and expression are both defined in @Mapping, either define a source or an expression." ), + PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED( "Expression and constant are both defined in @Mapping, either define an expression or a constant." ), + PROPERTYMAPPING_INVALID_EXPRESSION( "Value must be given in the form \"java()\"." ), + PROPERTYMAPPING_REVERSAL_PROBLEM( "Parameter %s cannot be reversed." ), + PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no parameter named \"%s\"." ), + PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%s\"." ), + PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s)." ), + CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ), + MAPMAPPING_KEY_MAPPING_NOT_FOUND( "Can't create implementation of method %s. Found no method nor built-in conversion for mapping source key type to target key type." ), + MAPMAPPING_VALUE_MAPPING_NOT_FOUND( "Can't create implementation of method %s. Found no method nor built-in conversion for mapping source value type to target value type." ), + MAPMAPPING_NO_ELEMENTS( "'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', 'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, define at least one of them." ), + ITERABLEMAPPING_MAPPING_NOT_FOUND( "Can't create implementation of method %s. Found no method nor built-in conversion for mapping source element type into target element type." ), + ITERABLEMAPPING_NO_ELEMENTS( "'dateformat', 'qualifiedBy' and 'elementTargetType' are undefined in @IterableMapping, define at least one of them." ), + ENUMMAPPING_MULTIPLE_TARGETS( "One enum constant must not be mapped to more than one target constant, but constant %s is mapped to %s." ), + ENUMMAPPING_UNDEFINED_SOURCE( "A source constant must be specified for mappings of an enum mapping method." ), + ENUMMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ), + ENUMMAPPING_UNDEFINED_TARGET( "A target constant must be specified for mappings of an enum mapping method." ), + ENUMMAPPING_UNMAPPED_TARGETS( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via @Mapping: %s." ), + DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ), + DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), + GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ), + GENERAL_AMBIGIOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s." ), + GENERAL_AMBIGIOUSFACTORY_METHOD( "Ambiguous mapping methods found for factorizing %s: %s." ), + GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), + GENERAL_VALID_DATE( "given date format \"%s\" is valid." ), + GENERAL_INVALID_DATE( "given date format \"%s\" is invalid. Message: \"%s\"." ), + RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ), + RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ), + RETRIEVAL_VOID_MAPPING_METHOD( "Can't generate mapping method with return type void." ), + RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE( "The result type is not assignable to the the return type." ), + RETRIEVAL_ITERABLE_TO_NON_ITERABLE( "Can't generate mapping method from iterable type to non-iterable type." ), + RETRIEVAL_MAPPING_HAS_TARGET_TYPE_PARAMETER( "Can't generate mapping method that has a parameter annotated with @TargetType." ), + RETRIEVAL_NON_ITERABLE_TO_ITERABLE( "Can't generate mapping method from non-iterable type to iterable type." ), + RETRIEVAL_PRIMITIVE_PARAMETER( "Can't generate mapping method with primitive parameter type." ), + RETRIEVAL_PRIMITIVE_RETURN( "Can't generate mapping method with primitive return type." ), + RETRIEVAL_ENUM_TO_NON_ENUM( "Can't generate mapping method from enum type to non-enum type." ), + RETRIEVAL_NON_ENUM_TO_ENUM( "Can't generate mapping method from non-enum type to enum type." ), + INHERITCONFIGURATION_BOTH( "Method cannot be annotated with both a @InheritConfiguration and @InheritInverseConfiguration." ), + INHERITINVERSECONFIGURATION_REFERENCE_HAS_INVERSE( "Resolved inverse mapping method %s() should not carry the @InheritInverseConfiguration annotation itself." ), + INHERITINVERSECONFIGURATION_REFERENCE_HAS_FORWARD( "Resolved inverse mapping method %s() should not carry the @InheritConfiguration annotation." ), + INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), + INHERITINVERSECONFIGURATION_INVALID_NAME( "None of the candidates %s() matches given name: \"%s\"." ), + INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES( "Given name \"%s\" matches several candidate methods: %s()." ), + INHERITINVERSECONFIGURATION_NO_NAME_MATCH( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ), + INHERITCONFIGURATION_REFERENCE_HAS_FORWARD( "Resolved mapping method %s() should not carry the @InheritConfiguration annotation itself." ), + INHERITCONFIGURATION_REFERENCE_HAS_INVERSE( "Resolved mapping method %s() should not carry the @InheritInverseConfiguration annotation." ), + INHERITCONFIGURATION_DUPLICATES( "Several matching methods exist: %s(). Specify a name explicitly." ), + INHERITCONFIGURATION_INVALIDNAME( "None of the candidates %s() matches given name: \"%s\"." ), + INHERITCONFIGURATION_DUPLICATE_MATCHES( "Given name \"%s\" matches several candidate methods: %s()." ), + INHERITCONFIGURATION_NO_NAME_MATCH( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ); // CHECKSTYLE:ON private final String description; + private final Diagnostic.Kind kind; private Message(String description) { this.description = description; + this.kind = Diagnostic.Kind.ERROR; + } + + private Message(String description, Diagnostic.Kind kind) { + this.description = description; + this.kind = kind; } public String getDescription() { return description; } + public Diagnostic.Kind getDiagnosticKind() { + return kind; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/model/common/DefaultConversionContextTest.java index 67da8410c..b33b0336b 100755 --- a/processor/src/test/java/org/mapstruct/ap/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/model/common/DefaultConversionContextTest.java @@ -125,21 +125,20 @@ public class DefaultConversionContextTest { private Diagnostic.Kind lastKindPrinted; @Override - public void printMessage( Diagnostic.Kind kind, Message msg, Object... arg) { - lastKindPrinted = kind; + public void printMessage(Message msg, Object... arg) { + lastKindPrinted = msg.getDiagnosticKind(); } @Override - public void printMessage( Diagnostic.Kind kind, Element e, Message msg, Object... arg) { + public void printMessage(Element e, Message msg, Object... arg) { } @Override - public void printMessage( Diagnostic.Kind kind, Element e, AnnotationMirror a, Message msg, Object... arg) { + public void printMessage(Element e, AnnotationMirror a, Message msg, Object... arg) { } @Override - public void printMessage( Diagnostic.Kind kind, Element e, AnnotationMirror a, AnnotationValue v, - Message msg, Object... arg) { + public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Message msg, Object... arg) { } public Diagnostic.Kind getLastKindPrinted() {