Binding v2 - fix wrong imports from binding v1 12/70312/2
authorJie Han <han.jie@zte.com.cn>
Wed, 4 Apr 2018 03:04:20 +0000 (11:04 +0800)
committerJie Han <han.jie@zte.com.cn>
Wed, 4 Apr 2018 03:15:14 +0000 (11:15 +0800)
- It's a mistake to import classes from binding v1
  when bug MDSAL-253 ported changes from binding v1,
  just fix up.

- Eliminates a mistoken merged yang file.

Change-Id: Ifb094a128d32a45601bb0f1b3af6144e11521897
Signed-off-by: Jie Han <han.jie@zte.com.cn>
binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/UnionTypeCodec.java
binding2/mdsal-binding2-java-api-generator/src/test/resources/test/opendaylight-mdsal-binding-test.yang [deleted file]

index ec7cef148bc4d3a4288c06f6d9ae4f1c81a5e780..7c56dd752508ed6950ebf2a8a7c6216efa435344 100755 (executable)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.javav2.dom.codec.impl;
 
-import static org.opendaylight.yangtools.yang.binding.BindingMapping.toFirstUpper;
+import static org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeSpecificIdentifier;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableSet;
@@ -19,10 +19,8 @@ import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.UnionValueOp
 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.base.BindingCodecContext;
 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.value.ReflectionBasedCodec;
 import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier;
-import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer;
 import org.opendaylight.mdsal.binding.javav2.generator.yang.types.BaseYangTypes;
 import org.opendaylight.yangtools.concepts.Codec;
-import org.opendaylight.yangtools.yang.binding.BindingMapping;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
@@ -66,8 +64,8 @@ public final class UnionTypeCodec extends ReflectionBasedCodec {
                 if (subtype instanceof LeafrefTypeDefinition) {
                     addLeafrefValueCodec(unionCls, unionType, bindingCodecContext, values, subtype);
                 } else {
-                    final Method valueGetter = unionCls.getMethod("get" + JavaIdentifierNormalizer
-                            .normalizeSpecificIdentifier(subtype.getQName().getLocalName(), JavaIdentifier.CLASS));
+                    final Method valueGetter = unionCls.getMethod("get"
+                        normalizeSpecificIdentifier(subtype.getQName().getLocalName(), JavaIdentifier.CLASS));
                     final Class<?> valueType = valueGetter.getReturnType();
                     final Codec<Object, Object> valueCodec = bindingCodecContext.getCodec(valueType, subtype);
                     values.add(new UnionValueOptionContext(unionCls, valueType, valueGetter, valueCodec));
@@ -105,19 +103,19 @@ public final class UnionTypeCodec extends ReflectionBasedCodec {
         } else {
             dataNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, unionType, xpath);
         }
-        final String className = BindingMapping.getClassName(unionCls.getSimpleName());
+
         final LeafSchemaNode typeNode = (LeafSchemaNode) dataNode;
 
         // prepare name of type form return type of referenced leaf
-        final String typeName = BindingMapping.getClassName(BaseYangTypes.BASE_YANG_TYPES_PROVIDER
-            .javaTypeForSchemaDefinitionType(typeNode.getType(), typeNode, null).getName());
+        final String typeName = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
+            .javaTypeForSchemaDefinitionType(typeNode.getType(), typeNode, null).getName();
 
         // get method via reflection from generated code according to
         // get_TypeName_Value method
-        final String method = toFirstUpper(JavaIdentifierNormalizer.normalizeSpecificIdentifier(
-            new StringBuilder(typeName).append(className).append("Value").toString(), JavaIdentifier.METHOD));
-        final Method valueGetterParent = unionCls
-            .getMethod(new StringBuilder("get").append(method).toString());
+        final String method = normalizeSpecificIdentifier(new StringBuilder("get").append("_")
+            .append(typeName).append(unionCls.getSimpleName()).append("Value").toString(),
+            JavaIdentifier.METHOD);
+        final Method valueGetterParent = unionCls.getMethod(method);
         final Class<?> returnType = valueGetterParent.getReturnType();
 
         // prepare codec of union subtype according to return type of referenced
diff --git a/binding2/mdsal-binding2-java-api-generator/src/test/resources/test/opendaylight-mdsal-binding-test.yang b/binding2/mdsal-binding2-java-api-generator/src/test/resources/test/opendaylight-mdsal-binding-test.yang
deleted file mode 100644 (file)
index 0942c6d..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-module opendaylight-mdsal-binding-test {
-
-    namespace "urn:opendaylight:params:xml:ns:yang:mdsal:test:binding";
-    prefix list-test;
-
-
-    description
-        "This module contains a collection of YANG definitions used for
-        some test cases.";
-
-    revision 2014-07-01 {
-        description
-        "Test model for testing data broker with nested lists.";
-    }
-
-    typedef int32-string-union {
-        type union {
-            type int32;
-            type string;
-        }
-    }
-
-    identity test-root;
-
-    identity test-one {
-        base test-root;
-    }
-
-    identity test-two {
-        base test-root;
-    }
-
-    typedef test-identityref {
-        type identityref {
-            base test-root;
-        }
-    }
-
-    grouping two-level-list {
-        list top-level-list {
-            description
-                "Top Level List";
-            key "name";
-            leaf name {
-                type string;
-            }
-
-            choice choice-in-list {
-                case simple-case {
-                    leaf simple {
-                        type string;
-                    }
-                }
-            }
-
-            list nested-list {
-                key "name";
-                leaf name {
-                    type string;
-                }
-                leaf type {
-                    type string;
-                    mandatory true;
-                    description
-                        "Mandatory type of list.";
-                }
-                ordered-by user;
-                description
-                    "A list of service functions that compose the service chain";
-            }
-        }
-        leaf-list top-level-leaf-list {
-            type string;
-        }
-
-        leaf-list top-level-ordered-leaf-list {
-            type string;
-            ordered-by user;
-        }
-    }
-
-    grouping choice {
-        choice identifier {
-            case simple {
-                container simple-id {
-                    leaf id {
-                        type int32;
-                    }
-                }
-            }
-            case extended {
-                container extended-id {
-                    leaf id {
-                        type string;
-                    }
-                }
-            }
-        }
-    }
-
-    container top {
-        uses two-level-list;
-    }
-
-    container choice-container {
-        uses choice;
-    }
-
-    rpc put-top {
-        input {
-            uses two-level-list;
-        }
-    }
-
-    notification two-level-list-changed {
-        uses two-level-list;
-    }
-
-    rpc get-top {
-        output {
-            uses two-level-list;
-        }
-    }
-
-    augment "/list-test:top" {
-        leaf augmented-string {
-            type string;
-        }
-    }
-
-    augment "/list-test:top" {
-        leaf augmented-int {
-            type int32;
-        }
-    }
-}