2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.binding.javav2.generator.impl;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import java.util.List;
15 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
16 import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
17 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
18 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
19 import org.opendaylight.mdsal.binding.javav2.util.BindingMapping;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
26 final class ModuleToGenType {
28 private ModuleToGenType() {
29 throw new UnsupportedOperationException("Utility class");
32 static Map<Module, ModuleContext> generate(final Module module, Map<String, Map<String, GeneratedTypeBuilder>>
33 genTypeBuilders, final SchemaContext schemaContext, TypeProvider typeProvider, Map<Module,
34 ModuleContext> genCtx, final boolean verboseClassComments) {
36 genCtx.put(module, new ModuleContext());
37 genCtx = allTypeDefinitionsToGenTypes(module, genCtx, typeProvider);
39 //TODO: call generate for other entities (groupings, rpcs, identities, notifications)
41 if (!module.getChildNodes().isEmpty()) {
42 final GeneratedTypeBuilder moduleType = GenHelperUtil.moduleToDataType(module, genCtx, verboseClassComments);
43 genCtx.get(module).addModuleNode(moduleType);
44 final String basePackageName = BindingMapping.getRootPackageName(module);
45 GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, moduleType, moduleType, module
46 .getChildNodes(), genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
53 * Converts all extended type definitions of module to the list of
54 * <code>Type</code> objects.
57 * module from which is obtained set of type definitions
58 * @throws IllegalArgumentException
60 * <li>if module is null</li>
61 * <li>if name of module is null</li>
63 * @throws IllegalStateException
64 * if set of type definitions from module is null
66 private static Map<Module, ModuleContext> allTypeDefinitionsToGenTypes(final Module module, Map<Module, ModuleContext> genCtx,
67 TypeProvider typeProvider) {
68 Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
69 Preconditions.checkArgument(module.getName() != null, "Module name cannot be NULL.");
70 final DataNodeIterator it = new DataNodeIterator(module);
71 final List<TypeDefinition<?>> typeDefinitions = it.allTypedefs();
72 Preconditions.checkState(typeDefinitions != null, "Type Definitions for module «module.name» cannot be NULL.");
74 typeDefinitions.stream().filter(typedef -> typedef != null).forEach(typedef -> {
75 final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef,
78 final ModuleContext ctx = genCtx.get(module);
79 ctx.addTypedefType(typedef.getPath(), type);
80 ctx.addTypeToSchema(type, typedef);