#339 Uppercase for ENUM in messages, moving Diagnostic.Kind to Message

This commit is contained in:
sjaakd 2015-02-04 21:46:10 +01:00
parent 580d7869fd
commit b83c430758
19 changed files with 195 additions and 267 deletions

View File

@ -120,10 +120,9 @@ public class BeanMappingMethod extends MappingMethod {
if ( beanMapping != null && beanMapping.getResultType() != null ) { if ( beanMapping != null && beanMapping.getResultType() != null ) {
resultType = ctx.getTypeFactory().getType( beanMapping.getResultType() ); resultType = ctx.getTypeFactory().getType( beanMapping.getResultType() );
if ( !resultType.isAssignableTo( method.getResultType() ) ) { if ( !resultType.isAssignableTo( method.getResultType() ) ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(),
beanMappingPrism.mirror, 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 // fetch the target property
ExecutableElement targetProperty = unprocessedTargetProperties.get( mapping.getTargetName() ); ExecutableElement targetProperty = unprocessedTargetProperties.get( mapping.getTargetName() );
if ( targetProperty == null ) { if ( targetProperty == null ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(),
mapping.getMirror(), mapping.getMirror(),
mapping.getSourceAnnotationValue(), mapping.getSourceAnnotationValue(),
Message.beanmapping_unknownpropertyinreturntype, Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE,
mapping.getTargetName() mapping.getTargetName()
); );
errorOccurred = true; errorOccurred = true;
@ -310,9 +308,8 @@ public class BeanMappingMethod extends MappingMethod {
if ( propertyMapping != null && newPropertyMapping != null ) { if ( propertyMapping != null && newPropertyMapping != null ) {
// TODO improve error message // TODO improve error message
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(), Message.BEANMAPPING_SEVERAL_POSSIBLE_SOURCES,
Message.beanmapping_severalpossiblesources,
targetProperty.getKey() targetProperty.getKey()
); );
break; break;
@ -389,9 +386,8 @@ public class BeanMappingMethod extends MappingMethod {
} }
// Should never really happen // Should never really happen
else { else {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(), Message.BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS,
Message.beanmapping_severalpossibletargetaccessors,
sourcePropertyName sourcePropertyName
); );
@ -430,9 +426,11 @@ public class BeanMappingMethod extends MappingMethod {
if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) {
ctx.getMessager().printMessage( unmappedTargetPolicy.getDiagnosticKind(), Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
method.getExecutable(), Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING;
Message.beanmapping_unmappedtargets,
ctx.getMessager().printMessage( method.getExecutable(),
msg,
MessageFormat.format( MessageFormat.format(
"{0,choice,1#property|1<properties}: \"{1}\"", "{0,choice,1#property|1<properties}: \"{1}\"",
unprocessedTargetProperties.size(), unprocessedTargetProperties.size(),

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.source.EnumMapping; import org.mapstruct.ap.model.source.EnumMapping;
@ -85,9 +84,8 @@ public class EnumMappingMethod extends MappingMethod {
for ( Mapping mapping : mappedConstants ) { for ( Mapping mapping : mappedConstants ) {
targetConstants.add( mapping.getTargetName() ); targetConstants.add( mapping.getTargetName() );
} }
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(), Message.ENUMMAPPING_MULTIPLE_TARGETS,
Message.enummapping_multipletargets,
enumConstant, enumConstant,
Strings.join( targetConstants, ", " ) Strings.join( targetConstants, ", " )
); );
@ -108,38 +106,34 @@ public class EnumMappingMethod extends MappingMethod {
for ( Mapping mappedConstant : mappedConstants ) { for ( Mapping mappedConstant : mappedConstants ) {
if ( mappedConstant.getSourceName() == null ) { if ( mappedConstant.getSourceName() == null ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(),
mappedConstant.getMirror(), mappedConstant.getMirror(),
Message.enummapping_undefinedsource Message.ENUMMAPPING_UNDEFINED_SOURCE
); );
foundIncorrectMapping = true; foundIncorrectMapping = true;
} }
else if ( !sourceEnumConstants.contains( mappedConstant.getSourceName() ) ) { else if ( !sourceEnumConstants.contains( mappedConstant.getSourceName() ) ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(),
mappedConstant.getMirror(), mappedConstant.getMirror(),
mappedConstant.getSourceAnnotationValue(), mappedConstant.getSourceAnnotationValue(),
Message.enummapping_nonexistingconstant, Message.ENUMMAPPING_NON_EXISTING_CONSTANT,
mappedConstant.getSourceName(), mappedConstant.getSourceName(),
method.getSourceParameters().iterator().next().getType() method.getSourceParameters().iterator().next().getType()
); );
foundIncorrectMapping = true; foundIncorrectMapping = true;
} }
if ( mappedConstant.getTargetName() == null ) { if ( mappedConstant.getTargetName() == null ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(),
mappedConstant.getMirror(), mappedConstant.getMirror(),
Message.enummapping_undefinedtarget Message.ENUMMAPPING_UNDEFINED_TARGET
); );
foundIncorrectMapping = true; foundIncorrectMapping = true;
} }
else if ( !targetEnumConstants.contains( mappedConstant.getTargetName() ) ) { else if ( !targetEnumConstants.contains( mappedConstant.getTargetName() ) ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(),
mappedConstant.getMirror(), mappedConstant.getMirror(),
mappedConstant.getTargetAnnotationValue(), mappedConstant.getTargetAnnotationValue(),
Message.enummapping_nonexistingconstant, Message.ENUMMAPPING_NON_EXISTING_CONSTANT,
mappedConstant.getTargetName(), mappedConstant.getTargetName(),
method.getReturnType() method.getReturnType()
); );
@ -167,9 +161,8 @@ public class EnumMappingMethod extends MappingMethod {
} }
if ( !unmappedSourceEnumConstants.isEmpty() ) { if ( !unmappedSourceEnumConstants.isEmpty() ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(), Message.ENUMMAPPING_UNMAPPED_TARGETS,
Message.enummapping_unmappedtargets,
Strings.join( unmappedSourceEnumConstants, ", " ) Strings.join( unmappedSourceEnumConstants, ", " )
); );
} }

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.assignment.Assignment; import org.mapstruct.ap.model.assignment.Assignment;
import org.mapstruct.ap.model.assignment.LocalVarWrapper; import org.mapstruct.ap.model.assignment.LocalVarWrapper;
@ -112,8 +111,7 @@ public class IterableMappingMethod extends MappingMethod {
); );
if ( assignment == null ) { if ( assignment == null ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, method.getExecutable(), ctx.getMessager().printMessage( method.getExecutable(), Message.ITERABLEMAPPING_MAPPING_NOT_FOUND );
Message.iterablemapping_mappingnotfound );
} }
// target accessor is setter, so decorate assignment as setter // target accessor is setter, so decorate assignment as setter

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.model;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.assignment.Assignment; import org.mapstruct.ap.model.assignment.Assignment;
import org.mapstruct.ap.model.assignment.LocalVarWrapper; import org.mapstruct.ap.model.assignment.LocalVarWrapper;
@ -120,8 +119,7 @@ public class MapMappingMethod extends MappingMethod {
); );
if ( keyAssignment == null ) { if ( keyAssignment == null ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, method.getExecutable(), ctx.getMessager().printMessage( method.getExecutable(), Message.MAPMAPPING_KEY_MAPPING_NOT_FOUND );
Message.mapmapping_key_mappingnotfound );
} }
// find mapping method or conversion for value // find mapping method or conversion for value
@ -141,8 +139,7 @@ public class MapMappingMethod extends MappingMethod {
); );
if ( valueAssignment == null ) { if ( valueAssignment == null ) {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, method.getExecutable(), ctx.getMessager().printMessage( method.getExecutable(), Message.MAPMAPPING_VALUE_MAPPING_NOT_FOUND );
Message.mapmapping_value_mappingnotfound );
} }
// mapNullToDefault // mapNullToDefault

