import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.Callable;
-import org.opendaylight.mdsal.binding.generator.util.BaseYangTypes;
+import org.opendaylight.mdsal.binding.generator.util.BaseYangTypesProvider;
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
final LeafSchemaNode typeNode = (LeafSchemaNode) dataNode;
// prepare name of type form return type of referenced leaf
- final String typeName = BindingMapping.getClassName(BaseYangTypes.BASE_YANG_TYPES_PROVIDER
+ final String typeName = BindingMapping.getClassName(BaseYangTypesProvider.INSTANCE
.javaTypeForSchemaDefinitionType(typeNode.getType(), typeNode).getName());
// get method via reflection from generated code according to
import java.util.regex.Pattern;
import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
import org.opendaylight.mdsal.binding.generator.util.BaseYangTypes;
+import org.opendaylight.mdsal.binding.generator.util.BaseYangTypesProvider;
import org.opendaylight.mdsal.binding.model.api.AccessModifier;
import org.opendaylight.mdsal.binding.model.api.ConcreteType;
import org.opendaylight.mdsal.binding.model.api.Enumeration;
// and generated an enclosing ExtendedType to hold any range constraints. The new parser instantiates
// a base type which holds these constraints.
if (typeDefinition instanceof DecimalTypeDefinition) {
- final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition,
+ final Type ret = BaseYangTypesProvider.INSTANCE.javaTypeForSchemaDefinitionType(typeDefinition,
parentNode, restrictions, lenientRelativeLeafrefs);
if (ret != null) {
return ret;
returnType = genTOs.get(typedefName);
}
if (returnType == null) {
- returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
- baseTypeDef, typeDefinition, r, lenient);
+ returnType = BaseYangTypesProvider.INSTANCE.javaTypeForSchemaDefinitionType(baseTypeDef,
+ typeDefinition, r, lenient);
}
}
}
final TypeDefinition<?> baseType = baseTypeDefForExtendedType(unionSubtype);
if (unionTypeName.equals(baseType.getQName().getLocalName())) {
- final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(baseType,
- parentNode, BindingGeneratorUtil.getRestrictions(unionSubtype));
+ final Type javaType = BaseYangTypesProvider.INSTANCE.javaTypeForSchemaDefinitionType(baseType, parentNode,
+ BindingGeneratorUtil.getRestrictions(unionSubtype));
if (javaType != null) {
updateUnionTypeAsProperty(parentUnionGenTOBuilder, javaType, unionTypeName);
}
import com.google.common.collect.ImmutableMap;
import java.math.BigDecimal;
-import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
-import org.opendaylight.mdsal.binding.model.api.Restrictions;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.mdsal.binding.model.util.Types;
-import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint64;
import org.opendaylight.yangtools.yang.common.Uint8;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
public final class BaseYangTypes {
/**
* It is undesirable to create instance of this class.
*/
private BaseYangTypes() {
- throw new UnsupportedOperationException();
+
}
/**
public static Type javaTypeForYangType(final String type) {
return TYPE_MAP.get(type);
}
-
- public static final TypeProvider BASE_YANG_TYPES_PROVIDER = new TypeProvider() {
- /**
- * Searches <code>Type</code> value to which is YANG <code>type</code>
- * mapped.
- *
- * @param type
- * type definition representation of YANG type
- * @return java <code>Type</code> representation of <code>type</code>.
- * If <code>type</code> isn't found then <code>null</code> is
- * returned.
- */
- @Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
- final boolean lenientRelativeLeafrefs) {
- if (type != null) {
- return TYPE_MAP.get(type.getQName().getLocalName());
- }
-
- return null;
- }
-
- @Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
- final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
- String typeName = type.getQName().getLocalName();
- switch (typeName) {
- case "binary":
- return restrictions == null ? Types.BYTE_ARRAY : Types.typeForClass(byte[].class, restrictions);
- case "decimal64":
- return Types.typeForClass(BigDecimal.class, restrictions);
- case "enumeration":
- return Types.typeForClass(Enum.class, restrictions);
- case "int8":
- return Types.typeForClass(Byte.class, restrictions);
- case "int16":
- return Types.typeForClass(Short.class, restrictions);
- case "int32":
- return Types.typeForClass(Integer.class, restrictions);
- case "int64":
- return Types.typeForClass(Long.class, restrictions);
- case "string":
- return Types.typeForClass(String.class, restrictions);
- case "uint8":
- return Types.typeForClass(Uint8.class, restrictions);
- case "uint16":
- return Types.typeForClass(Uint16.class, restrictions);
- case "uint32":
- return Types.typeForClass(Uint32.class, restrictions);
- case "uint64":
- return Types.typeForClass(Uint64.class, restrictions);
- default:
- return javaTypeForSchemaDefinitionType(type, parentNode, lenientRelativeLeafrefs);
- }
- }
-
- @Override
- public String getTypeDefaultConstruction(final LeafSchemaNode node) {
- return null;
- }
-
- @Override
- public String getConstructorPropertyName(final SchemaNode node) {
- return null;
- }
-
- @Override
- public String getParamNameFromType(final TypeDefinition<?> type) {
- return "_" + BindingMapping.getPropertyName(type.getQName().getLocalName());
- }
- };
}
--- /dev/null
+/*
+ * 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.util;
+
+import com.google.common.annotations.Beta;
+import java.math.BigDecimal;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
+import org.opendaylight.mdsal.binding.model.api.Restrictions;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.model.util.Types;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+@Beta
+public final class BaseYangTypesProvider implements TypeProvider {
+ public static final @NonNull BaseYangTypesProvider INSTANCE = new BaseYangTypesProvider();
+
+ private BaseYangTypesProvider() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Searches <code>Type</code> value to which is YANG <code>type</code>
+ * mapped.
+ *
+ * @param type
+ * type definition representation of YANG type
+ * @return java <code>Type</code> representation of <code>type</code>.
+ * If <code>type</code> isn't found then <code>null</code> is
+ * returned.
+ */
+ @Override
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
+ final boolean lenientRelativeLeafrefs) {
+ return type == null ? null : BaseYangTypes.javaTypeForYangType(type.getQName().getLocalName());
+ }
+
+ @Override
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
+ final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
+ final String typeName = type.getQName().getLocalName();
+ switch (typeName) {
+ case "binary":
+ return restrictions == null ? Types.BYTE_ARRAY : Types.typeForClass(byte[].class, restrictions);
+ case "decimal64":
+ return Types.typeForClass(BigDecimal.class, restrictions);
+ case "enumeration":
+ return Types.typeForClass(Enum.class, restrictions);
+ case "int8":
+ return Types.typeForClass(Byte.class, restrictions);
+ case "int16":
+ return Types.typeForClass(Short.class, restrictions);
+ case "int32":
+ return Types.typeForClass(Integer.class, restrictions);
+ case "int64":
+ return Types.typeForClass(Long.class, restrictions);
+ case "string":
+ return Types.typeForClass(String.class, restrictions);
+ case "uint8":
+ return Types.typeForClass(Uint8.class, restrictions);
+ case "uint16":
+ return Types.typeForClass(Uint16.class, restrictions);
+ case "uint32":
+ return Types.typeForClass(Uint32.class, restrictions);
+ case "uint64":
+ return Types.typeForClass(Uint64.class, restrictions);
+ default:
+ return javaTypeForSchemaDefinitionType(type, parentNode, lenientRelativeLeafrefs);
+ }
+ }
+
+ @Override
+ public String getTypeDefaultConstruction(final LeafSchemaNode node) {
+ return null;
+ }
+
+ @Override
+ public String getConstructorPropertyName(final SchemaNode node) {
+ return null;
+ }
+
+ @Override
+ public String getParamNameFromType(final TypeDefinition<?> type) {
+ return "_" + BindingMapping.getPropertyName(type.getQName().getLocalName());
+ }
+}
\ No newline at end of file
@Test
public void javaTypeForSchemaDefinitionTypeTest() {
- final TypeProvider typeProvider = BaseYangTypes.BASE_YANG_TYPES_PROVIDER;
+ final TypeProvider typeProvider = BaseYangTypesProvider.INSTANCE;
Type javaType = typeProvider.javaTypeForSchemaDefinitionType(binary, binary);
assertNotNull(javaType);
@Test
public void javaTypeForRestrictedSchemaDefinitionTypeTest() {
- final TypeProvider typeProvider = BaseYangTypes.BASE_YANG_TYPES_PROVIDER;
+ final TypeProvider typeProvider = BaseYangTypesProvider.INSTANCE;
Type javaType = typeProvider.javaTypeForSchemaDefinitionType(binary, binary,
BindingGeneratorUtil.getRestrictions(binary));