Cleanup BindingReflections.getModuleInfo()
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / mdsal / binding / yang / types / BaseYangTypesProvider.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.yang.types;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
12 import org.opendaylight.mdsal.binding.model.api.Restrictions;
13 import org.opendaylight.mdsal.binding.model.api.Type;
14 import org.opendaylight.mdsal.binding.model.util.BaseYangTypes;
15 import org.opendaylight.mdsal.binding.model.util.Types;
16 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
18
19 @Deprecated(forRemoval = true)
20 final class BaseYangTypesProvider implements TypeProvider {
21     static final @NonNull BaseYangTypesProvider INSTANCE = new BaseYangTypesProvider();
22
23     private BaseYangTypesProvider() {
24         // Hidden on purpose
25     }
26
27     /**
28      * Searches <code>Type</code> value to which is YANG <code>type</code>
29      * mapped.
30      *
31      * @param type
32      *            type definition representation of YANG type
33      * @return java <code>Type</code> representation of <code>type</code>.
34      *         If <code>type</code> isn't found then <code>null</code> is
35      *         returned.
36      */
37     @Override
38     public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
39             final boolean lenientRelativeLeafrefs) {
40         return type == null ? null : BaseYangTypes.javaTypeForYangType(type.getQName().getLocalName());
41     }
42
43     @Override
44     public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
45             final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
46         final String typeName = type.getQName().getLocalName();
47         final Type mapped = BaseYangTypes.javaTypeForYangType(typeName);
48         return mapped == null || restrictions == null ? mapped : Types.restrictedType(mapped, restrictions);
49     }
50 }