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;
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());
}
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);
}
/**
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);
* @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);
}
* 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();
}
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));
}
}