From 7a9464c525443a197a2df7081a9bb544bd8847a1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jun 2017 20:25:42 +0200 Subject: [PATCH] #1150 Improve error reporting for nested properties --- .../org/mapstruct/ap/internal/model/PropertyMapping.java | 4 +++- .../nestedbeans/exclusions/ErroneousJavaInternalTest.java | 8 +++++++- .../mapstruct/ap/test/nestedbeans/exclusions/Source.java | 4 +--- .../mapstruct/ap/test/nestedbeans/exclusions/Target.java | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 51cb0da68..db7fa579f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -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(), diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index db2e37e71..b367dbf57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -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 { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java index da8e64d32..adeaba126 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java @@ -47,8 +47,6 @@ class Source { public MyType date; public MyType calendar; public List 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 } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java index 7ceedbd35..3691541ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java @@ -43,6 +43,6 @@ class Target { public Date date; public GregorianCalendar calendar; public List types; - //public TargetNested nestedMyType; + public TargetNested nestedMyType; //CHECKSTYLE:ON }