BUG-4638: fix typedef types 89/30089/2
authorRobert Varga <rovarga@cisco.com>
Mon, 23 Nov 2015 19:19:28 +0000 (20:19 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 24 Nov 2015 10:18:59 +0000 (10:18 +0000)
This adds the fix for model.util.type type structure, which differs for
leaf types with default value.

Change-Id: Ibefebda88d5a6876a72b1ff1ebdf0cb639135a07
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/TypeProviderWrapper.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java

index ac1992932fe6c348920470b0c9e93004a49c5bf9..fd19f7e38c2f5324000072afc5fd9c28c65d299d 100644 (file)
@@ -15,11 +15,12 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
 
 public class TypeProviderWrapper {
     private final TypeProvider typeProvider;
 
-    public TypeProviderWrapper(TypeProvider typeProvider) {
+    public TypeProviderWrapper(final TypeProvider typeProvider) {
         this.typeProvider = typeProvider;
     }
 
@@ -27,16 +28,16 @@ public class TypeProviderWrapper {
      * For input node, find if it contains config:java-name-prefix extension. If
      * not found, convert local name of node converted to cammel case.
      */
-    public static String findJavaNamePrefix(SchemaNode schemaNode) {
+    public static String findJavaNamePrefix(final SchemaNode schemaNode) {
         return convertToJavaName(schemaNode, true);
     }
 
-    public static String findJavaParameter(SchemaNode schemaNode) {
+    public static String findJavaParameter(final SchemaNode schemaNode) {
         return convertToJavaName(schemaNode, false);
     }
 
-    public static String convertToJavaName(SchemaNode schemaNode,
-                                           boolean capitalizeFirstLetter) {
+    public static String convertToJavaName(final SchemaNode schemaNode,
+                                           final boolean capitalizeFirstLetter) {
         for (UnknownSchemaNode unknownNode : schemaNode.getUnknownSchemaNodes()) {
             if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME
                     .equals(unknownNode.getNodeType())) {
@@ -48,8 +49,8 @@ public class TypeProviderWrapper {
                 capitalizeFirstLetter);
     }
 
-    public static String convertToJavaName(String localName,
-                                           boolean capitalizeFirstLetter) {
+    public static String convertToJavaName(final String localName,
+                                           final boolean capitalizeFirstLetter) {
         if (capitalizeFirstLetter) {
             return BindingGeneratorUtil.parseToClassName(localName);
         } else {
@@ -57,16 +58,16 @@ public class TypeProviderWrapper {
         }
     }
 
-    public Type getType(LeafSchemaNode leaf) {
-        TypeDefinition<?> type = leaf.getType();
+    public Type getType(final LeafSchemaNode leaf) {
+        TypeDefinition<?> type = CompatUtils.compatLeafType(leaf);
         return getType(leaf, type);
     }
 
-    public String getDefault(LeafSchemaNode node) {
+    public String getDefault(final LeafSchemaNode node) {
         return typeProvider.getTypeDefaultConstruction(node);
     }
 
-    public Type getType(SchemaNode leaf, TypeDefinition<?> type) {
+    public Type getType(final SchemaNode leaf, final TypeDefinition<?> type) {
         Type javaType;
         try {
             javaType = typeProvider.javaTypeForSchemaDefinitionType(
@@ -83,7 +84,7 @@ public class TypeProviderWrapper {
     }
 
     // there is no getType in common interface
-    public Type getType(LeafListSchemaNode leaf) {
+    public Type getType(final LeafListSchemaNode leaf) {
         Type javaType;
         try {
             javaType = typeProvider.javaTypeForSchemaDefinitionType(
@@ -99,11 +100,11 @@ public class TypeProviderWrapper {
         return javaType;
     }
 
-    public String getJMXParamForBaseType(TypeDefinition<?> baseType) {
+    public String getJMXParamForBaseType(final TypeDefinition<?> baseType) {
         return typeProvider.getConstructorPropertyName(baseType);
     }
 
-    public String getJMXParamForUnionInnerType(TypeDefinition<?> unionInnerType) {
+    public String getJMXParamForUnionInnerType(final TypeDefinition<?> unionInnerType) {
         return typeProvider.getParamNameFromType(unionInnerType);
     }
 }
index d830e97678db5d7f4f5b26c8db70daf212472d48..5136a98e20b258c233b84baade451dc98bdaf280 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
 
 public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
 
@@ -34,20 +35,20 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
     private final TypeProviderWrapper typeProviderWrapper;
     private final TypeDefinition<?> typeDefinition;
 
-    public JavaAttribute(LeafSchemaNode leaf,
-            TypeProviderWrapper typeProviderWrapper) {
+    public JavaAttribute(final LeafSchemaNode leaf,
+            final TypeProviderWrapper typeProviderWrapper) {
         super(leaf);
         this.type = typeProviderWrapper.getType(leaf);
 
-        this.typeDefinition = leaf.getType();
+        this.typeDefinition = CompatUtils.compatLeafType(leaf);
         this.typeProviderWrapper = typeProviderWrapper;
         this.nullableDefault = leaf.getDefault();
         this.nullableDefaultWrappedForCode = leaf.getDefault() == null ? null : typeProviderWrapper.getDefault(leaf);
         this.nullableDescription = leaf.getDescription();
     }
 
-    public JavaAttribute(LeafListSchemaNode leaf,
-            TypeProviderWrapper typeProviderWrapper) {
+    public JavaAttribute(final LeafListSchemaNode leaf,
+            final TypeProviderWrapper typeProviderWrapper) {
         super(leaf);
         this.type = typeProviderWrapper.getType(leaf);
         this.typeDefinition = leaf.getType();
@@ -73,7 +74,7 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
     /**
      * Returns the most base type
      */
-    private TypeDefinition<?> getBaseType(TypeProviderWrapper typeProviderWrapper, TypeDefinition<?> baseType) {
+    private TypeDefinition<?> getBaseType(final TypeProviderWrapper typeProviderWrapper, TypeDefinition<?> baseType) {
         while(baseType.getBaseType()!=null) {
             baseType = baseType.getBaseType();
         }
@@ -100,7 +101,7 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
     }
 
     @Override
-    public boolean equals(Object o) {
+    public boolean equals(final Object o) {
         if (this == o) {
             return true;
         }
@@ -184,7 +185,7 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
         return typeDefinition instanceof IdentityrefTypeDefinition;
     }
 
-    private OpenType<?> getCompositeTypeForUnion(TypeDefinition<?> baseTypeDefinition) {
+    private OpenType<?> getCompositeTypeForUnion(final TypeDefinition<?> baseTypeDefinition) {
         Preconditions.checkArgument(baseTypeDefinition instanceof UnionTypeDefinition,
                 "Expected %s instance but was %s", UnionTypeDefinition.class, baseTypeDefinition);
 
@@ -232,7 +233,7 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
 
     public static final Class<Character> TYPE_OF_ARTIFICIAL_UNION_PROPERTY = char.class;
 
-    private void addArtificialPropertyToUnionCompositeType(TypeDefinition<?> baseTypeDefinition, String[] itemNames, OpenType<?>[] itemTypes) {
+    private void addArtificialPropertyToUnionCompositeType(final TypeDefinition<?> baseTypeDefinition, final String[] itemNames, final OpenType<?>[] itemTypes) {
         String artificialPropertyName = typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);
         itemNames[0] = artificialPropertyName;
 
@@ -241,12 +242,12 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
         itemTypes[0] = artificialPropertyType;
     }
 
-    private OpenType<?> getSimpleType(Type type) {
+    private OpenType<?> getSimpleType(final Type type) {
         SimpleType<?> simpleType = SimpleTypeResolver.getSimpleType(type);
         return simpleType;
     }
 
-    private OpenType<?> getCompositeType(Type baseType, TypeDefinition<?> baseTypeDefinition) {
+    private OpenType<?> getCompositeType(final Type baseType, final TypeDefinition<?> baseTypeDefinition) {
 
         SimpleType<?> innerItemType = SimpleTypeResolver.getSimpleType(baseType);
         String innerItemName = typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);
@@ -282,7 +283,7 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
         return getArrayOpenTypeForSimpleType(innerTypeFullyQName, innerSimpleType);
     }
 
-    private OpenType<?> getArrayOpenTypeForSimpleType(String innerTypeFullyQName, SimpleType<?> innerSimpleType) {
+    private OpenType<?> getArrayOpenTypeForSimpleType(final String innerTypeFullyQName, final SimpleType<?> innerSimpleType) {
         try {
             ArrayType<Object> arrayType = isPrimitive(innerTypeFullyQName) ? new ArrayType<>(innerSimpleType, true)
                     : new ArrayType<>(1, innerSimpleType);
@@ -294,7 +295,7 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
     }
 
     // TODO verify
-    private boolean isPrimitive(String innerTypeFullyQName) {
+    private boolean isPrimitive(final String innerTypeFullyQName) {
         if (innerTypeFullyQName.contains(".")) {
             return false;
         }
@@ -306,11 +307,11 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
         return type.getName().endsWith("[]");
     }
 
-    private boolean isDerivedType(Type baseType, Type currentType) {
+    private boolean isDerivedType(final Type baseType, final Type currentType) {
         return baseType.equals(currentType) == false;
     }
 
-    private static String getInnerType(Type type) {
+    private static String getInnerType(final Type type) {
         String fullyQualifiedName = type.getFullyQualifiedName();
         return fullyQualifiedName.substring(0, fullyQualifiedName.length() - 2);
     }