-
Notifications
You must be signed in to change notification settings - Fork 234
Generify AttributeRenderer #233
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
Conversation
Add a generic type on the AttributeRenderer interface and make methods using it generic, too. This allows subclasses like NumberRenderer or StringRenderer to not have to use casts. The change remains full binary compatibility because of erasure, and source compatibility for valid uses. Code like ``` group.registerRenderer(Object.class, new StringRenderer()); ``` now produces a compiler error. It would previously have failed at runtime due to the forced (String)o cast.
7a58ee7 to
1162f7f
Compare
|
Wow! Interesting change. Let me consider this. |
|
@sharwell do you think it's safe to add generics here? Is it worth it? I.e., is there really a problem we're solving here? |
|
I think the concept is cool but I'd like to review it when I'm back at a computer to see if we can improve accuracy of some of the implementation details. |
sharwell
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.
I completed my initial review. I left a few comments to help improve accuracy of the type signatures involved in the change. After completing these changes (and confirming that the code follows the best patterns possible given our compatibility constraints), I would like to see ModelAdaptor updated in the same way so the new API is consistent.
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
…cept Class<? extends T> again
|
Thanks alot, @sharwell ! |
|
@Clashsoft would you be willing to submit a pull request to make the same change for |
As suggested in antlr#233 The only change introduced by this that can be considered breaking is the removal of the superclass MapModelAdaptor from AggregateModelAdaptor. The inheritance was replaced by composition. This had to be done because MapModelAdaptor is now a ModelAdaptor<Map>, while AggregateModelAdaptor needs to be a ModelAdaptor<Aggregate>. Previously, AggregateModelAdaptor could not handle a Map, so I think this "breaking" change should not cause any issues.
Reverts NumberRenderer and StringRenderer to accept Object instead of Number or String respectively. NumberRenderer always worked with Object before. Actually it should be called FormatRenderer or similar because it merely uses Formatter, nothing Number-specific. StringRenderer now uses the pre-antlr#233 behaviour of accepting Object at runtime, but failing if the actual value is not a String due to the forced cast.
Fix backward compatibility issues introduced by #233
Add a generic type variable on the AttributeRenderer interface and make methods using it generic, too.
This allows subclasses like NumberRenderer or StringRenderer to not have to use casts.
The change retains full binary compatibility because of erasure, and source compatibility for valid uses. Code like
now produces a compiler error. It would previously have failed at runtime due to the forced (String)o cast.