[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:
Blocks
blocks MDSAL-740 Generate fields for all Identityrefs ... Resolved
is blocked by MDSAL-49 Do not generate Builders for Union types Resolved
is blocked by MDSAL-741 Capture union's stringValue() contract Confirmed
Relates
relates to MDSAL-732 Binding generator generates uncompila... Resolved

 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.



 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.

Generated at Wed Feb 07 20:10:47 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.