Remove augmentableToAugmentations maps
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / util / BindingRuntimeContext.java
index 48da02b8ffdbc25c65e03992a4d224150cdf7d37..88fadd29ee97bd58aeda9fcc5344a808a6e706b7 100644 (file)
@@ -53,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;
@@ -82,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<>();
 
@@ -113,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());
         }
@@ -288,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);
@@ -342,13 +341,8 @@ public class BindingRuntimeContext implements Immutable {
     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();
 
@@ -416,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());
@@ -425,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));
             }
         }