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 java.math.BigDecimal;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
14 import org.opendaylight.mdsal.binding.model.api.Restrictions;
15 import org.opendaylight.mdsal.binding.model.api.Type;
16 import org.opendaylight.mdsal.binding.model.util.Types;
17 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
18 import org.opendaylight.yangtools.yang.common.Uint16;
19 import org.opendaylight.yangtools.yang.common.Uint32;
20 import org.opendaylight.yangtools.yang.common.Uint64;
21 import org.opendaylight.yangtools.yang.common.Uint8;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
27 public final class BaseYangTypesProvider implements TypeProvider {
28 public static final @NonNull BaseYangTypesProvider INSTANCE = new BaseYangTypesProvider();
30 private BaseYangTypesProvider() {
35 * Searches <code>Type</code> value to which is YANG <code>type</code>
39 * type definition representation of YANG type
40 * @return java <code>Type</code> representation of <code>type</code>.
41 * If <code>type</code> isn't found then <code>null</code> is
45 public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
46 final boolean lenientRelativeLeafrefs) {
47 return type == null ? null : BaseYangTypes.javaTypeForYangType(type.getQName().getLocalName());
51 public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
52 final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
53 final String typeName = type.getQName().getLocalName();
56 return restrictions == null ? Types.BYTE_ARRAY : Types.typeForClass(byte[].class, restrictions);
58 return Types.typeForClass(BigDecimal.class, restrictions);
60 return Types.typeForClass(Enum.class, restrictions);
62 return Types.typeForClass(Byte.class, restrictions);
64 return Types.typeForClass(Short.class, restrictions);
66 return Types.typeForClass(Integer.class, restrictions);
68 return Types.typeForClass(Long.class, restrictions);
70 return Types.typeForClass(String.class, restrictions);
72 return Types.typeForClass(Uint8.class, restrictions);
74 return Types.typeForClass(Uint16.class, restrictions);
76 return Types.typeForClass(Uint32.class, restrictions);
78 return Types.typeForClass(Uint64.class, restrictions);
80 return javaTypeForSchemaDefinitionType(type, parentNode, lenientRelativeLeafrefs);
85 public String getTypeDefaultConstruction(final LeafSchemaNode node) {
90 public String getConstructorPropertyName(final SchemaNode node) {
95 public String getParamNameFromType(final TypeDefinition<?> type) {
96 return "_" + BindingMapping.getPropertyName(type.getQName().getLocalName());