Do not rely on ExtendedType when looking for the base type 20/29820/2
authorRobert Varga <robert.varga@pantheon.sk>
Tue, 17 Nov 2015 16:31:34 +0000 (17:31 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 18 Nov 2015 08:11:40 +0000 (08:11 +0000)
A base type can be recognized as having its base type null, use that
indicator instead of specific implementation class. Also change the
implementation to use a simple loop instead of recursion.

Change-Id: Iff3e78c618bcbb7a33ae7335ea3bafe7cdf203a6
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java

index 3aedd9d2f0c66d0d4445ce31e97a05a6b59efe02..85ea46b1f1e18d8dd6cf45bdab4fc4d87adee373 100644 (file)
@@ -426,7 +426,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Gets base type definition for <code>extendTypeDef</code>. The method is
-     * recursivelly called until non <code>ExtendedType</code> type is found.
+     * recursively called until non <code>ExtendedType</code> type is found.
      *
      * @param extendTypeDef
      *            type definition for which is the base type definition sought
@@ -434,17 +434,15 @@ public final class TypeProviderImpl implements TypeProvider {
      * @throws IllegalArgumentException
      *             if <code>extendTypeDef</code> equal null
      */
-    private TypeDefinition<?> baseTypeDefForExtendedType(final TypeDefinition<?> extendTypeDef) {
+    private static TypeDefinition<?> baseTypeDefForExtendedType(final TypeDefinition<?> extendTypeDef) {
         Preconditions.checkArgument(extendTypeDef != null, "Type Definition reference cannot be NULL!");
-        final TypeDefinition<?> baseTypeDef = extendTypeDef.getBaseType();
-        if (baseTypeDef == null) {
-            return extendTypeDef;
-        } else if (baseTypeDef instanceof ExtendedType) {
-            return baseTypeDefForExtendedType(baseTypeDef);
-        } else {
-            return baseTypeDef;
+
+        TypeDefinition<?> ret = extendTypeDef;
+        while (ret.getBaseType() != null) {
+            ret = ret.getBaseType();
         }
 
+        return ret;
     }
 
     /**