Remove AugmentationSchemaNode.getOriginalDefinition()
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / EffectiveStmtCtx.java
1 /*
2  * Copyright (c) 2020 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.parser.spi.meta;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.VerifyException;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.concepts.Immutable;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22
23 /**
24  * Effective view of a {@link StmtContext} for the purposes of creating an {@link EffectiveStatement}.
25  */
26 @Beta
27 public interface EffectiveStmtCtx extends CommonStmtCtx, StmtContextCompat, Immutable {
28     /**
29      * Return parent of this context, if there is one. All statements except for top-level source statements, such as
30      * {@code module} and {@code submodule}.
31      *
32      * @return Parent context, or null if this statement is the root
33      */
34     @Nullable Parent effectiveParent();
35
36     /**
37      * Return parent of this context.
38      *
39      * @return Parent context
40      * @throws VerifyException if this context is already the root
41      */
42     default @NonNull Parent getEffectiveParent() {
43         return verifyNotNull(effectiveParent(), "Attempted to access beyond root context");
44     }
45
46     /**
47      * Minimum amount of parent state required to build an accurate effective view of a particular child. Child state
48      * is expressed as {@link Current}.
49      */
50     @Beta
51     interface Parent extends EffectiveStmtCtx {
52         /**
53          * Effective {@code config} statement value.
54          */
55         @Beta
56         enum EffectiveConfig {
57             /**
58              * We have an effective {@code config true} statement.
59              */
60             TRUE(Boolean.TRUE),
61             /**
62              * We have an effective {@code config false} statement.
63              */
64             FALSE(Boolean.FALSE),
65             /**
66              * We are in a context where {@code config} statements are ignored.
67              */
68             IGNORED(null),
69             /**
70              * We are in a context where {@code config} is not determined, such as within a {@code grouping}.
71              */
72             UNDETERMINED(null);
73
74             private final Boolean config;
75
76             EffectiveConfig(final @Nullable Boolean config) {
77                 this.config = config;
78             }
79
80             /**
81              * Return this value as a {@link Boolean} for use with {@link DataSchemaNode#effectiveConfig()}.
82              *
83              * @return A boolean or null
84              */
85             public @Nullable Boolean asNullable() {
86                 return config;
87             }
88         }
89
90         /**
91          * Return the effective {@code config} statement value.
92          *
93          * @return This statement's effective config
94          */
95         @NonNull EffectiveConfig effectiveConfig();
96
97         // FIXME: 7.0.0: this is currently only used by AbstractTypeStatement
98         @NonNull QNameModule effectiveNamespace();
99     }
100
101     /**
102      * Minimum amount of state required to build an accurate effective view of a statement. This is a strict superset
103      * of information available in {@link Parent}.
104      *
105      * @param <A> Argument type
106      * @param <D> Class representing declared version of this statement
107      */
108     @Beta
109     interface Current<A, D extends DeclaredStatement<A>> extends Parent, NamespaceStmtCtx, BoundStmtCtxCompat<A, D> {
110
111         @NonNull QName moduleName();
112
113         // FIXME: 8.0.0: this method should be moved to stmt.type in some shape or form
114         @NonNull QName argumentAsTypeQName();
115
116         /**
117          * Summon the <a href="https://en.wikipedia.org/wiki/Rabbit_of_Caerbannog">Rabbit of Caerbannog</a>.
118          *
119          * @param <E> Effective Statement representation
120          * @return The {@code Legendary Black Beast of Arrrghhh}.
121          */
122         // FIXME: YANGTOOLS-1186: lob the Holy Hand Grenade of Antioch
123         @Deprecated
124         <E extends EffectiveStatement<A, D>> @NonNull StmtContext<A, D, E> caerbannog();
125     }
126
127     /**
128      * A restricted version of {@link Current}, which does not expose the raw argument or the declared statement.
129      *
130      * @param <A> Argument type
131      * @param <D> Class representing declared version of this statement
132      */
133     @Beta
134     interface UndeclaredCurrent<A, D extends DeclaredStatement<A>> extends Current<A, D> {
135         @Deprecated
136         @Override
137         default String rawArgument() {
138             throw new UnsupportedOperationException();
139         }
140
141         @Deprecated
142         @Override
143         default D declared() {
144             throw new UnsupportedOperationException();
145         }
146     }
147 }