Covert yang-binding to bnd-parent
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / contract / 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.yangtools.yang.binding.contract;
9
10 import static com.google.common.base.Verify.verify;
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 public enum StatementNamespace {
19     /**
20      * The namespace of all {@code feature} statements, bullet 3.
21      */
22     FEATURE("$F"),
23     /**
24      * The namespace of all {@code identity} statements, bullet 4.
25      */
26     IDENTITY("$I"),
27     /**
28      * The namespace of all {@code typedef} statements, bullet 5.
29      */
30     TYPEDEF("$T"),
31     /**
32      * The namespace of all {@code grouping} statements, bullet 6.
33      */
34     GROUPING("$G"),
35     /**
36      * The namespace of all RFC8040 {@code ietf-restconf:yang-data} statements. These sit outside of the usual YANG
37      * statement namespaces, but may overlap in the usual case when template names conform to YANG {@code identifier}
38      * rules.
39      */
40     YANG_DATA("$YD"),
41     /**
42      * The namespace for {@code augment} statements. These are specific to Java Binding.
43      */
44     AUGMENT("$AU", true),
45     ACTION("$AC", true),
46     ANYDATA("$AD", true),
47     ANYXML("$AX", true),
48     CASE("$CA", true),
49     CHOICE("$CH", true),
50     CONTAINER("$CO", true),
51     INPUT("$IP", true),
52     LEAF("$LE", true),
53     LIST("$LI", true),
54     LEAF_LIST("$LL", true),
55     /**
56      * The namespace for a {@code list}'s {@code key} statement. This typically does not conflict, but could in case of
57      * <pre>{@code
58      *   module foo {
59      *     list foo { // results Foo
60      *       key bar;  // triggers FooKey as a sibling to Foo
61      *       leaf bar {
62      *         type string;
63      *       }
64      *     }
65      *
66      *     container foo-key; // results in FooKey
67      *   }
68      * }</pre>
69      * In this case the key-derived FooKey gets shifted to {@code $KE}.
70      */
71     KEY("$KE", true),
72     NOTIFICATION("$NO", true),
73     OUTPUT("$OU", true),
74     RPC("$RP", true),
75     /**
76      * The namespace for a {@code module}'s data root interface. This typically does not conflict, but could in case of
77      * <pre>{@code
78      *     module foo { // results in FooData
79      *       container foo-data; // results in FooData as well
80      *     }
81      * }</pre>
82      * In this case the module-derived FooData gets shifted to {@code $D}.
83      */
84     DATA_ROOT("$D", true);
85
86     private final @NonNull String suffix;
87     private final boolean resistant;
88
89     StatementNamespace(final @NonNull String suffix) {
90         this(suffix, false);
91     }
92
93     StatementNamespace(final @NonNull String suffix, final boolean resistant) {
94         verify(!suffix.isEmpty());
95         this.suffix = requireNonNull(suffix);
96         this.resistant = resistant;
97     }
98
99     public @NonNull String suffix() {
100         return suffix;
101     }
102
103     public boolean resistant() {
104         return resistant;
105     }
106 }