/* * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.generator.impl; import static com.google.common.base.Preconditions.checkArgument; import com.google.common.annotations.Beta; import com.google.common.annotations.VisibleForTesting; import java.util.Collection; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import javax.inject.Singleton; import org.eclipse.jdt.annotation.NonNull; import org.kohsuke.MetaInfServices; import org.opendaylight.mdsal.binding.generator.api.BindingGenerator; import org.opendaylight.mdsal.binding.model.api.JavaTypeName; import org.opendaylight.mdsal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; /** * Default implementation of {@link BindingGenerator}. */ @Beta @MetaInfServices @Singleton // Note: not exposed in OSGi on purpose, as this should only be needed at compile-time public final class DefaultBindingGenerator implements BindingGenerator { @Override public List generateTypes(final SchemaContext context, final Collection modules) { return generateFor(context, modules); } @VisibleForTesting static @NonNull List generateFor(final SchemaContext context) { return generateFor(context, context.getModules()); } /** * Resolves generated types from context schema nodes only for modules specified * in modules. Generated types are created for modules, groupings, types, containers, lists, choices, * augments, rpcs, notification, identities. * * @param context schema context which contains data about all schema nodes saved in modules * @param modules set of modules for which schema nodes should be generated types * @return list of types (usually GeneratedType or * GeneratedTransferObject) which: * * @throws IllegalArgumentException * * @throws IllegalStateException * if context contain no modules */ @VisibleForTesting static @NonNull List generateFor(final SchemaContext context, final Collection modules) { GeneratorUtils.checkContext(context); checkArgument(modules != null, "Set of Modules cannot be NULL."); final Map renames = new IdentityHashMap<>(); for (;;) { try { return new CodegenTypeGenerator(context, renames).toTypes(modules); } catch (RenameMappingException e) { GeneratorUtils.rename(renames, e); } } } }