-
Notifications
You must be signed in to change notification settings - Fork 35
[JENKINS-53825] Choose from ambiguous class names via a simple heuristic #40
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
base: master
Are you sure you want to change the base?
Conversation
If there are multiple possible classes matching a name on resolution, filter for just classes that are either inner classes of the model class, are in the same package as the model class, or are in subpackages of the model class's package. If more than one class passes those filters, we'll still fail. Also starts reporting all possible clases when there are more than two of them.
stephenc
left a comment
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.
Not entirely clear that heuristics are the best way. I think an extension point to help narrow options might be a better route
|
I'm thinking of this initial work as just a first step - still needs symbol resolution, and I would like to add an extension point as well. I'm starting small. =) |
|
Yeah, symbol ambiguity resolution would definitely require a new API in |
|
@stephenc - I added some initial work on adding |
|
...check that, I wrote less tests by end of day yesterday than I thought I had, so I'm not 100% sure it works for |
| @Documented | ||
| public @interface Symbol { | ||
| String[] value(); | ||
| Class<?>[] context() default {}; |
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.
I think I like this idea.
Would help to express your plan in the javadoc for this.
I think what you want is that where there are multiple options with the same name, if there is one with the "closest" context, then that one will win.
TBH I like that, because we can do something like @Symbol(value="discoverOriginPRs", context={GitHubSCMSource.class,GitHubSCMNavigator.class}) and we get the win.
The problem, as I see it, is in deciding which is the nearer context if the context is not an exact match.
i.e. If the context is an interface or a parent class.
You'll need to clearly spell out how you decide the nearest context... and if multiple symbols are the same name at the same distance, we fall back to ambiguous
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.
My original idea was to just have an extension point that the symbol library could consult in the case where it had conflicts.
The extension point would basically be given a list of candidate symbols and the context in which these were requested and remove any that it wants from the list.
We then walk all implementations of the extension in order. If the list is empty, we stop and say "no match". If we get to the end and there is more than one, we stop and say "ambiguous" and if we have exactly one "winner"
And we need to process the list of extensions all the way to the end, as we don't know if a later impl might remove the one option we are left with bringing us to an empty list
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.
But with this... while requiring changes on the implementation plugins... we get a less "magic" solution... so as long as you define what is "closest" I think this will work really well
jglick
left a comment
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.
This all sounds overengineered to me. Use
@Symbol("discoverGitHubForkPRs")and go home.
|
No. We’ll have 7-8 of the logical equivalent but all with redundant names repeating the SCM. I want to encourage a common set of patterns across the different SCMs |
|
The first part of this (heuristically-determined disambiguation of short class names) is relevant before we even get to symbol naming philosophy - getting, say, I'm a bit more soft on the symbol disambiguation - my gut instincts are to go with @jglick's approach of deliberately disambiguated symbol names, but I can see the argument in the other direction's merits. |
|
Ok, actually, the more I work on implementing the symbol disambiguation and dealing with the pile of corner cases around nested |
Then define a single |
|
So, for the admittedly not publicly visible use case for this, what I need is a way to have Symbol disambiguation is only needed for what @stephenc wants - it'd be a slightly nicer user experience, but as I said above, I think it's probably more complex and edge-case-error-prone than is worth doing. I've got it "working" locally in The simplest option would just be to add non-ambiguous symbols to everything I care about (namely various |
|
So here is my thoughts on the matter:
What I think is that we need to filter the list of candidates based on the setter/getter signature and allow other extensions to assist in that filtering. Ideally the filtering should also take into account the generic type bounds, as this would actually solve the SCM API use case... but I can see other cases where the API defining plugin may need to provide a "smarter" assistant to the filtering. If you want to go the other way, then I respectfully ask that you setup a global registry of symbol names across all plugins and provide a process whereby people can register that they have grabbed that name in order to remove the risk of conflicts. If the absurdity of maintaining such a registry does not encourage you to see that we actually need symbol disambiguation, well I give up! |
JENKINS-53825
If there are multiple possible classes matching a name on resolution,
filter for just classes that are either inner classes of the model
class, are in the same package as the model class, or are in
subpackages of the model class's package. If more than one class
passes those filters, we'll still fail.
Also starts reporting all possible clases when there are more than two
of them.