Uploaded image for project: 'mdsal'
  1. mdsal
  2. MDSAL-733

Change 'type identityref' Binding representation to normal objects

    XMLWordPrintable

Details

    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

          # Subject Branch Project Status CR V

          Activity

            People

              rovarga Robert Varga
              rovarga Robert Varga
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: