-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Throw Exception when adding @AutomapConstructor to multiple constructors #2627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw Exception when adding @AutomapConstructor to multiple constructors #2627
Conversation
…nstructor can only be used in one constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, @sogoagain !
Actually, this problem is not affected by the argNameBasedConstructorAutoMapping
setting, so could you please move the test case to org.apache.ibatis.autoconstructor
?
If you are busy, please just let me know and I'll take care of it when I have time.
throw new ExecutorException("@AutomapConstructor should be used in only one constructor."); | ||
} | ||
if (automapConstructors.size() == 1) { | ||
return Optional.of(automapConstructors.get(0)); | ||
} | ||
if (configuration.isArgNameBasedConstructorAutoMapping()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using reduce
?
return Arrays.stream(constructors)
.filter(x -> x.isAnnotationPresent(AutomapConstructor.class))
.reduce((x, y) -> {
throw new ExecutorException("@AutomapConstructor should be used in only one constructor.");
}).or(() -> {
if (configuration.isArgNameBasedConstructorAutoMapping()) {
...
It probably is a matter of preference, so if you don't like it, the current version is fine. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks very good! thank you.
@harawata Thanks for the review! I understood and moved the test code package. also edited the PR title and content. |
- or() requires Java 9 - License years
Fixes #2626
Provides helpful error messages when adding @AutomapConstructor to multiple constructors.
thank you.