View File

@ -23,7 +23,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.assignment.AdderWrapper; import org.mapstruct.ap.model.assignment.AdderWrapper;
import org.mapstruct.ap.model.assignment.ArrayCopyWrapper; import org.mapstruct.ap.model.assignment.ArrayCopyWrapper;
@ -172,9 +171,8 @@ public class PropertyMapping extends ModelElement {
} }
} }
else { else {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(), Message.PROPERTYMAPPING_MAPPING_NOT_FOUND,
Message.propertymapping_mappingnotfound,
sourceElement, sourceElement,
targetType, targetType,
targetPropertyName, targetPropertyName,
@ -531,9 +529,8 @@ public class PropertyMapping extends ModelElement {
} }
} }
else { else {
ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, ctx.getMessager().printMessage( method.getExecutable(),
method.getExecutable(), Message.CONSTANTMAPPING_MAPPING_NOT_FOUND,
Message.constantmapping_mappingnotfound,
sourceType, sourceType,
constantExpression, constantExpression,
targetType, targetType,

View File

@ -18,7 +18,6 @@
*/ */
package org.mapstruct.ap.model.common; package org.mapstruct.ap.model.common;
import javax.tools.Diagnostic;
import org.mapstruct.ap.util.Message; import org.mapstruct.ap.util.Message;
import org.mapstruct.ap.util.FormattingMessager; import org.mapstruct.ap.util.FormattingMessager;
@ -49,7 +48,7 @@ final class DateFormatValidationResult {
} }
public void printErrorMessage(FormattingMessager messager) { public void printErrorMessage(FormattingMessager messager) {
messager.printMessage( Diagnostic.Kind.ERROR, validationInfo, validationInfoArgs ); messager.printMessage( validationInfo, validationInfoArgs );
} }
} }

View File

@ -74,7 +74,7 @@ final class DateFormatValidatorFactory {
dateFormatValidator = new DateFormatValidator() { dateFormatValidator = new DateFormatValidator() {
@Override @Override
public DateFormatValidationResult validate(String dateFormat) { public DateFormatValidationResult validate(String dateFormat) {
return new DateFormatValidationResult( true, Message.general_unsupporteddateformatcheck, return new DateFormatValidationResult( true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK,
sourceType, targetType ); sourceType, targetType );
} }
}; };
@ -179,10 +179,10 @@ final class DateFormatValidatorFactory {
} }
private static DateFormatValidationResult validDateFormat(String dateFormat) { private static DateFormatValidationResult validDateFormat(String dateFormat) {
return new DateFormatValidationResult( true, Message.general_validdate, dateFormat ); return new DateFormatValidationResult( true, Message.GENERAL_VALID_DATE, dateFormat );
} }
private static DateFormatValidationResult invalidDateFormat(String dateFormat, Throwable e) { private static DateFormatValidationResult invalidDateFormat(String dateFormat, Throwable e) {
return new DateFormatValidationResult( false, Message.general_invaliddate, dateFormat, e.getMessage() ); return new DateFormatValidationResult( false, Message.GENERAL_INVALID_DATE, dateFormat, e.getMessage() );
} }
} }

View File

