Merge "Fixed bug in generation of return type for list key properties."
authorRobert Varga <rovarga@cisco.com>
Fri, 31 Jan 2014 19:25:40 +0000 (19:25 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 31 Jan 2014 19:25:40 +0000 (19:25 +0000)
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend

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) {