Fixed bug in generation of return type for list key properties. 85/4885/1
authorMartin Vitez <mvitez@cisco.com>
Mon, 27 Jan 2014 14:25:11 +0000 (15:25 +0100)
committerMartin Vitez <mvitez@cisco.com>
Mon, 27 Jan 2014 14:25:11 +0000 (15:25 +0100)
Signed-off-by: Martin Vitez <mvitez@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java

index 4411c09aecbe8057a247483f66efa8f2d7230008..e5aa5c4c2286f9660fcfa58319cce5060f79e66c 100644 (file)
@@ -1553,7 +1553,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
      *         </ul>\r
      */
     private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf,
-        boolean isReadOnly) {
+        boolean isReadOnly, Module module) {
         if ((leaf !== null) && (toBuilder !== null)) {
             val leafName = leaf.QName.localName;
             var String leafDesc = leaf.description;
@@ -1561,11 +1561,24 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 leafDesc = "";
             }
 
-            if (leafName !== null) {
-                val TypeDefinition<?> typeDef = leaf.type;
+            if (leafName !== null) {\r
+                var Type returnType = null;
+                val TypeDefinition<?> typeDef = leaf.type;\r
+                if (typeDef instanceof UnionTypeDefinition) {\r
+                    // GeneratedType for this type definition should be already created\r
+                    var qname = typeDef.QName\r
+                    var Module unionModule = null\r
+                    if (qname.prefix == null || qname.prefix.empty) {\r
+                        unionModule = module\r
+                    } else {\r
+                        unionModule = findModuleFromImports(module.imports, qname.prefix)\r
+                    }\r
+                    val ModuleContext mc = genCtx.get(unionModule)\r
+                    returnType = mc.typedefs.get(typeDef.path)\r
+                } else {\r
+                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);\r
+                }
 
-                // TODO: properly resolve enum types\r
-                val returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
                 if (returnType !== null) {
                     val propBuilder = toBuilder.addProperty(parseToValidParamName(leafName));
                     propBuilder.setReadOnly(isReadOnly);
@@ -1860,7 +1873,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
             val leafName = leaf.QName.localName;\r
             resolveLeafSchemaNodeAsMethod(typeBuilder, leaf);
             if (listKeys.contains(leafName)) {
-                resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true);
+                resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true, module)
             }
         } else if (!schemaNode.addedByUses) {
             if (schemaNode instanceof LeafListSchemaNode) {
index d800d15a26a664c06cbc12973f949a7b54206dd2..e51e4684323f63df9bd14fa6f6501ce1b48a034e 100644 (file)
@@ -25,7 +25,7 @@ public interface SchemaContext extends ContainerSchemaNode {
     /**
      * Returns data schema node instances which represents direct subnodes (like
      * leaf, leaf-list, list, container) in all YANG modules in the context.
-     * 
+     *
      * @return set of <code>DataSchemaNode</code> instances which represents
      *         YANG data nodes at the module top level
      */
@@ -33,16 +33,16 @@ public interface SchemaContext extends ContainerSchemaNode {
 
     /**
      * Returns modules which are part of the schema context.
-     * 
+     *
      * @return set of the modules which belong to the schema context
      */
     Set<Module> getModules();
 
     /**
-     * 
+     *
      * Returns notification definition instances which are defined as the direct
      * subelements in all YANG modules in the context.
-     * 
+     *
      * @return set of <code>NotificationDefinition</code> instances which
      *         represents nodes defined via <code>notification</code> YANG
      *         keyword
@@ -52,7 +52,7 @@ public interface SchemaContext extends ContainerSchemaNode {
     /**
      * Returns rpc definition instances which are defined as the direct
      * subelements in all YANG modules in the context.
-     * 
+     *
      * @return set of <code>RpcDefinition</code> instances which represents
      *         nodes defined via <code>rpc</code> YANG keyword
      */
@@ -61,7 +61,7 @@ public interface SchemaContext extends ContainerSchemaNode {
     /**
      * Returns extencion definition instances which are defined as the direct
      * subelements in all YANG modules in the context
-     * 
+     *
      * @return set of <code>ExtensionDefinition</code> instances which
      *         represents nodes defined via <code>extension</code> YANG keyword
      */
@@ -70,7 +70,7 @@ public interface SchemaContext extends ContainerSchemaNode {
     /**
      * Returns module instance (from the context) with concrete name and
      * revision date.
-     * 
+     *
      * @param name
      *            string with the module name
      * @param revision
@@ -79,20 +79,29 @@ public interface SchemaContext extends ContainerSchemaNode {
      *         same as are the values specified in parameters <code>name</code>
      *         and <code>revision</code>. In other cases the <code>null</code>
      *         value is returned.
-     * 
+     *
      */
     Module findModuleByName(final String name, final Date revision);
 
     /**
-     * 
+     *
      * Returns module instance (from the context) with concrete namespace.
-     * 
+     *
      * @param namespace
      *            URI instance with specified namespace
      * @return module instance which has namespace equal to the
      *         <code>namespace</code> or <code>null</code> in other cases
      */
     Set<Module> findModuleByNamespace(final URI namespace);
-    
-    Module findModuleByNamespaceAndRevision(final URI namespace,final Date revision);
+
+    /**
+     * Returns module instance based on given namespace and revision. If
+     * revision is not specified, returns module with newest revision.
+     *
+     * @param namespace
+     * @param revision
+     * @return
+     */
+    Module findModuleByNamespaceAndRevision(final URI namespace, final Date revision);
+
 }
index b7face08fcf30f07d4e06ebfb7094438dd321f1f..73b2cb637e7828b5ac22a614f8d261b4af74612b 100644 (file)
@@ -15,6 +15,7 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeMap;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
@@ -114,9 +115,22 @@ final class SchemaContextImpl implements SchemaContext {
     @Override
     public Module findModuleByNamespaceAndRevision(URI namespace, Date revision) {
         if (namespace != null) {
-            for (final Module module : modules) {
-                if (module.getNamespace().equals(namespace) && module.getRevision().equals(revision)) {
-                    return(module);
+            Set<Module> modules = findModuleByNamespace(namespace);
+
+            if (revision == null) {
+                TreeMap<Date, Module> map = new TreeMap<Date, Module>();
+                for (Module module : modules) {
+                    map.put(module.getRevision(), module);
+                }
+                if (map.isEmpty()) {
+                    return null;
+                }
+                return map.lastEntry().getValue();
+            } else {
+                for (Module module : modules) {
+                    if (module.getRevision().equals(revision)) {
+                        return(module);
+                    }
                 }
             }
         }