@ -23,7 +23,6 @@ import org.mapstruct.ap.util.FormattingMessager;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.prism.BeanMappingPrism; import org.mapstruct.ap.prism.BeanMappingPrism;
import org.mapstruct.ap.util.Message; import org.mapstruct.ap.util.Message;
@ -46,7 +45,7 @@ public class BeanMapping {
boolean resultTypeIsDefined = !TypeKind.VOID.equals( beanMapping.resultType().getKind() ); boolean resultTypeIsDefined = !TypeKind.VOID.equals( beanMapping.resultType().getKind() );
if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() ) { if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, method, Message.beanmapping_noelements ); messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS );
} }
return new BeanMapping( return new BeanMapping(

View File

@ -25,7 +25,6 @@ import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.prism.IterableMappingPrism; import org.mapstruct.ap.prism.IterableMappingPrism;
import org.mapstruct.ap.util.Message; import org.mapstruct.ap.util.Message;
@ -53,7 +52,7 @@ public class IterableMapping {
if ( !elementTargetTypeIsDefined if ( !elementTargetTypeIsDefined
&& iterableMapping.dateFormat().isEmpty() && iterableMapping.dateFormat().isEmpty()
&& iterableMapping.qualifiedBy().isEmpty() ) { && iterableMapping.qualifiedBy().isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, method, Message.iterablemapping_noelements ); messager.printMessage( method, Message.ITERABLEMAPPING_NO_ELEMENTS );
} }
return new IterableMapping( return new IterableMapping(

View File

@ -24,7 +24,6 @@ import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.prism.MapMappingPrism; import org.mapstruct.ap.prism.MapMappingPrism;
import org.mapstruct.ap.util.Message; import org.mapstruct.ap.util.Message;
@ -58,7 +57,7 @@ public class MapMapping {
&& mapMapping.valueQualifiedBy().isEmpty() && mapMapping.valueQualifiedBy().isEmpty()
&& !keyTargetTypeIsDefined && !keyTargetTypeIsDefined
&& !valueTargetTypeIsDefined ) { && !valueTargetTypeIsDefined ) {
messager.printMessage( Diagnostic.Kind.ERROR, method, Message.mapmapping_noelements ); messager.printMessage( method, Message.MAPMAPPING_NO_ELEMENTS );
} }

View File

@ -32,8 +32,6 @@ import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.DeclaredType; import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import org.mapstruct.ap.model.common.TypeFactory; import org.mapstruct.ap.model.common.TypeFactory;
import org.mapstruct.ap.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.prism.CollectionMappingStrategyPrism;
@ -82,11 +80,7 @@ public class Mapping {
mappingsOfProperty.add( mapping ); mappingsOfProperty.add( mapping );
if ( mappingsOfProperty.size() > 1 && !isEnumType( method.getReturnType() ) ) { if ( mappingsOfProperty.size() > 1 && !isEnumType( method.getReturnType() ) ) {
messager.printMessage( Kind.ERROR, messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, mappingPrism.target() );
method,
Message.propertymapping_duplicatetargets,
mappingPrism.target()
);
} }
} }
} }
@ -98,34 +92,24 @@ public class Mapping {
FormattingMessager messager) { FormattingMessager messager) {
if ( mappingPrism.target().isEmpty() ) { if ( mappingPrism.target().isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( element,
element,
mappingPrism.mirror, mappingPrism.mirror,
mappingPrism.values.target(), mappingPrism.values.target(),
Message.propertymapping_emptytarget Message.PROPERTYMAPPING_EMPTY_TARGET
); );
return null; return null;
} }
if ( !mappingPrism.source().isEmpty() && !mappingPrism.constant().isEmpty() ) { if ( !mappingPrism.source().isEmpty() && !mappingPrism.constant().isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED );
element,
Message.propertymapping_sourceandconstantbothdefined
);
return null; return null;
} }
else if ( !mappingPrism.source().isEmpty() && !mappingPrism.expression().isEmpty() ) { else if ( !mappingPrism.source().isEmpty() && !mappingPrism.expression().isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED );
element,
Message.propertymapping_sourceandexpressionbothdefined
);
return null; return null;
} }
else if ( !mappingPrism.expression().isEmpty() && !mappingPrism.constant().isEmpty() ) { else if ( !mappingPrism.expression().isEmpty() && !mappingPrism.constant().isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED );
element,
Message.propertymapping_expressionandconstantbothdefined
);
return null; return null;
} }
@ -180,12 +164,8 @@ public class Mapping {
Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.expression() ); Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.expression() );
if ( !javaExpressionMatcher.matches() ) { if ( !javaExpressionMatcher.matches() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( element, mappingPrism.mirror, mappingPrism.values.expression(),
element, Message.PROPERTYMAPPING_INVALID_EXPRESSION );
mappingPrism.mirror,
mappingPrism.values.expression(),
Message.propertymapping_invalidexpression
);
return null; return null;
} }
@ -295,11 +275,8 @@ public class Mapping {
if ( sourceReference != null && sourceReference.getPropertyEntries().isEmpty() ) { if ( sourceReference != null && sourceReference.getPropertyEntries().isEmpty() ) {
// parameter mapping only, apparently the @InheritReverseConfiguration is intentional // parameter mapping only, apparently the @InheritReverseConfiguration is intentional
// but erroneous. Lets raise an error to warn. // but erroneous. Lets raise an error to warn.
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(), Message.PROPERTYMAPPING_REVERSAL_PROBLEM,
method.getExecutable(), sourceReference.getParameter() );
Message.propertymapping_reversalproblem,
sourceReference.getParameter()
);
return null; return null;
} }

View File

