RFC8040 'rc:yang-data' support for mdsal binding generator
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / reactor / StatementNamespace.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 static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
12
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * <a href="https://www.rfc-editor.org/rfc/rfc6020#section-6.2.1">YANG statement namespaces</a> which we process.
17  */
18 // FIXME: move this to 'BindingNamespace' in binding-spec-util
19 enum StatementNamespace {
20     /**
21      * The namespace of all {@code feature} statements, bullet 3.
22      */
23     FEATURE("$F"),
24     /**
25      * The namespace of all {@code identity} statements, bullet 4.
26      */
27     IDENTITY("$I"),
28     /**
29      * The namespace of all {@code typedef} statements, bullet 5.
30      */
31     TYPEDEF("$T"),
32     /**
33      * The namespace of all {@code grouping} statements, bullet 6.
34      */
35     GROUPING("$G"),
36     /**
37      * The namespace of all RFC8040 {@code ietf-restconf:yang-data} statements. These sit outside of the usual YANG
38      * statement namespaces, but may overlap in the usual case when template names conform to YANG {@code identifier}
39      * rules.
40      */
41     YANG_DATA("$YD"),
42     /**
43      * All other processed statements. Includes {@code augment}, and {@code schema tree} statements.
44      */
45     // FIXME: peel augment into "$A", which our own thing
46     // FIXME: add "$D" to disambiguate <module-name>Data
47     // FIXME: add "$L" to disambiguate <module-name>Listener
48     // FIXME: add "$S" to disambiguate <module-name>Service
49     DEFAULT("");
50
51     private final @NonNull String suffix;
52
53     StatementNamespace(final @NonNull String suffix) {
54         this.suffix = requireNonNull(suffix);
55     }
56
57     @NonNull String appendSuffix(final String str) {
58         return suffix.isEmpty() ? verifyNotNull(str) : str + suffix;
59     }
60 }