Separate out YangIdentifierClassNamingStrategy
[mdsal.git] / binding / mdsal-binding-generator / 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.yangtools.concepts.Immutable;
15
16 /**
17  * Enumeration of known strategies for translating a YANG node identifier into a Java package name segment or a Java
18  * simple class name.
19  */
20 abstract class ClassNamingStrategy implements Immutable {
21     /**
22      * Return the simple Java class name assigned by this naming strategy.
23      *
24      * @return Simple class name
25      */
26     abstract @NonNull String simpleClassName();
27
28     /**
29      * Return the fallback naming strategy. The fallback is used if this strategy ends up being insufficient in
30      * assigning a unique name.
31      *
32      * @return Fallback strategy, {@code null} if there is no fallback.
33      */
34     abstract @Nullable ClassNamingStrategy fallback();
35
36     // FIXME: document this method
37     abstract @NonNull String rootName();
38
39     /**
40      * Return the {@code Java package name} allocated for any classes generated as children of this strategy.
41      *
42      * @return A package fragment name, for example {@code "foo.bar.baz"}
43      */
44     abstract @NonNull String childPackage();
45
46     @Override
47     public final String toString() {
48         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
49     }
50
51     abstract @NonNull ToStringHelper addToStringAttributes(@NonNull ToStringHelper helper);
52 }