Fix LeafListSchemaNode.getDefaults() 13/65113/7
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2017 16:41:51 +0000 (17:41 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Nov 2017 10:24:41 +0000 (11:24 +0100)
This method should be non-default, as marked by FIXME. Furthermore
it should represent a readily-parsed set of values, such that they
can be fed into a data container.

Change-Id: Ib63b3a5a419b13f79901632251b7584f3d18d2b8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/LeafListSchemaNode.java
yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6880Test.java

index db24be09cefbeb7f64f48cac3aac746a05b9217c..c78b26b9e7454e15e47e0f436598ea6c74aeacef 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
-import com.google.common.collect.ImmutableList;
 import java.util.Collection;
 import javax.annotation.Nonnull;
 
@@ -25,15 +24,11 @@ public interface LeafListSchemaNode extends TypedSchemaNode {
     boolean isUserOrdered();
 
     /**
-     * All implementations should override this method.
-     * The default definition of this method is used only in YANG 1.0 (RFC6020) implementation of
-     * LeafListSchemaNode which does not support default statements.
-     * YANG leaf-list statement has been changed in YANG 1.1 (RFC7950) and now allows default statements.
+     * Return the default value of this leaf-list, as per the rules outlined in
+     * <a href="https://tools.ietf.org/html/rfc7950#section-7.7.4">Section 7.4.4 of RFC7950</a>. RFC6020 does not
+     * allow for default value of leaf-list, hence the returned list will be empty.
      *
-     * @return collection of Strings which specify the default values of this leaf-list
+     * @return Ordered list of Strings which specify the default values of this leaf-list
      */
-     // FIXME: version 2.0.0: make this method non-default
-    @Nonnull default Collection<String> getDefaults() {
-        return ImmutableList.of();
-    }
+    @Nonnull Collection<? extends Object> getDefaults();
 }
index 0c8f0fda1ade06745b3e37ffbd323192aa0043cc..d9657eab421577018fea10c0b03757ccc38ab8fa 100644 (file)
@@ -1573,8 +1573,8 @@ abstract class SchemaContextEmitter {
             super.writer.endNode();
         }
 
-        private void emitDefaultNodes(final Collection<String> defaults) {
-            for (final String defaultValue : defaults) {
+        private void emitDefaultNodes(final Collection<? extends Object> defaults) {
+            for (final Object defaultValue : defaults) {
                 emitDefaultNode(defaultValue);
             }
         }
index ae6824f16b29040bf0228b0156c5e1310270795c..a9e265183ec8ffa31bca7cb0a89c341a2190031b 100644 (file)
@@ -66,6 +66,7 @@ public final class LeafListEffectiveStatementImpl extends AbstractEffectiveDataS
             }
         }
 
+        // FIXME: We need to interpret the default value in terms of supplied element type
         defaultValues = defaultValuesBuilder.build();
         SourceException.throwIf(
                 TypeUtils.hasDefaultValueMarkedWithIfFeature(ctx.getRootVersion(), typeStmt, defaultValues),
@@ -73,6 +74,8 @@ public final class LeafListEffectiveStatementImpl extends AbstractEffectiveDataS
                 "Leaf-list '%s' has one of its default values '%s' marked with an if-feature statement.",
                 ctx.getStatementArgument(), defaultValues);
 
+        // FIXME: RFC7950 section 7.7.4: we need to check for min-elements and defaultValues conflict
+
         type = builder.build();
         userOrdered = isUserOrdered;
     }
index 05ac83409e49a70bae59e89eb1657836955102d8..a44bde1430d51d50e37e43a261016f5e89715c15 100644 (file)
@@ -37,7 +37,7 @@ public class Bug6880Test {
         assertTrue(findDataSchemaNode instanceof LeafListSchemaNode);
         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
 
-        final Collection<String> defaults = myLeafList.getDefaults();
+        final Collection<? extends Object> defaults = myLeafList.getDefaults();
         assertEquals(2, defaults.size());
         assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
     }