#1756 better forged method error based on empty target bean properties (#1757)

This commit is contained in:
Sjaak Derksen 2019-03-19 09:44:27 +01:00 committed by Filip Hrisafov
parent fe22c9b1ce
commit 66055f024b
8 changed files with 51 additions and 40 deletions

View File

@ -829,7 +829,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
ForgedMethodHistory history = forgedMethod.getHistory(); ForgedMethodHistory history = forgedMethod.getHistory();
ctx.getMessager().printMessage( ctx.getMessager().printMessage(
this.method.getExecutable(), this.method.getExecutable(),
Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, Message.PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND,
history.createSourcePropertyErrorMessage(), history.createSourcePropertyErrorMessage(),
history.getTargetType(), history.getTargetType(),
history.createTargetPropertyName(), history.createTargetPropertyName(),

View File

@ -184,7 +184,6 @@ public class MapMappingMethod extends NormalTypeMappingMethod {
.getFactoryMethod( method, null, ctx ); .getFactoryMethod( method, null, ctx );
} }
keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false ); keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false );
valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes(), valueTargetType, false ); valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes(), valueTargetType, false );

View File

@ -32,7 +32,8 @@ public enum Message {
BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ),
PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ),
PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND( "Can't map %s to %s. Consider to implement a mapping method: \"%s map(%s value)\"." ), PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND( "No target bean properties found: can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ),
PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND( "No target bean properties found: can't map %s to %s. Consider to implement a mapping method: \"%s map(%s value)\"." ),
PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ), PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ),
PROPERTYMAPPING_EMPTY_TARGET( "Target must not be empty in @Mapping." ), 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_CONSTANT_BOTH_DEFINED( "Source and constant are both defined in @Mapping, either define a source or a constant." ),

View File

