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;
11 import static com.google.common.base.Preconditions.checkState;
14 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
15 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
16 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 final class GeneratorUtils {
24 private static final Logger LOG = LoggerFactory.getLogger(GeneratorUtils.class);
26 private GeneratorUtils() {
30 static void checkContext(final SchemaContext context) {
31 checkArgument(context != null, "Schema Context reference cannot be NULL.");
32 checkState(context.getModules() != null, "Schema Context does not contain defined modules.");
35 static void rename(final Map<SchemaNode, JavaTypeName> renames, final RenameMappingException ex) {
36 final JavaTypeName name = ex.getName();
37 final SchemaNode def = ex.getDefinition();
38 final JavaTypeName existing = renames.get(def);
39 if (existing != null) {
40 throw new IllegalStateException("Attempted to relocate " + def + " to " + name + ", already remapped to "
45 if (def instanceof IdentitySchemaNode) {
47 } else if (def instanceof GroupingDefinition) {
49 } else if (def instanceof TypeDefinition) {
52 throw new IllegalStateException("Unhandled remapping of " + def + " at " + name, ex);
55 final JavaTypeName newName = name.createSibling(name.simpleName() + suffix);
56 renames.put(def, newName);
57 LOG.debug("Restarting code generation after remapping {} to {}", name, newName);