Rehost BindingMapping in yang.binding.contract.Naming
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / reactor / YangDataNamingStrategy.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech s.r.o. 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.generator.impl.reactor;
9
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.binding.contract.Naming;
14
15 /**
16  * Naming strategy for {@code ietf-restconf:yang-data} template which has a generic string not matching YANG identifier.
17  */
18 @NonNullByDefault
19 final class YangDataNamingStrategy extends ClassNamingStrategy {
20     private final String javaIdentifier;
21
22     YangDataNamingStrategy(final String templateName) {
23         javaIdentifier = Naming.mapYangDataName(templateName);
24     }
25
26     @Override
27     String simpleClassName() {
28         return javaIdentifier;
29     }
30
31     @Override
32     @Nullable ClassNamingStrategy fallback() {
33         // javaIdentifier is guaranteed to be unique, there is no need for fallback
34         return null;
35     }
36
37     @Override
38     String rootName() {
39         return javaIdentifier;
40     }
41
42     @Override
43     String childPackage() {
44         // javaIdentifier is always unique and provides an identifier which is suitable for package naming as well,
45         //  except we need to further expand the package name so it does not class with the class.
46         // Since the strategy escapes '$', appending one cannot clash.
47         return javaIdentifier + '$';
48     }
49
50     @Override
51     ToStringHelper addToStringAttributes(final ToStringHelper helper) {
52         return helper.add("javaIdentifier", javaIdentifier);
53     }
54 }