7349ccdd2d680cbe778fc37de6e7181a71e15f07
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / util / BindingSchemaMapping.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, 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.dom.codec.util;
9
10 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
11 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
12 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
13 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
15
16 public final class BindingSchemaMapping {
17     private BindingSchemaMapping() {
18
19     }
20
21     public static String getGetterMethodName(final DataSchemaNode node) {
22         return node instanceof TypedDataSchemaNode ? getGetterMethodName((TypedDataSchemaNode) node)
23                 : BindingMapping.getGetterMethodName(node.getQName(), false);
24     }
25
26     public static String getGetterMethodName(final TypedDataSchemaNode node) {
27         // Bug 8903: If it is a derived type of boolean, not an inner type, then the return type
28         // of method would be the generated type of typedef not build-in types, so here it should be 'get'.
29         final TypeDefinition<?> type = node.getType();
30         return BindingMapping.getGetterMethodName(node.getQName(),
31             type instanceof BooleanTypeDefinition
32             && (type.getPath().equals(node.getPath()) || type.getBaseType() == null));
33     }
34 }