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.EffectiveModelContext;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
29 * Default implementation of {@link BindingGenerator}.
34 // Note: not exposed in OSGi on purpose, as this should only be needed at compile-time
35 public final class DefaultBindingGenerator implements BindingGenerator {
37 public List<Type> generateTypes(final EffectiveModelContext context, final Collection<? extends Module> modules) {
38 return generateFor(context, modules);
42 static @NonNull List<Type> generateFor(final EffectiveModelContext context) {
43 return generateFor(context, context.getModules());
47 * Resolves generated types from <code>context</code> schema nodes only for modules specified
48 * in <code>modules</code>. Generated types are created for modules, groupings, types, containers, lists, choices,
49 * augments, rpcs, notification, identities.
51 * @param context schema context which contains data about all schema nodes saved in modules
52 * @param modules set of modules for which schema nodes should be generated types
53 * @return list of types (usually <code>GeneratedType</code> or
54 * <code>GeneratedTransferObject</code>) which:
56 * <li>are generated from <code>context</code> schema nodes and</li>
57 * <li>are also part of some of the module in <code>modules</code>
60 * @throws IllegalArgumentException
62 * <li>if arg <code>context</code> is null or</li>
63 * <li>if arg <code>modules</code> is null</li>
65 * @throws IllegalStateException
66 * if <code>context</code> contain no modules
69 static @NonNull List<Type> generateFor(final EffectiveModelContext context,
70 final Collection<? extends Module> modules) {
71 GeneratorUtils.checkContext(context);
72 checkArgument(modules != null, "Set of Modules cannot be NULL.");
74 final Map<SchemaNode, JavaTypeName> renames = new IdentityHashMap<>();
77 return new CodegenTypeGenerator(context, renames).toTypes(modules);
78 } catch (RenameMappingException e) {
79 GeneratorUtils.rename(renames, e);