2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
10 import java.util.Collection;
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;
27 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
30 StatementSource getStatementSource();
33 StatementSourceReference getStatementSourceReference();
36 StatementDefinition getPublicDefinition();
39 * Return the parent statement context, or null if this is the root statement.
41 * @return context of parent of statement, or null if this is the root statement.
44 StmtContext<?, ?, ?> getParentContext();
47 * @return raw statement argument string
50 String rawStatementArgument();
53 A getStatementArgument();
56 * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
57 * {@link Optional#empty()} is returned.
59 * @return Optional SchemaPath
61 @Nonnull Optional<SchemaPath> getSchemaPath();
63 boolean isConfiguration();
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
70 * @return true if it is placed within a 'yang-data' extension statement, otherwise false
72 boolean isInYangDataExtensionBody();
74 boolean isEnabledSemanticVersioning();
77 <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
78 Class<N> type, KT key) throws NamespaceNotAvailableException;
80 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
83 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
86 StmtContext<?, ?, ?> getRoot();
89 * Return declared substatements. These are the statements which are explicitly written in the source model.
91 * @return Collection of declared substatements
94 Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements();
97 * Return effective substatements. These are the statements which are added as this statement's substatements
98 * complete their effective model phase.
100 * @return Collection of declared substatements
103 Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
106 * Builds {@link DeclaredStatement} for statement context.
111 * Builds {@link EffectiveStatement} for statement context
115 boolean isSupportedToBuildEffective();
117 Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
120 * @return copy of this considering {@link CopyType} (augment, uses)
122 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
124 Mutable<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
127 * @return copy of this considering {@link CopyType} (augment, uses)
129 * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
131 Mutable<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
132 CopyType typeOfCopy);
134 CopyHistory getCopyHistory();
136 boolean isSupportedByFeatures();
138 Optional<StmtContext<?, ?, ?>> getOriginalCtx();
142 ModelProcessingPhase getCompletedPhase();
145 * Return version of root statement context.
147 * @return version of root statement context
149 @Nonnull YangVersion getRootVersion();
151 interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
152 extends StmtContext<A, D, E> {
155 Mutable<?, ?, ?> getParentContext();
157 <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, KT key,
158 VT value) throws NamespaceNotAvailableException;
162 Mutable<?, ?, ?> getRoot();
165 Collection<? extends Mutable<?, ?, ?>> mutableDeclaredSubstatements();
168 Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements();
171 * Create a new inference action to be executed during specified phase. The action cannot be cancelled
172 * and will be executed even if its definition remains incomplete.
174 * @param phase Target phase in which the action will resolved.
175 * @return A new action builder.
176 * @throws NullPointerException if the specified phase is null
178 @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
181 * adds statement to namespace map with the key
184 * {@link StatementNamespace} child that determines namespace to be added to
186 * of type according to namespace class specification
188 * to be added to namespace map
190 <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
191 StmtContext<?, ?, ?> stmt);
194 * Set version of root statement context.
197 * of root statement context
199 void setRootVersion(YangVersion version);
202 * Add mutable statement to seal. Each mutable statement must be sealed
203 * as the last step of statement parser processing.
205 * @param mutableStatement
206 * mutable statement which should be sealed
208 void addMutableStmtToSeal(MutableStatement mutableStatement);
211 * Add required module. Based on these dependencies are collected
212 * required sources from library sources.
215 * ModuleIdentifier of module required by current root
218 void addRequiredModule(ModuleIdentifier dependency);
220 void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);
222 void addAsEffectOfStatement(Collection<? extends StmtContext<?, ?, ?>> ctxs);
225 * Set identifier of current root context.
228 * of current root context
230 void setRootIdentifier(ModuleIdentifier identifier);
232 void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
234 void setOrder(int order);
236 // FIXME: this seems to be unused, but looks useful.
237 void setCompletedPhase(ModelProcessingPhase completedPhase);