@ -24,7 +24,6 @@ import java.util.List;
import org.mapstruct.ap.util.FormattingMessager; import org.mapstruct.ap.util.FormattingMessager;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.common.Type;
@ -115,7 +114,7 @@ public class SourceReference {
String sourceParameterName = segments[0]; String sourceParameterName = segments[0];
parameter = method.getSourceParameter( sourceParameterName ); parameter = method.getSourceParameter( sourceParameterName );
if ( parameter == null ) { if ( parameter == null ) {
reportMappingError( Message.propertymapping_invalidparametername, sourceParameterName ); reportMappingError( Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, sourceParameterName );
isValid = false; isValid = false;
} }
} }
@ -155,15 +154,11 @@ public class SourceReference {
if ( !foundEntryMatch ) { if ( !foundEntryMatch ) {
if ( parameter != null ) { if ( parameter != null ) {
reportMappingError( Message.propertymapping_nopropertyinparameter, reportMappingError( Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER, parameter.getName(),
parameter.getName(), Strings.join( Arrays.asList( sourcePropertyNames ), "." ) );
Strings.join( Arrays.asList( sourcePropertyNames ), "." )
);
} }
else { else {
reportMappingError( Message.propertymapping_invalidpropertyname, reportMappingError( Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName() );
mapping.getSourceName()
);
} }
isValid = false; isValid = false;
} }
@ -193,14 +188,8 @@ public class SourceReference {
} }
private void reportMappingError(Message msg, Object... objects) { private void reportMappingError(Message msg, Object... objects) {
messager.printMessage( messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(),
Diagnostic.Kind.ERROR, msg, objects );
method.getExecutable(),
mapping.getMirror(),
mapping.getSourceAnnotationValue(),
msg,
objects
);
} }
} }

View File

@ -109,38 +109,38 @@ public class DefaultModelElementProcessorContext implements ProcessorContext {
} }
@Override @Override
public void printMessage( Kind kind, Message msg, Object... args) { public void printMessage(Message msg, Object... args) {
String message = String.format( msg.getDescription(), args ); String message = String.format( msg.getDescription(), args );
delegate.printMessage( kind, message); delegate.printMessage( msg.getDiagnosticKind(), message);
if ( kind == Kind.ERROR ) { if ( msg.getDiagnosticKind() == Kind.ERROR ) {
isErroneous = true; isErroneous = true;
} }
} }
@Override @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 ); String message = String.format( msg.getDescription(), args );
delegate.printMessage( kind, message, e ); delegate.printMessage( msg.getDiagnosticKind(), message, e );
if ( kind == Kind.ERROR ) { if ( msg.getDiagnosticKind() == Kind.ERROR ) {
isErroneous = true; isErroneous = true;
} }
} }
@Override @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 ); String message = String.format( msg.getDescription(), args );
delegate.printMessage( kind, message, e, a ); delegate.printMessage( msg.getDiagnosticKind(), message, e, a );
if ( kind == Kind.ERROR ) { if ( msg.getDiagnosticKind() == Kind.ERROR ) {
isErroneous = true; isErroneous = true;
} }
} }
@Override @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) { Object... args) {
String message = String.format( msg.getDescription(), args ); String message = String.format( msg.getDescription(), args );
delegate.printMessage( kind, message, e, a, v ); delegate.printMessage( msg.getDiagnosticKind(), message, e, a, v );
if ( kind == Kind.ERROR ) { if ( msg.getDiagnosticKind() == Kind.ERROR ) {
isErroneous = true; isErroneous = true;
} }
} }

View File

