mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1150 Improve error reporting for nested properties
This commit is contained in:
parent
a3eca8c8ca
commit
7a9464c525
@ -324,7 +324,9 @@ public class PropertyMapping extends ModelElement {
|
||||
*/
|
||||
private void reportCannotCreateMapping() {
|
||||
if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).getHistory() != null ) {
|
||||
ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory();
|
||||
// The history that is part of the ForgedMethod misses the information from the current right hand
|
||||
// side. Therefore we need to extract the most relevant history and use that in the error reporting.
|
||||
ForgedMethodHistory history = getForgedMethodHistory( rightHandSide );
|
||||
reportCannotCreateMapping(
|
||||
method,
|
||||
history.createSourcePropertyErrorMessage(),
|
||||
|
@ -57,7 +57,13 @@ public class ErroneousJavaInternalTest {
|
||||
line = 29,
|
||||
messageRegExp = "Can't map property \".*List<.*MyType> types\" to \".*List<.*String> types\"\\" +
|
||||
". Consider to declare/implement a mapping method: \".*List<.*String> map\\(.*List<.*MyType> " +
|
||||
"value\\)\"\\.")
|
||||
"value\\)\"\\."),
|
||||
@Diagnostic(type = ErroneousJavaInternalMapper.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 29,
|
||||
messageRegExp = "Can't map property \".*List<.*MyType> nestedMyType\\.deepNestedType\\.types\" to \"" +
|
||||
".*List<.*String> nestedMyType\\.deepNestedType\\.types\"\\. Consider to declare/implement a " +
|
||||
"mapping method: \".*List<.*String> map\\(.*List<.*MyType> value\\)\"\\.")
|
||||
})
|
||||
@Test
|
||||
public void shouldNotNestIntoJavaPackageObjects() throws Exception {
|
||||
|
@ -47,8 +47,6 @@ class Source {
|
||||
public MyType date;
|
||||
public MyType calendar;
|
||||
public List<MyType> types;
|
||||
//TODO Nested error messages do not work yet. I think that this should be solved as part of #1150
|
||||
// (or we solve that one first :))
|
||||
//public NestedMyType nestedMyType;
|
||||
public NestedMyType nestedMyType;
|
||||
//CHECKSTYLE:ON
|
||||
}
|
||||
|
@ -43,6 +43,6 @@ class Target {
|
||||
public Date date;
|
||||
public GregorianCalendar calendar;
|
||||
public List<String> types;
|
||||
//public TargetNested nestedMyType;
|
||||
public TargetNested nestedMyType;
|
||||
//CHECKSTYLE:ON
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user