Adopt yangtools-11.0.0-SNAPSHOT
[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 import org.opendaylight.yangtools.yang.common.YangDataName;
15
16 /**
17  * Naming strategy for {@code ietf-restconf:yang-data} template which has a generic string not matching YANG identifier.
18  */
19 @NonNullByDefault
20 final class YangDataNamingStrategy extends ClassNamingStrategy {
21     private final String javaIdentifier;
22
23     YangDataNamingStrategy(final YangDataName templateName) {
24         javaIdentifier = Naming.mapYangDataName(templateName);
25     }
26
27     @Override
28     String simpleClassName() {
29         return javaIdentifier;
30     }
31
32     @Override
33     @Nullable ClassNamingStrategy fallback() {
34         // javaIdentifier is guaranteed to be unique, there is no need for fallback
35         return null;
36     }
37
38     @Override
39     String rootName() {
40         return javaIdentifier;
41     }
42
43     @Override
44     String childPackage() {
45         // javaIdentifier is always unique and provides an identifier which is suitable for package naming as well,
46         //  except we need to further expand the package name so it does not class with the class.
47         // Since the strategy escapes '$', appending one cannot clash.
48         return javaIdentifier + '$';
49     }
50
51     @Override
52     ToStringHelper addToStringAttributes(final ToStringHelper helper) {
53         return helper.add("javaIdentifier", javaIdentifier);
54     }
55 }