@ -32,8 +32,6 @@ import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements; import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; 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.BeanMappingMethod;
import org.mapstruct.ap.model.Decorator; import org.mapstruct.ap.model.Decorator;
@ -166,7 +164,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratorPrism.value() ); TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratorPrism.value() );
if ( !typeUtils.isAssignable( decoratorElement.asType(), element.asType() ) ) { if ( !typeUtils.isAssignable( decoratorElement.asType(), element.asType() ) ) {
messager.printMessage( Kind.ERROR, element, decoratorPrism.mirror, Message.decorator_nosubtype); messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_NO_SUBTYPE);
} }
List<MappingMethod> mappingMethods = new ArrayList<MappingMethod>( methods.size() ); List<MappingMethod> mappingMethods = new ArrayList<MappingMethod>( methods.size() );
@ -204,7 +202,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
} }
if ( !hasDelegateConstructor && !hasDefaultConstructor ) { if ( !hasDelegateConstructor && !hasDefaultConstructor ) {
messager.printMessage( Kind.ERROR, element, decoratorPrism.mirror, Message.decorator_constructor ); messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_CONSTRUCTOR );
} }
return Decorator.getInstance( return Decorator.getInstance(
@ -360,11 +358,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
if ( method.getReturnType().getTypeMirror().getKind() != TypeKind.VOID && if ( method.getReturnType().getTypeMirror().getKind() != TypeKind.VOID &&
method.getReturnType().isInterface() && method.getReturnType().isInterface() &&
method.getReturnType().getImplementationType() == null ) { method.getReturnType().getImplementationType() == null ) {
messager.printMessage( Kind.ERROR, messager.printMessage( method.getExecutable(), Message.GENERAL_NO_IMPLEMENTATION, method.getReturnType() );
method.getExecutable(),
Message.general_noimplementation,
method.getReturnType()
);
} }
} }
@ -506,11 +500,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
method.getExecutable() method.getExecutable()
); );
if ( reversePrism != null ) { if ( reversePrism != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(), reversePrism.mirror, Message.INHERITCONFIGURATION_BOTH );
method.getExecutable(),
reversePrism.mirror,
Message.inheritconfiguration_both
);
} }
} }
@ -524,10 +514,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
); );
if ( candidatePrism != null ) { if ( candidatePrism != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
reversePrism.mirror, reversePrism.mirror,
Message.inheritinverseconfiguration_referencehasinverse, Message.INHERITINVERSECONFIGURATION_REFERENCE_HAS_INVERSE,
candidate.getName() candidate.getName()
); );
} }
@ -536,10 +525,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
candidate.getExecutable() candidate.getExecutable()
); );
if ( candidateTemplatePrism != null ) { if ( candidateTemplatePrism != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
reversePrism.mirror, reversePrism.mirror,
Message.inheritinverseconfiguration_referencehasforward, Message.INHERITINVERSECONFIGURATION_REFERENCE_HAS_FORWARD,
candidate.getName() candidate.getName()
); );
} }
@ -555,19 +543,17 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
String name = reversePrism.name(); String name = reversePrism.name();
if ( name.isEmpty() ) { if ( name.isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
reversePrism.mirror, reversePrism.mirror,
Message.inheritinverseconfiguration_duplicates, Message.INHERITINVERSECONFIGURATION_DUPLICATES,
Strings.join( candidateNames, "(), " ) Strings.join( candidateNames, "(), " )
); );
} }
else { else {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
reversePrism.mirror, reversePrism.mirror,
Message.inheritinverseconfiguration_invalidname, Message.INHERITINVERSECONFIGURATION_INVALID_NAME,
Strings.join( candidateNames, "(), " ), Strings.join( candidateNames, "(), " ),
name name
@ -578,10 +564,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method, private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
InheritInverseConfigurationPrism reversePrism) { InheritInverseConfigurationPrism reversePrism) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
reversePrism.mirror, reversePrism.mirror,
Message.inheritinverseconfiguration_duplicatematches, Message.INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES,
reversePrism.name(), reversePrism.name(),
Strings.join( candidates, "(), " ) Strings.join( candidates, "(), " )
@ -591,10 +576,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
InheritInverseConfigurationPrism reversePrism) { InheritInverseConfigurationPrism reversePrism) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
reversePrism.mirror, reversePrism.mirror,
Message.inheritinverseconfiguration_nonamematch, Message.INHERITINVERSECONFIGURATION_NO_NAME_MATCH,
reversePrism.name(), reversePrism.name(),
onlyCandidate.getName() onlyCandidate.getName()
); );
@ -609,10 +593,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
); );
if ( candidatePrism != null ) { if ( candidatePrism != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
prism.mirror, prism.mirror,
Message.inheritconfiguration_referencehasforward, Message.INHERITCONFIGURATION_REFERENCE_HAS_FORWARD,
candidate.getName() candidate.getName()
); );
} }
@ -622,10 +605,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
); );
if ( candidateInversePrism != null ) { if ( candidateInversePrism != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
prism.mirror, prism.mirror,
Message.inheritconfiguration_referencehasinverse, Message.INHERITCONFIGURATION_REFERENCE_HAS_INVERSE,
candidate.getName() candidate.getName()
); );
} }
@ -641,18 +623,16 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
String name = prism.name(); String name = prism.name();
if ( name.isEmpty() ) { if ( name.isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
prism.mirror, prism.mirror,
Message.inheritconfiguration_duplicates, Message.INHERITCONFIGURATION_DUPLICATES,
Strings.join( candidateNames, "(), " ) Strings.join( candidateNames, "(), " )
); );
} }
else { else {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
prism.mirror, prism.mirror,
Message.inheritconfiguration_invalidname, Message.INHERITCONFIGURATION_INVALIDNAME,
Strings.join( candidateNames, "(), " ), Strings.join( candidateNames, "(), " ),
name name
); );
@ -662,10 +642,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method, private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
InheritConfigurationPrism prism) { InheritConfigurationPrism prism) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
prism.mirror, prism.mirror,
Message.inheritconfiguration_duplicatematches, Message.INHERITCONFIGURATION_DUPLICATE_MATCHES,
prism.name(), prism.name(),
Strings.join( candidates, "(), " ) Strings.join( candidates, "(), " )
); );
@ -674,10 +653,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
InheritConfigurationPrism prims) { InheritConfigurationPrism prims) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( method.getExecutable(),
method.getExecutable(),
prims.mirror, prims.mirror,
Message.inheritconfiguration_nonamematch, Message.INHERITCONFIGURATION_NO_NAME_MATCH,
prims.name(), prims.name(),
onlyCandidate.getName() onlyCandidate.getName()
); );

View File

