2 * Copyright (c) 2016 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.binding2.generator.impl;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import java.util.HashMap;
14 import java.util.List;
16 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
17 import org.opendaylight.mdsal.binding2.generator.yang.types.TypeProviderImpl;
18 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
19 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
20 import org.opendaylight.mdsal.binding2.util.BindingMapping;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
27 final class ModuleToGenType {
29 private ModuleToGenType() {
30 throw new UnsupportedOperationException("Utility class");
33 static Map<Module, ModuleContext> generate(final Module module, final SchemaContext schemaContext,
34 TypeProvider typeProvider, final boolean verboseClassComments) {
35 Map<Module, ModuleContext> genCtx = new HashMap<>();
37 genCtx.put(module, new ModuleContext());
38 genCtx = allTypeDefinitionsToGenTypes(module, genCtx, typeProvider);
40 //TODO: call generate for other entities (groupings, rpcs, identities, notifications)
42 if (!module.getChildNodes().isEmpty()) {
43 final GeneratedTypeBuilder moduleType = GenHelperUtil.moduleToDataType(module, genCtx, verboseClassComments);
44 genCtx.get(module).addModuleNode(moduleType);
45 final String basePackageName = BindingMapping.getRootPackageName(module);
46 GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, moduleType, moduleType, module
54 * Converts all extended type definitions of module to the list of
55 * <code>Type</code> objects.
58 * module from which is obtained set of type definitions
59 * @throws IllegalArgumentException
61 * <li>if module is null</li>
62 * <li>if name of module is null</li>
64 * @throws IllegalStateException
65 * if set of type definitions from module is null
67 private static Map<Module, ModuleContext> allTypeDefinitionsToGenTypes(final Module module, Map<Module, ModuleContext> genCtx,
68 TypeProvider typeProvider) {
69 Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
70 Preconditions.checkArgument(module.getName() != null, "Module name cannot be NULL.");
71 final DataNodeIterator it = new DataNodeIterator(module);
72 final List<TypeDefinition<?>> typeDefinitions = it.allTypedefs();
73 Preconditions.checkState(typeDefinitions != null, "Type Definitions for module «module.name» cannot be NULL.");
75 typeDefinitions.stream().filter(typedef -> typedef != null).forEach(typedef -> {
76 final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef,
79 final ModuleContext ctx = genCtx.get(module);
80 ctx.addTypedefType(typedef.getPath(), type);
81 ctx.addTypeToSchema(type, typedef);