Revert "MDSAL-361: Deal with restricted types in unions" 44/76644/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 4 Oct 2018 13:58:45 +0000 (15:58 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 4 Oct 2018 13:59:30 +0000 (15:59 +0200)
This reverts commit 47693173debca78b74858ca15080445fc93d0953, as it
breaks on openconfig-network-instance-types.yang -- the construction
results in wring constants being generated and also conflicting
constructors being present.

Change-Id: If7e3fa155e83d454570beca64e92956e69987b10
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/AbstractTypeProvider.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal361Test.java [deleted file]
binding/mdsal-binding-generator-impl/src/test/resources/mdsal361.yang [deleted file]

index 50ba62a591ed9e4c1042aef22238f906cda0d294..74a65c8c39e964c3823a626f327fbd91f15be600 100644 (file)
@@ -15,8 +15,6 @@ import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findP
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.HashBiMap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.common.io.BaseEncoding;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.common.io.BaseEncoding;
@@ -962,25 +960,23 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         // Pattern string is the key, XSD regex is the value. The reason for this choice is that the pattern carries
         // also negation information and hence guarantees uniqueness.
         final Map<String, String> expressions = new HashMap<>();
         // Pattern string is the key, XSD regex is the value. The reason for this choice is that the pattern carries
         // also negation information and hence guarantees uniqueness.
         final Map<String, String> expressions = new HashMap<>();
-        final Map<TypeDefinition, String> propertyNames = resolveUnionMemberTypePropertyNames(unionTypes);
         for (TypeDefinition<?> unionType : unionTypes) {
         for (TypeDefinition<?> unionType : unionTypes) {
-            final String propertyName = propertyNames.get(unionType);
+            final String unionTypeName = unionType.getQName().getLocalName();
 
             // If we have a base type we should follow the type definition backwards, except for identityrefs, as those
             // do not follow type encapsulation -- we use the general case for that.
             if (unionType.getBaseType() != null  && !(unionType instanceof IdentityrefTypeDefinition)) {
 
             // If we have a base type we should follow the type definition backwards, except for identityrefs, as those
             // do not follow type encapsulation -- we use the general case for that.
             if (unionType.getBaseType() != null  && !(unionType instanceof IdentityrefTypeDefinition)) {
-                resolveExtendedSubtypeAsUnion(unionGenTOBuilder, unionType, expressions, parentNode,
-                        propertyName);
+                resolveExtendedSubtypeAsUnion(unionGenTOBuilder, unionType, expressions, parentNode);
             } else if (unionType instanceof UnionTypeDefinition) {
                 generatedTOBuilders.addAll(resolveUnionSubtypeAsUnion(unionGenTOBuilder,
                     (UnionTypeDefinition) unionType, parentNode));
             } else if (unionType instanceof EnumTypeDefinition) {
                 final Enumeration enumeration = addInnerEnumerationToTypeBuilder((EnumTypeDefinition) unionType,
             } else if (unionType instanceof UnionTypeDefinition) {
                 generatedTOBuilders.addAll(resolveUnionSubtypeAsUnion(unionGenTOBuilder,
                     (UnionTypeDefinition) unionType, parentNode));
             } else if (unionType instanceof EnumTypeDefinition) {
                 final Enumeration enumeration = addInnerEnumerationToTypeBuilder((EnumTypeDefinition) unionType,
-                        propertyName, unionGenTOBuilder);
-                updateUnionTypeAsProperty(unionGenTOBuilder, enumeration, propertyName);
+                        unionTypeName, unionGenTOBuilder);
+                updateUnionTypeAsProperty(unionGenTOBuilder, enumeration, unionTypeName);
             } else {
                 final Type javaType = javaTypeForSchemaDefinitionType(unionType, parentNode);
             } else {
                 final Type javaType = javaTypeForSchemaDefinitionType(unionType, parentNode);
-                updateUnionTypeAsProperty(unionGenTOBuilder, javaType, propertyName);
+                updateUnionTypeAsProperty(unionGenTOBuilder, javaType, unionTypeName);
             }
         }
         addStringRegExAsConstant(unionGenTOBuilder, expressions);
             }
         }
         addStringRegExAsConstant(unionGenTOBuilder, expressions);
@@ -990,22 +986,6 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         return generatedTOBuilders;
     }
 
         return generatedTOBuilders;
     }
 
