Skip to content

Conversation

@Clashsoft
Copy link
Contributor

@Clashsoft Clashsoft commented Dec 23, 2019

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

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.

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.
@Clashsoft Clashsoft changed the title Generic attributerenderer Generic AttributeRenderer Dec 23, 2019
@Clashsoft Clashsoft force-pushed the generic-attributerenderer branch from 7a58ee7 to 1162f7f Compare December 23, 2019 12:17
@Clashsoft Clashsoft changed the title Generic AttributeRenderer Generify AttributeRenderer Dec 23, 2019
@parrt
Copy link
Member

parrt commented Dec 23, 2019

Wow! Interesting change. Let me consider this.

@parrt
Copy link
Member

parrt commented Dec 24, 2019

@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?

@sharwell
Copy link
Member

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.

Copy link
Member

@sharwell sharwell left a 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.

Clashsoft and others added 7 commits December 29, 2019 10:53
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
@parrt parrt requested a review from sharwell December 29, 2019 17:07
@parrt
Copy link
Member

parrt commented Dec 29, 2019

Thanks alot, @sharwell !

@sharwell
Copy link
Member

@Clashsoft would you be willing to submit a pull request to make the same change for ModelAdaptor after we merge this?

@parrt parrt merged commit 19eb20b into antlr:master Dec 29, 2019
@Clashsoft Clashsoft deleted the generic-attributerenderer branch December 30, 2019 11:04
Clashsoft added a commit to Clashsoft/stringtemplate4 that referenced this pull request Dec 30, 2019
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.
Clashsoft added a commit to Clashsoft/stringtemplate4 that referenced this pull request Jan 8, 2020
@Clashsoft Clashsoft mentioned this pull request Jan 8, 2020
Clashsoft added a commit to Clashsoft/stringtemplate4 that referenced this pull request Jan 8, 2020
Clashsoft added a commit to Clashsoft/stringtemplate4 that referenced this pull request Jan 11, 2020
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.
parrt added a commit that referenced this pull request Jan 11, 2020
Fix backward compatibility issues introduced by #233
@parrt parrt added this to the 4.3 milestone Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants