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 com.google.common.base.Optional;
11 import java.util.Collection;
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 context of parent of statement
42 StmtContext<?, ?, ?> getParentContext();
45 * @return raw statement argument string
48 String rawStatementArgument();
51 A getStatementArgument();
54 * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
55 * {@link Optional#absent()} is returned.
57 * @return Optional SchemaPath
59 @Nonnull Optional<SchemaPath> getSchemaPath();
61 boolean isConfiguration();
64 * Checks whether this statement is placed within a 'yang-data' extension statement.
65 * Some YANG statements are constrained when used within a 'yang-data' statement.
66 * See the following link for more information - https://tools.ietf.org/html/rfc8040#section-8
68 * @return true if it is placed within a 'yang-data' extension statement, otherwise false
70 boolean isInYangDataExtensionBody();
72 boolean isEnabledSemanticVersioning();
75 <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
76 Class<N> type, KT key) throws NamespaceNotAvailableException;
78 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
81 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
84 StmtContext<?, ?, ?> getRoot();
87 * Return declared substatements. These are the statements which are explicitly written in the source model.
89 * @return Collection of declared substatements
92 Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements();
95 * Return effective substatements. These are the statements which are added as this statement's substatements
96 * complete their effective model phase.
98 * @return Collection of declared substatements
101 Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
104 * Builds {@link DeclaredStatement} for statement context.
109 * Builds {@link EffectiveStatement} for statement context
113 boolean isSupportedToBuildEffective();
115 Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
117 Mutable<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
119 Mutable<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
120 CopyType typeOfCopy);
122 CopyHistory getCopyHistory();
124 boolean isSupportedByFeatures();
126 StmtContext<?, ?, ?> getOriginalCtx();
128 boolean isRootContext();
132 ModelProcessingPhase getCompletedPhase();
135 * Return version of root statement context.
137 * @return version of root statement context
139 @Nonnull YangVersion getRootVersion();
141 interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
142 extends StmtContext<A, D, E> {
145 Mutable<?, ?, ?> getParentContext();
147 <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, KT key,
148 VT value) throws NamespaceNotAvailableException;
152 Mutable<?, ?, ?> getRoot();
155 Collection<? extends Mutable<?, ?, ?>> mutableDeclaredSubstatements();
158 Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements();
161 * Create a new inference action to be executed during specified phase. The action cannot be cancelled
162 * and will be executed even if its definition remains incomplete.
164 * @param phase Target phase in which the action will resolved.
165 * @return A new action builder.
166 * @throws NullPointerException if the specified phase is null
168 @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
171 * adds statement to namespace map with the key
174 * {@link StatementNamespace} child that determines namespace to be added to
176 * of type according to namespace class specification
178 * to be added to namespace map
180 <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
181 StmtContext<?, ?, ?> stmt);
184 * Set version of root statement context.
187 * of root statement context
189 void setRootVersion(YangVersion version);
192 * Add mutable statement to seal. Each mutable statement must be sealed
193 * as the last step of statement parser processing.
195 * @param mutableStatement
196 * mutable statement which should be sealed
198 void addMutableStmtToSeal(MutableStatement mutableStatement);
201 * Add required module. Based on these dependencies are collected
202 * required sources from library sources.
205 * ModuleIdentifier of module required by current root
208 void addRequiredModule(ModuleIdentifier dependency);
210 void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);
212 void addAsEffectOfStatement(Collection<? extends StmtContext<?, ?, ?>> ctxs);
215 * Set identifier of current root context.
218 * of current root context
220 void setRootIdentifier(ModuleIdentifier identifier);
222 void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
224 void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
226 void setOriginalCtx(StmtContext<?, ?, ?> originalCtx);
228 void setOrder(int order);
230 // FIXME: this seems to be unused, but looks useful.
231 void setCompletedPhase(ModelProcessingPhase completedPhase);