#3628 Add locale parameter for numberFormat#3693
Conversation
filiphr
left a comment
There was a problem hiding this comment.
Thanks for your work on this @Obolrom. It is on the right track. However, it still needs some work before it is in a mergeable state. I've left some inline comments, but there are some other more general remarks as well:
- The use of
new Localepublic constructor. This constructor has been deprecated in Java 19 and there isLocale.forLanguageTagavailable since Java 7, let's use that everywhere instead. - I see that we are only supporting the
numberFormatin the@Mappingfor this. However, we also havedateFormatin@Mappingand we also have the following (if we are adding thelocalewe need to support it everywhere):MapMapping#keyNumberFormatMapMapping#keyDateFormatMapMapping#valueNumberFormatMapMapping#valueDateFormatIterableMapping#numberFormatIterableMapping#dateFormat
- I don't see any tests with a custom locale. The
NumberFormatConversionRuLocaleTestis identical toNumberFormatConversionTest, with the only difference being that a different default locale is used. What we need instead is in theNumberFormatConversionTest(which runs using the defaultenlocale to have mappers using a custom locale. - An additional improvement could be that we store the passed
Localeto the method in a field, but this is more complex and this can be an additional improvement.
processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java
Outdated
Show resolved
Hide resolved
processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl
Outdated
Show resolved
Hide resolved
|
@filiphr, thank you for the quick feedback. However, I didn't understand your idea about
|
Ignore that for now. It isn't that important |
filiphr
left a comment
There was a problem hiding this comment.
I've missed some things in my previous review. Have a look at my comments. We strive to have a readable generated code. What is being done now is not really readable, let's try to not have full qualified names if possible.
| if ( conversionContext.getLocale() != null ) { | ||
| sb.append( ", java.util.Locale.forLanguageTag( \"" ); | ||
| sb.append( conversionContext.getLocale() ); | ||
| sb.append( "\" )" ); | ||
| } | ||
| else { | ||
| sb.append( ", java.util.Locale.getDefault() " ); | ||
| } |
There was a problem hiding this comment.
We strive to have as much readable code as possible. having a full qualified name here isn't readable 😉. Please have a look at how we are doing it in the getFromExpression for the BigDecimal import
| if ( conversionContext.getLocale() != null ) { | ||
| sb.append( ", Locale.forLanguageTag( \"" ); | ||
| sb.append( conversionContext.getLocale() ); | ||
| sb.append( "\" )" ); | ||
| } | ||
| else { | ||
| sb.append( ", Locale.getDefault() " ); | ||
| } |
There was a problem hiding this comment.
Same comment as in BigDecimalToStringConversion
|
@filiphr However, right now we have some code duplications We can make |
1580228 to
2d461c8
Compare
2d461c8 to
7388038
Compare
|
@filiphr |
|
Looks better @Obolrom. However, I see that there is a change in behaviour and now we always pass i.e. there should be no need to change anything in existing tests. |
|
If you are busy, I can apply these changes while merging |
|
@filiphr |
|
@Obolrom it will most definitely not be closed today. I'll apply the changes when I start the merge |
Implementation of enhancement #3628
e.g.
Fixes #3628