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.common.QNameModule;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 * Support for processing concrete YANG statement.
24 * This interface is intended to be implemented by developers, which want to
25 * introduce support of statement to parser. Consider subclassing
26 * {@link AbstractStatementSupport} for easier implementation of this interface.
31 * Declared Statement representation
33 * Effective Statement representation
35 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
36 extends StatementDefinition, StatementFactory<A, D, E> {
39 * Returns public statement definition, which will be present in built
42 * Public statement definition may be used to provide different
43 * implementation of statement definition, which will not retain any build
44 * specific data or context.
46 * @return public statement definition, which will be present in built
49 StatementDefinition getPublicView();
52 * Parses textual representation of argument in object representation.
55 * Context, which may be used to access source-specific
56 * namespaces required for parsing.
58 * String representation of value, as was present in text source.
59 * @return Parsed value
60 * @throws SourceException
61 * when an inconsistency is detected.
63 A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value);
66 * Adapts the argument value to match a new module.
69 * Context, which may be used to access source-specific
70 * namespaces required for parsing.
72 * Target module, may not be null.
73 * @return Adapted argument value. The default implementation returns original value stored in context.
75 default A adaptArgumentValue(final StmtContext<A, D, E> ctx, final QNameModule targetModule) {
76 return ctx.getStatementArgument();
80 * Invoked when a statement supported by this instance is added to build context. This allows implementations
81 * of this interface to start tracking the statement and perform any modifications to the build context hierarchy,
82 * accessible via {@link StmtContext#getParentContext()}. One such use is populating the parent's namespaces to
83 * allow it to locate this child statement.
86 * Context of added statement. No substatements are available.
88 void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
91 * Returns implicit parent statement support for supplied statement
92 * definition, if it is defined. This allows implementations of this
93 * interface add implicit parent to the build context hierarchy before a
94 * substatement is created.
97 * statement definition of substatement
98 * @return optional of implicit parent statement support
100 Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef);
103 * Invoked when statement is closed during
104 * {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
105 * from this and previous phase are available.
107 * Implementation may use method to perform actions on this event or
108 * register modification action using
109 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
112 * Context of added statement.
114 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
117 * Invoked when statement is closed during
118 * {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
119 * from this and previous phase are available.
121 * Implementation may use method to perform actions on this event or
122 * register modification action using
123 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
126 * Context of added statement.
127 * @throws SourceException
128 * when an inconsistency is detected.
130 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
133 * Invoked when statement is closed during
134 * {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase, only
135 * substatements from this phase are available.
137 * Implementation may use method to perform actions on this event or
138 * register modification action using
139 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
142 * Context of added statement. Argument and statement parent is
144 * @throws SourceException
145 * when an inconsistency is detected.
147 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
150 * Invoked when statement is closed during
151 * {@link ModelProcessingPhase#FULL_DECLARATION} phase.
153 * Invoked when statement is closed during
154 * {@link ModelProcessingPhase#FULL_DECLARATION} phase, only substatements
155 * from this phase are available.
157 * Implementation may use method to perform actions on this event or
158 * register modification action using
159 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
163 * Context of added statement. Argument and statement parent is
165 * @throws SourceException
166 * when an inconsistency is detected.
168 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
171 * Returns true if this support has argument specific supports.
173 boolean hasArgumentSpecificSupports();
176 * If this support has argument specific supports, the method returns
177 * support specific for given argument (e.g. type statement support need to
178 * be specialized based on its argument), otherwise returns null.
181 * argument of statement
182 * @return statement support specific for supplied argument or null
185 StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);
188 * Given a raw string representation of an argument, try to use a shared representation
192 * @return A potentially-shard instance
194 default String internArgument(final String rawArgument) {
199 * Returns unknown statement form of a regular yang statement supplied as
200 * parameter to the method.
203 * statement definition of a regular yang statement
204 * @return Optional of unknown statement form of a regular yang statement or
205 * Optional.empty() if it is not supported by this statement support
207 default Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(final StatementDefinition yangStmtDef) {
208 return Optional.empty();
212 * Returns true if this statement support and all its substatements ignore
213 * if-feature statements (e.g. yang-data extension defined in
214 * https://tools.ietf.org/html/rfc8040#section-8). Default implementation
217 * @return true if this statement support ignores if-feature statements,
221 default boolean isIgnoringIfFeatures() {
226 * Returns true if this statement support and all its substatements ignore
227 * config statements (e.g. yang-data extension defined in
228 * https://tools.ietf.org/html/rfc8040#section-8). Default implementation
231 * @return true if this statement support ignores config statements,
235 default boolean isIgnoringConfig() {