2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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
8 package org.opendaylight.mdsal.binding.generator.impl;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import com.google.common.annotations.Beta;
13 import com.google.common.annotations.VisibleForTesting;
14 import java.util.Collection;
15 import java.util.IdentityHashMap;
16 import java.util.List;
18 import javax.inject.Singleton;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.kohsuke.MetaInfServices;
21 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
22 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
29 * Default implementation of {@link BindingGenerator}.
34 public final class DefaultBindingGenerator implements BindingGenerator {
36 public List<Type> generateTypes(final SchemaContext context, final Collection<? extends Module> modules) {
37 return generateFor(context, modules);
41 static @NonNull List<Type> generateFor(final SchemaContext context) {
42 return generateFor(context, context.getModules());
46 * Resolves generated types from <code>context</code> schema nodes only for modules specified
47 * in <code>modules</code>. Generated types are created for modules, groupings, types, containers, lists, choices,
48 * augments, rpcs, notification, identities.
50 * @param context schema context which contains data about all schema nodes saved in modules
51 * @param modules set of modules for which schema nodes should be generated types
52 * @return list of types (usually <code>GeneratedType</code> or
53 * <code>GeneratedTransferObject</code>) which:
55 * <li>are generated from <code>context</code> schema nodes and</li>
56 * <li>are also part of some of the module in <code>modules</code>
59 * @throws IllegalArgumentException
61 * <li>if arg <code>context</code> is null or</li>
62 * <li>if arg <code>modules</code> is null</li>
64 * @throws IllegalStateException
65 * if <code>context</code> contain no modules
68 static @NonNull List<Type> generateFor(final SchemaContext context, final Collection<? extends Module> modules) {
69 GeneratorUtils.checkContext(context);
70 checkArgument(modules != null, "Set of Modules cannot be NULL.");
72 final Map<SchemaNode, JavaTypeName> renames = new IdentityHashMap<>();
75 return new CodegenTypeGenerator(context, renames).toTypes(modules);
76 } catch (RenameMappingException e) {
77 GeneratorUtils.rename(renames, e);