-    private Map<TypeDefinition, String> resolveUnionMemberTypePropertyNames(final List<TypeDefinition<?>> unionTypes) {
-        final BiMap<String, TypeDefinition> propertyNames = HashBiMap.create();
-        String propertyName;
-        Integer suffix = 0;
-        for (TypeDefinition<?> type : unionTypes) {
-            propertyName = type.getQName().getLocalName();
-            if (propertyNames.containsKey(propertyName)) {
-                propertyName = propertyName + (++suffix);
-            }
-
-            propertyNames.put(propertyName, type);
-        }
-
-        return propertyNames.inverse();
-    }
-
     /**
      * Wraps code which handles the case when union subtype is also of the type <code>UnionType</code>.
      *
     /**
      * Wraps code which handles the case when union subtype is also of the type <code>UnionType</code>.
      *
@@ -1062,8 +1042,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
      *
      */
     private void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
      *
      */
     private void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
-            final TypeDefinition<?> unionSubtype, final Map<String, String> expressions, final SchemaNode parentNode,
-            final String propertyName) {
+            final TypeDefinition<?> unionSubtype, final Map<String, String> expressions, final SchemaNode parentNode) {
         final String unionTypeName = unionSubtype.getQName().getLocalName();
         final Type genTO = findGenTO(unionTypeName, unionSubtype);
         if (genTO != null) {
         final String unionTypeName = unionSubtype.getQName().getLocalName();
         final Type genTO = findGenTO(unionTypeName, unionSubtype);
         if (genTO != null) {
@@ -1076,7 +1055,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
             final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(baseType,
                 parentNode, BindingGeneratorUtil.getRestrictions(unionSubtype));
             if (javaType != null) {
             final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(baseType,
                 parentNode, BindingGeneratorUtil.getRestrictions(unionSubtype));
             if (javaType != null) {
-                updateUnionTypeAsProperty(parentUnionGenTOBuilder, javaType, propertyName);
+                updateUnionTypeAsProperty(parentUnionGenTOBuilder, javaType, unionTypeName);
             }
         } else if (baseType instanceof LeafrefTypeDefinition) {
             final Type javaType = javaTypeForSchemaDefinitionType(baseType, parentNode);
             }
         } else if (baseType instanceof LeafrefTypeDefinition) {
             final Type javaType = javaTypeForSchemaDefinitionType(baseType, parentNode);
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal361Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal361Test.java
deleted file mode 100644 (file)
index 991ee1d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.generator.impl;
-
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.mdsal.binding.model.util.Types;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class Mdsal361Test {
-
-    @Test
-    public void mdsal361Test() {
-        final SchemaContext context = YangParserTestUtils.parseYangResource("/mdsal361.yang");
-
-        final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
-        assertNotNull(generateTypes);
-        assertEquals(4, generateTypes.size());
-        for (final Type type : generateTypes) {
-            if (type.getName().equals("PceId")) {
-                final GeneratedType gt = (GeneratedType) type;
-                assertNotNull(gt);
-                assertEquals(2, gt.getProperties().size());
-            }
-
-            if (type.getName().equals("PceId2")) {
-                final GeneratedType gt = (GeneratedType) type;
-                assertNotNull(gt);
-                assertEquals(2, gt.getEnumerations().size());
-                assertEquals(2, gt.getProperties().size());
-            }
-        }
-    }
-}
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal361.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal361.yang
deleted file mode 100644 (file)
index 17d9dc9..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-module mdsal361 {
-
-    namespace "yang:test:mdsal361";
-    prefix m;
-
-    revision 2018-09-13 {
-    }
-
-    typedef pce-id {
-        type union {
-            type binary {
-                length 4;
-            }
-            type binary {
-                length 16;
-            }
-        }
-    }
-
-    typedef pce-id-2 {
-        type union {
-            type enumeration {
-                enum a;
-            }
-
-            type enumeration {
-                enum b;
-            }
-        }
-    }
-
-}