c82825e094e4faedd919b4a6dd3f38d736f977f5
[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 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
16
17 public final class BindingSchemaMapping {
18     private BindingSchemaMapping() {
19
20     }
21
22     public static String getGetterMethodName(final DataSchemaNode node) {
23         return node instanceof TypedDataSchemaNode ? getGetterMethodName((TypedDataSchemaNode) node)
24                 : BindingMapping.getGetterMethodName(node.getQName(), false);
25     }
26
27     public static String getGetterMethodName(final TypedDataSchemaNode node) {
28         // Bug 8903: If it is a derived type of boolean or empty, not an inner type, then the return type
29         // of method would be the generated type of typedef not build-in types, so here it should be 'get'.
30         final TypeDefinition<?> type = node.getType();
31         return BindingMapping.getGetterMethodName(node.getQName(),
32             (type instanceof BooleanTypeDefinition || type instanceof EmptyTypeDefinition)
33             && (type.getPath().equals(node.getPath()) || type.getBaseType() == null));
34     }
35 }