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
9 package org.opendaylight.yangtools.yang.parser.spi.meta;
11 import com.google.common.annotations.Beta;
12 import java.util.Optional;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementDefinitionContext;
24 * Support for processing concrete YANG statement.
27 * This interface is intended to be implemented by developers, which want to
28 * introduce support of statement to parser. Consider subclassing
29 * {@link AbstractStatementSupport} for easier implementation of this interface.
34 * Declared Statement representation
36 * Effective Statement representation
38 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
39 extends StatementDefinition, StatementFactory<A, D, E> {
42 * Returns public statement definition, which will be present in built
45 * Public statement definition may be used to provide different
46 * implementation of statement definition, which will not retain any build
47 * specific data or context.
49 * @return public statement definition, which will be present in built
52 StatementDefinition getPublicView();
56 * Parses textual representation of argument in object representation.
59 * Context, which may be used to access source-specific
60 * namespaces required for parsing.
62 * String representation of value, as was present in text source.
63 * @return Parsed value
64 * @throws SourceException
65 * when an inconsistency is detected.
67 A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value);
70 * Invoked when a statement supported by this instance is added to build context. This allows implementations
71 * of this interface to start tracking the statement and perform any modifications to the build context hierarchy,
72 * accessible via {@link StmtContext#getParentContext()}. One such use is populating the parent's namespaces to
73 * allow it to locate this child statement.
76 * Context of added statement. No substatements are available.
78 void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
81 * Invoked before a substatement with specified offset, definition,
82 * reference and argument is created and added to parent statement. This
83 * allows implementations of this interface perform any modifications to the
84 * build context hierarchy before a substatement is created. One such use is
85 * creating an implicit statement.
88 * Context of parent statement where a new substatement should be
89 * created. No substatements are available.
97 * substatement argument
98 * @return optional of an implicit substatement
100 Optional<StatementContextBase<?, ?, ?>> beforeSubStatementCreated(final Mutable<?, ?, ?> stmt, final int offset,
101 final StatementDefinitionContext<?, ?, ?> def, final StatementSourceReference ref, final String argument);
104 * Invoked when statement is closed during
105 * {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
106 * from this and previous phase are available.
108 * Implementation may use method to perform actions on this event or
109 * register modification action using
110 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
113 * Context of added statement.
115 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
118 * Invoked when statement is closed during
119 * {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
120 * from this and previous phase are available.
122 * Implementation may use method to perform actions on this event or
123 * register modification action using
124 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
127 * Context of added statement.
128 * @throws SourceException
129 * when an inconsistency is detected.
131 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
134 * Invoked when statement is closed during
135 * {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase, only
136 * substatements from this phase are available.
138 * Implementation may use method to perform actions on this event or
139 * register modification action using
140 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
143 * Context of added statement. Argument and statement parent is
145 * @throws SourceException
146 * when an inconsistency is detected.
148 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
151 * Invoked when statement is closed during
152 * {@link ModelProcessingPhase#FULL_DECLARATION} phase.
154 * Invoked when statement is closed during
155 * {@link ModelProcessingPhase#FULL_DECLARATION} phase, only substatements
156 * from this phase are available.
158 * Implementation may use method to perform actions on this event or
159 * register modification action using
160 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
164 * Context of added statement. Argument and statement parent is
166 * @throws SourceException
167 * when an inconsistency is detected.
169 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
172 * Returns true if this support has argument specific supports.
174 boolean hasArgumentSpecificSupports();
177 * If this support has argument specific supports, the method returns
178 * support specific for given argument (e.g. type statement support need to
179 * be specialized based on its argument), otherwise returns null.
182 * argument of statement
183 * @return statement support specific for supplied argument or null
186 StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);
189 * Given a raw string representation of an argument, try to use a shared representation
193 * @return A potentially-shard instance
195 default String internArgument(final String rawArgument) {
200 * Returns unknown statement form of a regular yang statement supplied as
201 * parameter to the method.
204 * statement definition of a regular yang statement
205 * @return Optional of unknown statement form of a regular yang statement or
206 * Optional.empty() if it is not supported by this statement support
208 default Optional<StatementDefinitionContext<?, ?, ?>> getUnknownStatementDefinitionOf(
209 final StatementDefinitionContext<?, ?, ?> yangStmtDef) {
210 return Optional.empty();
214 * Returns true if this statement support and all its substatements ignore
215 * if-feature statements (e.g. yang-data extension defined in
216 * https://tools.ietf.org/html/rfc8040#section-8). Default implementation
219 * @return true if this statement support ignores if-feature statements,
223 default boolean isIgnoringIfFeatures() {
228 * Returns true if this statement support and all its substatements ignore
229 * config statements (e.g. yang-data extension defined in
230 * https://tools.ietf.org/html/rfc8040#section-8). Default implementation
233 * @return true if this statement support ignores config statements,
237 default boolean isIgnoringConfig() {