[MDSAL-733] Change 'type identityref' Binding representation to normal objects Created: 12/Mar/22 Updated: 14/Apr/22 Resolved: 14/Apr/22 |
|
| Status: | Resolved |
| Project: | mdsal |
| Component/s: | Binding codegen, Binding runtime |
| Affects Version/s: | None |
| Fix Version/s: | 10.0.0 |
| Type: | Improvement | Priority: | High |
| Reporter: | Robert Varga | Assignee: | Robert Varga |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
|
For 'identity' statements we currently generate a plain interface: public interface Foo extends BaseIdentity { public static final @NonNull QName QNAME = $YangModuleInfoImpl.qnameOf("foo"); } without any instantiation. We then use these classes as values wherever we have an identityref. This leads to a rather not nice user experience, where users spell out Foo.class. Furthermore it is also a source of issues, as Class objects require different handling in Java source (see Update the design so that we generate a Foo.VALUE field, which implements the generated interface and also properly expose implementedInterface(): public interface Foo extends BaseIdentity { public static final @NonNull QName QNAME = $YangModuleInfoImpl.qnameOf("foo"); public static final @NonNull Foo VALUE = new Foo() { @Override Class<Foo> implementedInterface() { return Foo.class; } }; @Override Class<? extends Foo> implementedInterface(); } For identityref leaf/leaf-list members change the mapping from Class<? extends Foo> to plain Foo. Users will then use Foo.VALUE instead of Foo.class to identify instances. |
| Comments |
| Comment by Robert Varga [ 14/Apr/22 ] |
|
Changing the mapping removes type erasure from the picture by introducing a reified type for each identity. |