@ -104,9 +104,9 @@ public class ErroneousCollectionMappingTest {
@Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 25, line = 25,
messageRegExp = "Can't map Collection element \".*WithProperties withProperties\" to \".*NoProperties" + messageRegExp = "No target bean properties found: can't map Collection element \".*WithProperties "
" noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + "withProperties\" to \".*NoProperties noProperties\". Consider to declare/implement "
".*WithProperties value\\)") + "a mapping method: \".*NoProperties map\\(.*WithProperties value\\)")
} }
) )
public void shouldFailOnNoElementMappingFound() { public void shouldFailOnNoElementMappingFound() {
@ -138,9 +138,10 @@ public class ErroneousCollectionMappingTest {
@Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 25, line = 25,
messageRegExp = "Can't map Map key \".*WithProperties withProperties\" to \".*NoProperties " + messageRegExp = "No target bean properties found: can't map Map key \".*WithProperties "
"noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + "withProperties\" to "
".*WithProperties value\\)") + "\".*NoProperties noProperties\". Consider to declare/implement a mapping method: "
+ "\".*NoProperties map\\(.*WithProperties value\\)" )
} }
) )
public void shouldFailOnNoKeyMappingFound() { public void shouldFailOnNoKeyMappingFound() {
@ -171,9 +172,10 @@ public class ErroneousCollectionMappingTest {
@Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 25, line = 25,
messageRegExp = "Can't map Map value \".*WithProperties withProperties\" to \".*NoProperties " + messageRegExp = "No target bean properties found: can't map Map value \".*WithProperties "
"noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + "withProperties\" to "
".*WithProperties value\\)") + "\".*NoProperties noProperties\". Consider to declare/implement a mapping method: "
+ "\".*NoProperties map\\(.*WithProperties value\\)" )
} }
) )
public void shouldFailOnNoValueMappingFound() { public void shouldFailOnNoValueMappingFound() {

View File

@ -87,8 +87,8 @@ public class CollectionMappingTest {
@Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class, @Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 17, line = 17,
messageRegExp = "Can't map Collection element \".* nonMappableSet\" to \".* nonMappableSet\". " messageRegExp = "No target bean properties found: can't map Collection element \".* nonMappableSet\" "
+ "Consider to declare/implement a mapping method: .*."), + "to \".* nonMappableSet\". Consider to declare/implement a mapping method: .*." ),
} }
) )
public void shouldGenerateNonMappleMethodForSetMapping() { public void shouldGenerateNonMappleMethodForSetMapping() {
@ -107,13 +107,15 @@ public class CollectionMappingTest {
@Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 17, line = 17,
messageRegExp = "Can't map Map key \".* nonMappableMap\\{:key\\}\" to \".* nonMappableMap\\{:key\\}\". " messageRegExp = "No target bean properties found: can't map Map key \".* nonMappableMap\\{:key\\}\" "
+ "Consider to declare/implement a mapping method: .*."), + "to \".* "
+ "nonMappableMap\\{:key\\}\". Consider to declare/implement a mapping method: .*." ),
@Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 17, line = 17,
messageRegExp = "Can't map Map value \".* nonMappableMap\\{:value\\}\" to \".* " + messageRegExp = "No target bean properties found: can't map Map value \".* "
"nonMappableMap\\{:value\\}\". Consider to declare/implement a mapping method: .*."), + "nonMappableMap\\{:value\\}\" to \".* nonMappableMap\\{:value\\}\". "
+ "Consider to declare/implement a mapping method: .*." ),
} }
) )
public void shouldGenerateNonMappleMethodForMapMapping() { public void shouldGenerateNonMappleMethodForMapMapping() {

View File

@ -104,9 +104,10 @@ public class ErroneousStreamMappingTest {
@Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 24, line = 24,
messageRegExp = "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties " + messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties "
"noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + "withProperties\" to \".*NoProperties noProperties\". "
".*WithProperties value\\)") + "Consider to declare/implement a mapping method: \".*NoProperties "
+ "map\\(.*WithProperties value\\)" )
} }
) )
public void shouldFailOnNoElementMappingFoundForStreamToStream() { public void shouldFailOnNoElementMappingFoundForStreamToStream() {
@ -136,10 +137,11 @@ public class ErroneousStreamMappingTest {
@Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 25, line = 25,
messageRegExp = messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties "
"Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties noProperties\"." + + "withProperties\" to \".*NoProperties noProperties\"."
" Consider to declare/implement a mapping method: \".*NoProperties map\\(.*WithProperties " + + " Consider to declare/implement a mapping method: \".*NoProperties map\\("
"value\\)") + ".*WithProperties "
+ "value\\)" )
} }
) )
public void shouldFailOnNoElementMappingFoundForListToStream() { public void shouldFailOnNoElementMappingFoundForListToStream() {
@ -154,8 +156,9 @@ public class ErroneousStreamMappingTest {
@Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class, @Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 20, line = 20,
messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + messageRegExp = "Can't map stream element \".*AttributedString\" to "
"declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + "\".*String \". Consider to declare/implement a mapping method: \".*String "
+ "map\\(.*AttributedString value\\)" )
} }
) )
public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() {
@ -169,9 +172,10 @@ public class ErroneousStreamMappingTest {
@Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 25, line = 25,
messageRegExp = messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties "
"Can't map Stream element \".*WithProperties withProperties\" to .*NoProperties noProperties\"." + + "withProperties\" to .*NoProperties noProperties\"."
" Consider to declare/implement a mapping method: \".*NoProperties map(.*WithProperties value)") + " Consider to declare/implement a mapping method: \".*NoProperties map("
+ ".*WithProperties value)" )
} }
) )
public void shouldFailOnNoElementMappingFoundForStreamToList() { public void shouldFailOnNoElementMappingFoundForStreamToList() {

View File

@ -70,9 +70,8 @@ public class ForgedStreamMappingTest {
@Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 17, line = 17,
messageRegExp = "Can't map Stream element \".* nonMappableStream\" to \".* nonMappableStream\". " messageRegExp = "No target bean properties found: can't map Stream element \".* nonMappableStream\" "
+ "Consider to declare/implement a mapping method: .*."), + "to \".* nonMappableStream\". Consider to declare/implement a mapping method: .*." ) }
}
) )
public void shouldGenerateNonMappableMethodForSetMapping() { public void shouldGenerateNonMappableMethodForSetMapping() {
} }

View File

@ -85,9 +85,9 @@ public class ConversionTest {
diagnostics = { diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper1.class, @Diagnostic(type = ErroneousSourceTargetMapper1.class,
kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.UpperBoundWrapper" messageRegExp = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection."
+ "<org.mapstruct.ap.test.selection.generics.TypeA> fooUpperBoundFailure\" to " + "generics.UpperBoundWrapper<org.mapstruct.ap.test.selection.generics.TypeA> "
+ "\"org.mapstruct.ap.test.selection.generics.TypeA fooUpperBoundFailure\"") + "fooUpperBoundFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA fooUpperBoundFailure\"")
}) })
public void shouldFailOnUpperBound() { public void shouldFailOnUpperBound() {
} }
@ -99,7 +99,8 @@ public class ConversionTest {
@Diagnostic(type = ErroneousSourceTargetMapper2.class, @Diagnostic(type = ErroneousSourceTargetMapper2.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 16, line = 16,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardExtendsWrapper" messageRegExp = "No target bean properties found: can't map property "
+ "\"org.mapstruct.ap.test.selection.generics.WildCardExtendsWrapper"
+ "<org.mapstruct.ap.test.selection.generics.TypeA> fooWildCardExtendsTypeAFailure\" to" + "<org.mapstruct.ap.test.selection.generics.TypeA> fooWildCardExtendsTypeAFailure\" to"
+ " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardExtendsTypeAFailure\"") + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardExtendsTypeAFailure\"")
}) })
@ -113,7 +114,8 @@ public class ConversionTest {
@Diagnostic(type = ErroneousSourceTargetMapper3.class, @Diagnostic(type = ErroneousSourceTargetMapper3.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 16, line = 16,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics." messageRegExp = "No target bean properties found: can't map property "
+ "\"org.mapstruct.ap.test.selection.generics."
+ "WildCardExtendsMBWrapper<org.mapstruct.ap.test.selection.generics.TypeB> " + "WildCardExtendsMBWrapper<org.mapstruct.ap.test.selection.generics.TypeB> "
+ "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB " + "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB "
+ "fooWildCardExtendsMBTypeBFailure\"") + "fooWildCardExtendsMBTypeBFailure\"")
@ -128,7 +130,8 @@ public class ConversionTest {
@Diagnostic(type = ErroneousSourceTargetMapper4.class, @Diagnostic(type = ErroneousSourceTargetMapper4.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 16, line = 16,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" messageRegExp = "No target bean properties found: can't map property "
+ "\"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper"
+ "<org.mapstruct.ap.test.selection.generics.TypeA> fooWildCardSuperTypeAFailure\" to" + "<org.mapstruct.ap.test.selection.generics.TypeA> fooWildCardSuperTypeAFailure\" to"
+ " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardSuperTypeAFailure\"") + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardSuperTypeAFailure\"")
}) })
@ -142,7 +145,8 @@ public class ConversionTest {
@Diagnostic(type = ErroneousSourceTargetMapper5.class, @Diagnostic(type = ErroneousSourceTargetMapper5.class,
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
line = 16, line = 16,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" messageRegExp = "No target bean properties found: can't map property "
+ "\"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper"
+ "<org.mapstruct.ap.test.selection.generics.TypeC> fooWildCardSuperTypeCFailure\" to" + "<org.mapstruct.ap.test.selection.generics.TypeC> fooWildCardSuperTypeCFailure\" to"
+ " \"org.mapstruct.ap.test.selection.generics.TypeC fooWildCardSuperTypeCFailure\"") + " \"org.mapstruct.ap.test.selection.generics.TypeC fooWildCardSuperTypeCFailure\"")
}) })