Fixed regression of Bug 4699 82/30482/2
authorTony Tkacik <ttkacik@cisco.com>
Wed, 2 Dec 2015 12:41:09 +0000 (13:41 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 2 Dec 2015 14:10:14 +0000 (15:10 +0100)
Added special case to leaf method resolution
to use derived type instead of restricted type
to lookup for Java Method.

Change-Id: Ibba83be142f97485cc0f5139da68788a018c4b48
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java

index d56db0c1d02a46b730f83045f53a1249330bef96..b9824f031e0bacc25c59fd0b765ce232f6c1bda7 100644 (file)
@@ -1408,8 +1408,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
                     returnType = genTOBuilder.toInstance();
                 }
             } else {
+                // It is constrained version of already declared type (inner declared type exists,
+                // onlyfor special cases (Enum, Union, Bits), which were already checked.
+                // In order to get proper class we need to look up closest derived type
+                // and apply restrictions from leaf type
                 final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
-                returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions);
+                returnType = typeProvider.javaTypeForSchemaDefinitionType(getBaseOrDeclaredType(typeDef), leaf,
+                        restrictions);
             }
         } else {
             final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
@@ -1430,6 +1435,16 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return returnType;
     }
 
+    private static TypeDefinition<?> getBaseOrDeclaredType(TypeDefinition<?> typeDef) {
+        if (typeDef instanceof ExtendedType) {
+            // Legacy behaviour returning ExtendedType is enough
+            return typeDef;
+        }
+        // Returns DerivedType in case of new parser.
+        final TypeDefinition<?> baseType = typeDef.getBaseType();
+        return (baseType != null && baseType.getBaseType() != null) ? baseType : typeDef;
+    }
+
     private void processContextRefExtension(final LeafSchemaNode leaf, final MethodSignatureBuilder getter,
             final Module module) {
         for (final UnknownSchemaNode node : leaf.getUnknownSchemaNodes()) {