@ -35,7 +35,6 @@ import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements; import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; import javax.lang.model.util.Types;
import javax.tools.Diagnostic.Kind;
import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.common.Type;
@ -272,60 +271,60 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
Parameter targetParameter, Type resultType, Type returnType, Parameter targetParameter, Type resultType, Type returnType,
boolean containsTargetTypeParameter) { boolean containsTargetTypeParameter) {
if ( sourceParameters.isEmpty() ) { if ( sourceParameters.isEmpty() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_noinputargs ); messager.printMessage( method, Message.RETRIEVAL_NO_INPUT_ARGS );
return false; return false;
} }
if ( targetParameter != null && ( sourceParameters.size() + 1 != method.getParameters().size() ) ) { if ( targetParameter != null && ( sourceParameters.size() + 1 != method.getParameters().size() ) ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_duplicatemappingtargets ); messager.printMessage( method, Message.RETRIEVAL_DUPLICATE_MAPPING_TARGETS );
return false; return false;
} }
if ( resultType.getTypeMirror().getKind() == TypeKind.VOID ) { if ( resultType.getTypeMirror().getKind() == TypeKind.VOID ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_voidmappingmethod ); messager.printMessage( method, Message.RETRIEVAL_VOID_MAPPING_METHOD );
return false; return false;
} }
if ( returnType.getTypeMirror().getKind() != TypeKind.VOID && if ( returnType.getTypeMirror().getKind() != TypeKind.VOID &&
!resultType.isAssignableTo( returnType ) ) { !resultType.isAssignableTo( returnType ) ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_nonassignableresulttype ); messager.printMessage( method, Message.RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE );
return false; return false;
} }
Type parameterType = sourceParameters.get( 0 ).getType(); Type parameterType = sourceParameters.get( 0 ).getType();
if ( parameterType.isIterableType() && !resultType.isIterableType() ) { if ( parameterType.isIterableType() && !resultType.isIterableType() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_iterabletononiterable ); messager.printMessage( method, Message.RETRIEVAL_ITERABLE_TO_NON_ITERABLE );
return false; return false;
} }
if ( containsTargetTypeParameter ) { if ( containsTargetTypeParameter ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_mappinghastargettypeparameter ); messager.printMessage( method, Message.RETRIEVAL_MAPPING_HAS_TARGET_TYPE_PARAMETER );
return false; return false;
} }
if ( !parameterType.isIterableType() && resultType.isIterableType() ) { if ( !parameterType.isIterableType() && resultType.isIterableType() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_noniterabletoiterable ); messager.printMessage( method, Message.RETRIEVAL_NON_ITERABLE_TO_ITERABLE );
return false; return false;
} }
if ( parameterType.isPrimitive() ) { if ( parameterType.isPrimitive() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_primitiveparameter ); messager.printMessage( method, Message.RETRIEVAL_PRIMITIVE_PARAMETER );
return false; return false;
} }
if ( resultType.isPrimitive() ) { if ( resultType.isPrimitive() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_primitivereturn ); messager.printMessage( method, Message.RETRIEVAL_PRIMITIVE_RETURN );
return false; return false;
} }
if ( parameterType.isEnumType() && !resultType.isEnumType() ) { if ( parameterType.isEnumType() && !resultType.isEnumType() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_enumtononenum ); messager.printMessage( method, Message.RETRIEVAL_ENUM_TO_NON_ENUM );
return false; return false;
} }
if ( !parameterType.isEnumType() && resultType.isEnumType() ) { if ( !parameterType.isEnumType() && resultType.isEnumType() ) {
messager.printMessage( Kind.ERROR, method, Message.retrieval_nonenumtoenum ); messager.printMessage( method, Message.RETRIEVAL_NON_ENUM_TO_ENUM );
return false; return false;
} }

View File

