Remove augmentableToAugmentations maps
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / util / BindingRuntimeContext.java
index bdcd7c719886e464611b7fd98ed0edb6e60c0487..88fadd29ee97bd58aeda9fcc5344a808a6e706b7 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.collect.HashBiMap;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Multimap;
-import java.util.AbstractMap;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.Collection;
 import java.util.HashMap;
@@ -54,7 +53,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,7 +81,6 @@ public class BindingRuntimeContext implements Immutable {
 
     private final Map<Type, AugmentationSchema> augmentationToSchema = new HashMap<>();
     private final BiMap<Type, Object> typeToDefiningSchema = HashBiMap.create();
-    private final Multimap<Type, Type> augmentableToAugmentations = HashMultimap.create();
     private final Multimap<Type, Type> choiceToCases = HashMultimap.create();
     private final Map<QName, Type> identities = new HashMap<>();
 
@@ -114,7 +111,6 @@ public class BindingRuntimeContext implements Immutable {
             typeToDefiningSchema.putAll(ctx.getTypeToSchema());
 
             ctx.getTypedefs();
-            augmentableToAugmentations.putAll(ctx.getAugmentableToAugmentations());
             choiceToCases.putAll(ctx.getChoiceToCases());
             identities.putAll(ctx.getIdentities());
         }
@@ -214,13 +210,24 @@ public class BindingRuntimeContext implements Immutable {
         final Set<QName> childNames = new HashSet<>();
         final Set<DataSchemaNode> realChilds = new HashSet<>();
         for (final DataSchemaNode child : origSchema.getChildNodes()) {
-            realChilds.add(target.getDataChildByName(child.getQName()));
-            childNames.add(child.getQName());
+            final DataSchemaNode dataChildQNname = target.getDataChildByName(child.getQName());
+            final String childLocalName = child.getQName().getLocalName();
+            if (dataChildQNname == null) {
+                for (DataSchemaNode dataSchemaNode : target.getChildNodes()) {
+                    if (childLocalName.equals(dataSchemaNode.getQName().getLocalName())) {
+                        realChilds.add(dataSchemaNode);
+                        childNames.add(dataSchemaNode.getQName());
+                    }
+                }
+            } else {
+                realChilds.add(dataChildQNname);
+                childNames.add(child.getQName());
+            }
         }
 
         final AugmentationIdentifier identifier = new AugmentationIdentifier(childNames);
         final AugmentationSchema proxy = new EffectiveAugmentationSchema(origSchema, realChilds);
-        return new AbstractMap.SimpleEntry<>(identifier, proxy);
+        return new SimpleEntry<>(identifier, proxy);
     }
 
     /**
@@ -278,10 +285,12 @@ public class BindingRuntimeContext implements Immutable {
 
     private Entry<GeneratedType, Object> getTypeWithSchema(final Type referencedType) {
         final Object schema = typeToDefiningSchema.get(referencedType);
+        Preconditions.checkNotNull(schema, "Failed to find schema for type %s", referencedType);
+
         final Type definedType = typeToDefiningSchema.inverse().get(schema);
-        Preconditions.checkNotNull(schema);
-        Preconditions.checkNotNull(definedType);
-        if(definedType instanceof GeneratedTypeBuilder) {
+        Preconditions.checkNotNull(definedType, "Failed to find defined type for %s schema %s", referencedType, schema);
+
+        if (definedType instanceof GeneratedTypeBuilder) {
             return new SimpleEntry<>(((GeneratedTypeBuilder) definedType).toInstance(), schema);
         }
         Preconditions.checkArgument(definedType instanceof GeneratedType,"Type {} is not GeneratedType", referencedType);
@@ -317,7 +326,7 @@ public class BindingRuntimeContext implements Immutable {
      * @return mapped enum constants from yang with their corresponding values in generated binding classes
      */
     public BiMap<String, String> getEnumMapping(final Class<?> enumClass) {
-        final Map.Entry<GeneratedType, Object> typeWithSchema = getTypeWithSchema(enumClass);
+        final Entry<GeneratedType, Object> typeWithSchema = getTypeWithSchema(enumClass);
         return getEnumMapping(typeWithSchema);
     }
 
@@ -325,20 +334,15 @@ public class BindingRuntimeContext implements Immutable {
      * See {@link #getEnumMapping(Class)}}
      */
     public BiMap<String, String> getEnumMapping(final String enumClass) {
-        final Map.Entry<GeneratedType, Object> typeWithSchema = getTypeWithSchema(enumClass);
+        final Entry<GeneratedType, Object> typeWithSchema = getTypeWithSchema(enumClass);
         return getEnumMapping(typeWithSchema);
     }
 
     private static BiMap<String, String> getEnumMapping(final Entry<GeneratedType, Object> typeWithSchema) {
         final TypeDefinition<?> typeDef = (TypeDefinition<?>) typeWithSchema.getValue();
 
-        final EnumTypeDefinition enumType;
-        if(typeDef instanceof ExtendedType) {
-            enumType = (EnumTypeDefinition) ((ExtendedType) typeDef).getBaseType();
-        } else {
-            Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition);
-            enumType = (EnumTypeDefinition) typeDef;
-        }
+        Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition);
+        final EnumTypeDefinition enumType = (EnumTypeDefinition) typeDef;
 
         final HashBiMap<String, String> mappedEnums = HashBiMap.create();
 
@@ -406,7 +410,7 @@ public class BindingRuntimeContext implements Immutable {
     }
 
     private static Type referencedType(final Type type) {
-        if(type instanceof ReferencedTypeImpl) {
+        if (type instanceof ReferencedTypeImpl) {
             return type;
         }
         return new ReferencedTypeImpl(type.getPackageName(), type.getName());
@@ -415,10 +419,10 @@ public class BindingRuntimeContext implements Immutable {
     private static Set<Type> collectAllContainerTypes(final GeneratedType type, final Set<Type> collection) {
         for (final MethodSignature definition : type.getMethodDefinitions()) {
             Type childType = definition.getReturnType();
-            if(childType instanceof ParameterizedType) {
+            if (childType instanceof ParameterizedType) {
                 childType = ((ParameterizedType) childType).getActualTypeArguments()[0];
             }
-            if(childType instanceof GeneratedType || childType instanceof GeneratedTypeBuilder) {
+            if (childType instanceof GeneratedType || childType instanceof GeneratedTypeBuilder) {
                 collection.add(referencedType(childType));
             }
         }