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.util;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
13 import org.opendaylight.mdsal.binding.model.api.Restrictions;
14 import org.opendaylight.mdsal.binding.model.api.Type;
15 import org.opendaylight.mdsal.binding.model.util.BaseYangTypes;
16 import org.opendaylight.mdsal.binding.model.util.Types;
17 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 public final class BaseYangTypesProvider implements TypeProvider {
24 public static final @NonNull BaseYangTypesProvider INSTANCE = new BaseYangTypesProvider();
26 private BaseYangTypesProvider() {
31 * Searches <code>Type</code> value to which is YANG <code>type</code>
35 * type definition representation of YANG type
36 * @return java <code>Type</code> representation of <code>type</code>.
37 * If <code>type</code> isn't found then <code>null</code> is
41 public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
42 final boolean lenientRelativeLeafrefs) {
43 return type == null ? null : BaseYangTypes.javaTypeForYangType(type.getQName().getLocalName());
47 public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
48 final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
49 final String typeName = type.getQName().getLocalName();
50 final Type mapped = BaseYangTypes.javaTypeForYangType(typeName);
51 return mapped == null || restrictions == null ? mapped : Types.restrictedType(mapped, restrictions);
55 public String getTypeDefaultConstruction(final LeafSchemaNode node) {
60 public String getConstructorPropertyName(final SchemaNode node) {
65 public String getParamNameFromType(final TypeDefinition<?> type) {
66 return "_" + BindingMapping.getPropertyName(type.getQName().getLocalName());