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;
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<>();
typeToDefiningSchema.putAll(ctx.getTypeToSchema());
ctx.getTypedefs();
- augmentableToAugmentations.putAll(ctx.getAugmentableToAugmentations());
choiceToCases.putAll(ctx.getChoiceToCases());
identities.putAll(ctx.getIdentities());
}
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);
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();
}
private static Type referencedType(final Type type) {
- if(type instanceof ReferencedTypeImpl) {
+ if (type instanceof ReferencedTypeImpl) {
return type;
}
return new ReferencedTypeImpl(type.getPackageName(), type.getName());
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));
}
}