Bump to odlparent-9.0.0/yangtools-7.0.1-SNAPSHOT
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / mdsal / binding / generator / impl / reactor / ClassNamingStrategy.java
1 /*
2  * Copyright (c) 2021 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.generator.impl.reactor;
9
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.common.AbstractQName;
17
18 /**
19  * Enumeration of known strategies for translating a YANG node identifier into a Java package name segment or a Java
20  * simple class name.
21  */
22 abstract class ClassNamingStrategy implements Immutable {
23     /**
24      * Return the YANG node identifier backing this naming strategy. Only the {@link AbstractQName#getLocalName()} part
25      * of the identifier is significant.
26      *
27      * @return YANG node identifier.
28      */
29     abstract @NonNull AbstractQName nodeIdentifier();
30
31     /**
32      * Return the simple Java class name assigned by this naming strategy.
33      *
34      * @return Simple class name
35      */
36     @NonNull  String simpleClassName() {
37         return BindingMapping.getClassName(nodeIdentifier().getLocalName());
38     }
39
40     /**
41      * Return the fallback naming strategy. The fallback is used if this strategy ends up being insufficient in
42      * assigning a unique name.
43      *
44      * @return Fallback strategy, {@code null} if there is no fallback.
45      */
46     abstract @Nullable ClassNamingStrategy fallback();
47
48     @Override
49     public final String toString() {
50         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
51     }
52
53     abstract @NonNull ToStringHelper addToStringAttributes(@NonNull ToStringHelper helper);
54 }