Map system-ordered leaf-lists to Set<T>
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / reactor / LeafListGenerator.java
index eb9b36ebf074e7fda50fc9e895060446b030ab31..f20ad882aa49fca638dc9ce408b9cace0ecd1bff 100644 (file)
@@ -9,7 +9,9 @@ package org.opendaylight.mdsal.binding.generator.impl.reactor;
 
 import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.mdsal.binding.model.ri.Types;
+import org.opendaylight.yangtools.yang.common.Ordering;
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OrderedByEffectiveStatement;
 
 /**
  * Generator corresponding to a {@code leaf-list} statement.
@@ -24,6 +26,16 @@ final class LeafListGenerator extends AbstractTypeAwareGenerator<LeafListEffecti
         // If we are a leafref and the reference cannot be resolved, we need to generate a list wildcard, not
         // List<Object>, we will try to narrow the return type in subclasses.
         final Type type = super.methodReturnType(builderFactory);
-        return Types.objectType().equals(type) ? Types.listTypeWildcard() : Types.listTypeFor(type);
+        final boolean isObject = Types.objectType().equals(type);
+        final Ordering ordering = statement().findFirstEffectiveSubstatementArgument(OrderedByEffectiveStatement.class)
+            .orElse(Ordering.SYSTEM);
+        switch (ordering) {
+            case SYSTEM:
+                return isObject ? Types.setTypeWildcard() : Types.setTypeFor(type);
+            case USER:
+                return isObject ? Types.listTypeWildcard() : Types.listTypeFor(type);
+            default:
+                throw new IllegalStateException("Unexpected ordering " + ordering);
+        }
     }
 }