@ -27,7 +27,6 @@ import org.mapstruct.ap.util.FormattingMessager;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements; import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import org.mapstruct.ap.conversion.ConversionProvider; import org.mapstruct.ap.conversion.ConversionProvider;
import org.mapstruct.ap.conversion.Conversions; import org.mapstruct.ap.conversion.Conversions;
@ -465,18 +464,16 @@ public class MappingResolverImpl implements MappingResolver {
if ( candidates.size() > 1 ) { if ( candidates.size() > 1 ) {
if ( mappedElement != null ) { if ( mappedElement != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( mappingMethod.getExecutable(),
mappingMethod.getExecutable(), Message.GENERAL_AMBIGIOUS_MAPPING_METHOD,
Message.general_ambigiousmappingmethod,
mappedElement, mappedElement,
returnType, returnType,
Strings.join( candidates, ", " ) Strings.join( candidates, ", " )
); );
} }
else { else {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage( mappingMethod.getExecutable(),
mappingMethod.getExecutable(), Message.GENERAL_AMBIGIOUSFACTORY_METHOD,
Message.general_ambigiousfactorymethod,
returnType, returnType,
Strings.join( candidates, ", " ) Strings.join( candidates, ", " )
); );

View File

@ -21,37 +21,33 @@ package org.mapstruct.ap.util;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
public interface FormattingMessager { public interface FormattingMessager {
/** /**
* Prints a message of the specified kind. * Prints a message of the specified kind.
* *
* @param kind the kind of message
* @param msg the message * @param msg the message
* @param args Arguments referenced by the format specifiers in the format string. If there are more arguments * @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 * 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 * Prints a message of the specified kind at the location of the
* element. * element.
* *
* @param kind the kind of message
* @param e the element to use as a position hint * @param e the element to use as a position hint
* @param msg the message * @param msg the message
* @param args Arguments referenced by the format specifiers in the format string. If there are more arguments * @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 * 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 * Prints a message of the specified kind at the location of the
* annotation mirror of the annotated element. * annotation mirror of the annotated element.
* *
* @param kind the kind of message
* @param e the annotated element * @param e the annotated element
* @param a the annotation to use as a position hint * @param a the annotation to use as a position hint
* @param msg the message * @param msg the message
@ -59,14 +55,13 @@ public interface FormattingMessager {
* than format specifiers, the extra arguments are ignored * 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 * Prints a message of the specified kind at the location of the
* annotation value inside the annotation mirror of the annotated * annotation value inside the annotation mirror of the annotated
* element. * element.
* *
* @param kind the kind of message
* @param e the annotated element * @param e the annotated element
* @param a the annotation containing the annotation value * @param a the annotation containing the annotation value
* @param v the annotation value to use as a position hint * @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 * @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 * than format specifiers, the extra arguments are ignored
*/ */
void printMessage( Diagnostic.Kind kind, void printMessage(Element e,
Element e,
AnnotationMirror a, AnnotationMirror a,
AnnotationValue v, AnnotationValue v,
Message msg, Message msg,

View File

@ -18,83 +18,99 @@
*/ */
package org.mapstruct.ap.util; package org.mapstruct.ap.util;
import javax.tools.Diagnostic;
/** /**
* *
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public enum Message { public enum Message {
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
beanmapping_noelements( "'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), // CHECKSTYLE:OFF
beanmapping_notassignable( "%s not assignable to: %s." ), BEANMAPPING_NO_ELEMENTS( "'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ),
beanmapping_unknownpropertyinreturntype( "Unknown property \"%s\" in return type." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ),
beanmapping_severalpossiblesources( "Several possible source properties for target property \"%s\"." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE( "Unknown property \"%s\" in return type." ),
beanmapping_severalpossibletargetaccessors( "Found several matching getters for property \"%s\"." ), BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ),
beanmapping_unmappedtargets( "Unmapped target %s." ), BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS( "Found several matching getters for property \"%s\"." ),
propertymapping_mappingnotfound( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), BEANMAPPING_UNMAPPED_TARGETS_WARNING( "Unmapped target %s.", Diagnostic.Kind.WARNING ),
propertymapping_duplicatetargets( "Target property \"%s\" must not be mapped more than once." ), BEANMAPPING_UNMAPPED_TARGETS_ERROR( "Unmapped target %s." ),
propertymapping_emptytarget( "Target must not be empty in @Mapping." ), PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ),
propertymapping_sourceandconstantbothdefined( "Source and constant are both defined in @Mapping, either define a source or a constant." ), PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ),
propertymapping_sourceandexpressionbothdefined( "Source and expression are both defined in @Mapping, either define a source or an expression." ), PROPERTYMAPPING_EMPTY_TARGET( "Target must not be empty in @Mapping." ),
propertymapping_expressionandconstantbothdefined( "Expression and constant are both defined in @Mapping, either define an expression or a constant." ), PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED( "Source and constant are both defined in @Mapping, either define a source or a constant." ),
propertymapping_invalidexpression( "Value must be given in the form \"java(<EXPRESSION>)\"." ), PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED( "Source and expression are both defined in @Mapping, either define a source or an expression." ),
propertymapping_reversalproblem( "Parameter %s cannot be reversed." ), PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED( "Expression and constant are both defined in @Mapping, either define an expression or a constant." ),
propertymapping_invalidparametername( "Method has no parameter named \"%s\"." ), PROPERTYMAPPING_INVALID_EXPRESSION( "Value must be given in the form \"java(<EXPRESSION>)\"." ),
propertymapping_nopropertyinparameter( "The type of parameter \"%s\" has no property named \"%s\"." ), PROPERTYMAPPING_REVERSAL_PROBLEM( "Parameter %s cannot be reversed." ),
propertymapping_invalidpropertyname( "No property named \"%s\" exists in source parameter(s)." ), PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no parameter named \"%s\"." ),
constantmapping_mappingnotfound( "Can't map \"%s %s\" to \"%s %s\"." ), PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%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." ), PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s)." ),
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." ), CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ),
mapmapping_noelements( "'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', 'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, define at least one of them." ), 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." ),
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." ), 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." ),
iterablemapping_noelements( "'dateformat', 'qualifiedBy' and 'elementTargetType' are undefined in @IterableMapping, define at least one of them." ), MAPMAPPING_NO_ELEMENTS( "'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', 'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, 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." ), 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." ),
enummapping_undefinedsource( "A source constant must be specified for mappings of an enum mapping method." ), ITERABLEMAPPING_NO_ELEMENTS( "'dateformat', 'qualifiedBy' and 'elementTargetType' are undefined in @IterableMapping, define at least one of them." ),
enummapping_nonexistingconstant( "Constant %s doesn't exist in enum type %s." ), ENUMMAPPING_MULTIPLE_TARGETS( "One enum constant must not be mapped to more than one target constant, but constant %s is mapped to %s." ),
enummapping_undefinedtarget( "A target constant must be specified for mappings of an enum mapping method." ), ENUMMAPPING_UNDEFINED_SOURCE( "A source 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." ), ENUMMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ),
decorator_nosubtype( "Specified decorator type is no subtype of the annotated mapper type." ), ENUMMAPPING_UNDEFINED_TARGET( "A target constant must be specified for mappings of an enum mapping method." ),
decorator_constructor( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), 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." ),
general_noimplementation( "No implementation type is registered for return type %s." ), DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ),
general_ambigiousmappingmethod( "Ambiguous mapping methods found for mapping %s to %s: %s." ), DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ),
general_ambigiousfactorymethod( "Ambiguous mapping methods found for factorizing %s: %s." ), GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ),
general_unsupporteddateformatcheck( "No dateFormat check is supported for types %s, %s" ), GENERAL_AMBIGIOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s." ),
general_validdate( "given date format \"%s\" is valid." ), GENERAL_AMBIGIOUSFACTORY_METHOD( "Ambiguous mapping methods found for factorizing %s: %s." ),
general_invaliddate( "given date format \"%s\" is invalid. Message: \"%s\"." ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ),
retrieval_noinputargs( "Can't generate mapping method with no input arguments." ), GENERAL_VALID_DATE( "given date format \"%s\" is valid." ),
retrieval_duplicatemappingtargets( "Can't generate mapping method with more than one @MappingTarget parameter." ), GENERAL_INVALID_DATE( "given date format \"%s\" is invalid. Message: \"%s\"." ),
retrieval_voidmappingmethod( "Can't generate mapping method with return type void." ), RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ),
retrieval_nonassignableresulttype( "The result type is not assignable to the the return type." ), RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ),
retrieval_iterabletononiterable( "Can't generate mapping method from iterable type to non-iterable type." ), RETRIEVAL_VOID_MAPPING_METHOD( "Can't generate mapping method with return type void." ),
retrieval_mappinghastargettypeparameter( "Can't generate mapping method that has a parameter annotated with @TargetType." ), RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE( "The result type is not assignable to the the return type." ),
retrieval_noniterabletoiterable( "Can't generate mapping method from non-iterable type to iterable type." ), RETRIEVAL_ITERABLE_TO_NON_ITERABLE( "Can't generate mapping method from iterable type to non-iterable type." ),
retrieval_primitiveparameter( "Can't generate mapping method with primitive parameter type." ), RETRIEVAL_MAPPING_HAS_TARGET_TYPE_PARAMETER( "Can't generate mapping method that has a parameter annotated with @TargetType." ),
retrieval_primitivereturn( "Can't generate mapping method with primitive return type." ), RETRIEVAL_NON_ITERABLE_TO_ITERABLE( "Can't generate mapping method from non-iterable type to iterable type." ),
retrieval_enumtononenum( "Can't generate mapping method from enum type to non-enum type." ), RETRIEVAL_PRIMITIVE_PARAMETER( "Can't generate mapping method with primitive parameter type." ),
retrieval_nonenumtoenum( "Can't generate mapping method from non-enum type to enum type." ), RETRIEVAL_PRIMITIVE_RETURN( "Can't generate mapping method with primitive return type." ),
inheritconfiguration_both( "Method cannot be annotated with both a @InheritConfiguration and @InheritInverseConfiguration." ), RETRIEVAL_ENUM_TO_NON_ENUM( "Can't generate mapping method from enum type to non-enum type." ),
inheritinverseconfiguration_referencehasinverse( "Resolved inverse mapping method %s() should not carry the @InheritInverseConfiguration annotation itself." ), RETRIEVAL_NON_ENUM_TO_ENUM( "Can't generate mapping method from non-enum type to enum type." ),
inheritinverseconfiguration_referencehasforward( "Resolved inverse mapping method %s() should not carry the @InheritConfiguration annotation." ), INHERITCONFIGURATION_BOTH( "Method cannot be annotated with both a @InheritConfiguration and @InheritInverseConfiguration." ),
inheritinverseconfiguration_duplicates( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), INHERITINVERSECONFIGURATION_REFERENCE_HAS_INVERSE( "Resolved inverse mapping method %s() should not carry the @InheritInverseConfiguration annotation itself." ),
inheritinverseconfiguration_invalidname( "None of the candidates %s() matches given name: \"%s\"." ), INHERITINVERSECONFIGURATION_REFERENCE_HAS_FORWARD( "Resolved inverse mapping method %s() should not carry the @InheritConfiguration annotation." ),
inheritinverseconfiguration_duplicatematches( "Given name \"%s\" matches several candidate methods: %s()." ), INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ),
inheritinverseconfiguration_nonamematch( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ), INHERITINVERSECONFIGURATION_INVALID_NAME( "None of the candidates %s() matches given name: \"%s\"." ),
inheritconfiguration_referencehasforward( "Resolved mapping method %s() should not carry the @InheritConfiguration annotation itself." ), INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES( "Given name \"%s\" matches several candidate methods: %s()." ),
inheritconfiguration_referencehasinverse( "Resolved mapping method %s() should not carry the @InheritInverseConfiguration annotation." ), INHERITINVERSECONFIGURATION_NO_NAME_MATCH( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ),
inheritconfiguration_duplicates( "Several matching methods exist: %s(). Specify a name explicitly." ), INHERITCONFIGURATION_REFERENCE_HAS_FORWARD( "Resolved mapping method %s() should not carry the @InheritConfiguration annotation itself." ),
inheritconfiguration_invalidname( "None of the candidates %s() matches given name: \"%s\"." ), INHERITCONFIGURATION_REFERENCE_HAS_INVERSE( "Resolved mapping method %s() should not carry the @InheritInverseConfiguration annotation." ),
inheritconfiguration_duplicatematches( "Given name \"%s\" matches several candidate methods: %s()." ), INHERITCONFIGURATION_DUPLICATES( "Several matching methods exist: %s(). Specify a name explicitly." ),
inheritconfiguration_nonamematch( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ); 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 // CHECKSTYLE:ON
private final String description; private final String description;
private final Diagnostic.Kind kind;
private Message(String description) { private Message(String description) {
this.description = 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() { public String getDescription() {
return description; return description;
} }
public Diagnostic.Kind getDiagnosticKind() {
return kind;
}
} }

View File

@ -125,21 +125,20 @@ public class DefaultConversionContextTest {
private Diagnostic.Kind lastKindPrinted; private Diagnostic.Kind lastKindPrinted;
@Override @Override
public void printMessage( Diagnostic.Kind kind, Message msg, Object... arg) { public void printMessage(Message msg, Object... arg) {
lastKindPrinted = kind; lastKindPrinted = msg.getDiagnosticKind();
} }
@Override @Override
public void printMessage( Diagnostic.Kind kind, Element e, Message msg, Object... arg) { public void printMessage(Element e, Message msg, Object... arg) {
} }
@Override @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 @Override
public void printMessage( Diagnostic.Kind kind, Element e, AnnotationMirror a, AnnotationValue v, public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Message msg, Object... arg) {
Message msg, Object... arg) {
} }
public Diagnostic.Kind getLastKindPrinted() { public Diagnostic.Kind getLastKindPrinted() {