Details
-
Improvement
-
Status: Resolved
-
High
-
Resolution: Done
-
None
-
None
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 MDSAL-732) as well as runtime – instead of a plain Class.isInstance() checks an additional Class.isAssignableFrom() to ascertain type safety.
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.
Attachments
Issue Links
- blocks
-
MDSAL-740 Generate fields for all Identityrefs in an Union binding class.
-
- Resolved
-
- is blocked by
-
MDSAL-49 Do not generate Builders for Union types
- Resolved
-
MDSAL-741 Capture union's stringValue() contract
-
- Confirmed
-
- relates to
-
MDSAL-732 Binding generator generates uncompilable code for leafref chain with identityref at the end
-
- Resolved
-