Auto constraint name resolution for extracting method references [concept] #115
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Documentation defines constraint like this:
The suggested draft implementation enhances the way to define a constraint:
How it works. The lambda method reference
User::getName
passed asToCharSequence
is resolved via newLambdaUtils.unreferenceLambdaMethod
. It usesjava.lang.invoke.SerializedLambda
that allows to extract method information at runtime, then take the method name "getName" and finally resolve it as "name" constraint (cuts getter prefix).Pros:
LambdaUtils
is validated on a wide range of cases, so it looks reliableLambdaUtils
implementation is forward-compatible to Java 1.8 and higher (really make sense in comparison with other approaches to resolve the method reference)Cons:
For now it is just stubbed as "extracted" string.
Please note, that this implementation is an incomplete PoC, so let me know what do you think and in case of green light I'll finish it.