BUG-6972: eliminate StmtContext.getOrder()
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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 java.util.Collection;
11 import java.util.Map;
12 import java.util.Optional;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.YangVersion;
17 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
22 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
23 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
26
27 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
28
29     @Nonnull
30     StatementSource getStatementSource();
31
32     @Nonnull
33     StatementSourceReference getStatementSourceReference();
34
35     @Nonnull
36     StatementDefinition getPublicDefinition();
37
38     /**
39      * Return the parent statement context, or null if this is the root statement.
40      *
41      * @return context of parent of statement, or null if this is the root statement.
42      */
43     @Nullable
44     StmtContext<?, ?, ?> getParentContext();
45
46     /**
47      * @return raw statement argument string
48      */
49     @Nullable
50     String rawStatementArgument();
51
52     @Nullable
53     A getStatementArgument();
54
55     /**
56      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
57      * {@link Optional#empty()} is returned.
58      *
59      * @return Optional SchemaPath
60      */
61     @Nonnull Optional<SchemaPath> getSchemaPath();
62
63     boolean isConfiguration();
64
65     /**
66      * Checks whether this statement is placed within a 'yang-data' extension statement.
67      * Some YANG statements are constrained when used within a 'yang-data' statement.
68      * See the following link for more information - https://tools.ietf.org/html/rfc8040#section-8
69      *
70      * @return true if it is placed within a 'yang-data' extension statement, otherwise false
71      */
72     boolean isInYangDataExtensionBody();
73
74     boolean isEnabledSemanticVersioning();
75
76     @Nonnull
77     <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
78             Class<N> type, KT key) throws NamespaceNotAvailableException;
79
80     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
81             Class<N> type);
82
83     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
84
85     @Nonnull
86     StmtContext<?, ?, ?> getRoot();
87
88     /**
89      * Return declared substatements. These are the statements which are explicitly written in the source model.
90      *
91      * @return Collection of declared substatements
92      */
93     @Nonnull
94     Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements();
95
96     /**
97      * Return effective substatements. These are the statements which are added as this statement's substatements
98      * complete their effective model phase.
99      *
100      * @return Collection of declared substatements
101      */
102     @Nonnull
103     Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
104
105     /**
106      * Builds {@link DeclaredStatement} for statement context.
107      */
108     D buildDeclared();
109
110     /**
111      * Builds {@link EffectiveStatement} for statement context
112      */
113     E buildEffective();
114
115     boolean isSupportedToBuildEffective();
116
117     Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
118
119     /**
120      * @return copy of this considering {@link CopyType} (augment, uses)
121      *
122      * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
123      */
124     Mutable<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
125
126     /**
127      * @return copy of this considering {@link CopyType} (augment, uses)
128      *
129      * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
130      */
131     Mutable<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
132             CopyType typeOfCopy);
133
134     CopyHistory getCopyHistory();
135
136     boolean isSupportedByFeatures();
137
138     Optional<StmtContext<?, ?, ?>> getOriginalCtx();
139
140     ModelProcessingPhase getCompletedPhase();
141
142     /**
143      * Return version of root statement context.
144      *
145      * @return version of root statement context
146      */
147     @Nonnull YangVersion getRootVersion();
148
149     interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
150             extends StmtContext<A, D, E> {
151
152         @Override
153         Mutable<?, ?, ?> getParentContext();
154
155         <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, KT key,
156                 VT value) throws NamespaceNotAvailableException;
157
158         @Nonnull
159         @Override
160         Mutable<?, ?, ?> getRoot();
161
162         @Nonnull
163         Collection<? extends Mutable<?, ?, ?>> mutableDeclaredSubstatements();
164
165         @Nonnull
166         Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements();
167
168         /**
169          * Create a new inference action to be executed during specified phase. The action cannot be cancelled
170          * and will be executed even if its definition remains incomplete.
171          *
172          * @param phase Target phase in which the action will resolved.
173          * @return A new action builder.
174          * @throws NullPointerException if the specified phase is null
175          */
176         @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
177
178         /**
179          * adds statement to namespace map with the key
180          *
181          * @param namespace
182          *            {@link StatementNamespace} child that determines namespace to be added to
183          * @param key
184          *            of type according to namespace class specification
185          * @param stmt
186          *            to be added to namespace map
187          */
188         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
189                 StmtContext<?, ?, ?> stmt);
190
191         /**
192          * Set version of root statement context.
193          *
194          * @param version
195          *            of root statement context
196          */
197         void setRootVersion(YangVersion version);
198
199         /**
200          * Add mutable statement to seal. Each mutable statement must be sealed
201          * as the last step of statement parser processing.
202          *
203          * @param mutableStatement
204          *            mutable statement which should be sealed
205          */
206         void addMutableStmtToSeal(MutableStatement mutableStatement);
207
208         /**
209          * Add required module. Based on these dependencies are collected
210          * required sources from library sources.
211          *
212          * @param dependency
213          *            ModuleIdentifier of module required by current root
214          *            context
215          */
216         void addRequiredModule(ModuleIdentifier dependency);
217
218         void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);
219
220         void addAsEffectOfStatement(Collection<? extends StmtContext<?, ?, ?>> ctxs);
221
222         /**
223          * Set identifier of current root context.
224          *
225          * @param identifier
226          *            of current root context
227          */
228         void setRootIdentifier(ModuleIdentifier identifier);
229
230         void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
231
232         // FIXME: this seems to be unused, but looks useful.
233         void setCompletedPhase(ModelProcessingPhase completedPhase);
234     }
235 }