Migrate getDataChildByName() users
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / mdsal / binding / yang / types / AbstractTypeProvider.java
index 8e53b58a023e886310f32f272d4fe00910ec5057..3d092c7b6e07860226f47f64c8114b6f00c8ac04 100644 (file)
@@ -268,9 +268,9 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         DataSchemaNode dataChildByName;
         for (QName next : parentNode.getPath().getPathFromRoot()) {
             if (current == null) {
-                dataChildByName = schemaContext.getDataChildByName(next);
+                dataChildByName = schemaContext.dataChildByName(next);
             } else {
-                dataChildByName = current.getDataChildByName(next);
+                dataChildByName = current.dataChildByName(next);
             }
             if (dataChildByName == null) {
                 return false;
@@ -1425,25 +1425,25 @@ public abstract class AbstractTypeProvider implements TypeProvider {
             throw new UnsupportedOperationException("Cannot get default construction for identityref type");
         } else if (base instanceof InstanceIdentifierTypeDefinition) {
             throw new UnsupportedOperationException("Cannot get default construction for instance-identifier type");
-        } else if (BaseTypes.isInt8(base)) {
+        } else if (isInt8(base)) {
             result = typeToValueOfDef(Byte.class, defaultValue);
-        } else if (BaseTypes.isInt16(base)) {
+        } else if (isInt16(base)) {
             result = typeToValueOfDef(Short.class, defaultValue);
-        } else if (BaseTypes.isInt32(base)) {
+        } else if (isInt32(base)) {
             result = typeToValueOfDef(Integer.class, defaultValue);
-        } else if (BaseTypes.isInt64(base)) {
+        } else if (isInt64(base)) {
             result = typeToValueOfDef(Long.class, defaultValue);
         } else if (base instanceof LeafrefTypeDefinition) {
             result = leafrefToDef(node, (LeafrefTypeDefinition) base, defaultValue);
         } else if (base instanceof StringTypeDefinition) {
             result = "\"" + defaultValue + "\"";
-        } else if (BaseTypes.isUint8(base)) {
+        } else if (isUint8(base)) {
             result = typeToValueOfDef(Uint8.class, defaultValue);
-        } else if (BaseTypes.isUint16(base)) {
+        } else if (isUint16(base)) {
             result = typeToValueOfDef(Uint16.class, defaultValue);
-        } else if (BaseTypes.isUint32(base)) {
+        } else if (isUint32(base)) {
             result = typeToValueOfDef(Uint32.class, defaultValue);
-        } else if (BaseTypes.isUint64(base)) {
+        } else if (isUint64(base)) {
             result = typeToValueOfDef(Uint64.class, defaultValue);
         } else if (base instanceof UnionTypeDefinition) {
             result = unionToDef(node);
@@ -1466,6 +1466,91 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         return sb.toString();
     }
 
+
+    /**
+     * Check if a particular type definition represents the built-in int8 type.
+     *
+     * @param type Type definition
+     * @return True if the definition is the built-in int8 type.
+     */
+    private static boolean isInt8(final TypeDefinition<?> type) {
+        return BaseTypes.int8Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type definition represents the built-in int16 type.
+     *
+     * @param type Type definition
+     * @return True if the definition is the built-in int16 type.
+     */
+    private static boolean isInt16(final TypeDefinition<?> type) {
+        return BaseTypes.int16Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type definition represents the built-in int32 type.
+     *
+     * @param type Type definition
+     * @return True if the definition is the built-in int32 type.
+     */
+    private static boolean isInt32(final TypeDefinition<?> type) {
+        return BaseTypes.int32Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type definition represents the built-in int64 type.
+     *
+     * @param type Type definition
+     * @return True if the definition is the built-in int64 type.
+     */
+    private static boolean isInt64(final TypeDefinition<?> type) {
+        return BaseTypes.int64Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type is the base type for uint8.
+     *
+     * @param type The type to check
+     * @return If the type corresponds to the base uint8 type.
+     * @throws NullPointerException if type is null
+     */
+    private static boolean isUint8(final TypeDefinition<?> type) {
+        return BaseTypes.uint8Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type is the base type for uint16.
+     *
+     * @param type The type to check
+     * @return If the type corresponds to the base uint16 type.
+     * @throws NullPointerException if type is null
+     */
+    private static boolean isUint16(final TypeDefinition<?> type) {
+        return BaseTypes.uint16Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type is the base type for uint32.
+     *
+     * @param type The type to check
+     * @return If the type corresponds to the base uint32 type.
+     * @throws NullPointerException if type is null
+     */
+    private static boolean isUint32(final TypeDefinition<?> type) {
+        return BaseTypes.uint32Type().getPath().equals(type.getPath());
+    }
+
+    /**
+     * Check if a particular type is the base type for uint64.
+     *
+     * @param type The type to check
+     * @return If the type corresponds to the base uint64 type.
+     * @throws NullPointerException if type is null
+     */
+    private static boolean isUint64(final TypeDefinition<?> type) {
+        return BaseTypes.uint64Type().getPath().equals(type.getPath());
+    }
+
     private static String typeToDef(final Class<?> clazz, final String defaultValue) {
         return "new " + clazz.getName() + "(\"" + defaultValue + "\")";
     }
@@ -1507,16 +1592,10 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         bits.sort(BIT_NAME_COMPARATOR);
         final StringBuilder sb = new StringBuilder();
         if (!isExt) {
-            sb.append("new ");
-            sb.append(className);
-            sb.append('(');
+            sb.append("new ").append(className).append('(');
         }
         for (int i = 0; i < bits.size(); i++) {
-            if (bits.get(i).getName().equals(defaultValue)) {
-                sb.append(true);
-            } else {
-                sb.append(false);
-            }
+            sb.append(bits.get(i).getName().equals(defaultValue));
             if (i != bits.size() - 1) {
                 sb.append(", ");
             }
@@ -1608,11 +1687,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
 
     private static String union(final String className, final String defaultValue, final LeafSchemaNode node) {
         return new StringBuilder()
-                .append("new ")
-                .append(className)
-                .append("(\"")
-                .append(defaultValue)
-                .append("\".toCharArray())")
+                .append("new ").append(className).append("(\"").append(defaultValue).append("\".toCharArray())")
                 .toString();
     }