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 statements.
42 * Public statement definition may be used to provide different implementation of statement definition,
43 * which will not retain any build specific data or context.
45 * @return public statement definition, which will be present in built
48 StatementDefinition getPublicView();
51 * Parses textual representation of argument in object representation.
54 * Context, which may be used to access source-specific
55 * namespaces required for parsing.
57 * String representation of value, as was present in text source.
58 * @return Parsed value
59 * @throws SourceException
60 * when an inconsistency is detected.
62 A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value);
65 * Adapts the argument value to match a new module.
68 * Context, which may be used to access source-specific
69 * namespaces required for parsing.
71 * Target module, may not be null.
72 * @return Adapted argument value. The default implementation returns original value stored in context.
74 default A adaptArgumentValue(final StmtContext<A, D, E> ctx, final QNameModule targetModule) {
75 return ctx.getStatementArgument();
79 * Invoked when a statement supported by this instance is added to build context. This allows implementations
80 * of this interface to start tracking the statement and perform any modifications to the build context hierarchy,
81 * accessible via {@link StmtContext#getParentContext()}. One such use is populating the parent's namespaces to
82 * allow it to locate this child statement.
85 * Context of added statement. No substatements are available.
87 void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
90 * Returns implicit parent statement support for supplied statement definition, if it is defined. This allows
91 * implementations of this interface add implicit parent to the build context hierarchy before a substatement
95 * statement definition of substatement
96 * @return optional of implicit parent statement support
98 Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(StatementDefinition stmtDef);
101 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
102 * from this and previous phase are available.
105 * Implementation may use method to perform actions on this event or register modification action using
106 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
109 * Context of added statement.
111 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
114 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
115 * from this and previous phase are available.
118 * Implementation may use method to perform actions on this event or register modification action using
119 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
122 * Context of added statement.
123 * @throws SourceException
124 * when an inconsistency is detected.
126 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
129 * Invoked when statement is closed during {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase,
130 * only substatements from this phase are available.
133 * Implementation may use method to perform actions on this event or register modification action using
134 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
137 * Context of added statement. Argument and statement parent is
139 * @throws SourceException
140 * when an inconsistency is detected.
142 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
145 * Invoked when statement is closed during {@link ModelProcessingPhase#FULL_DECLARATION} phase,
146 * only substatements from this phase are available.
149 * Implementation may use method to perform actions on this event or register modification action using
150 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
153 * Context of added statement. Argument and statement parent is
155 * @throws SourceException
156 * when an inconsistency is detected.
158 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
161 * Returns true if this support has argument specific supports.
163 boolean hasArgumentSpecificSupports();
166 * If this support has argument specific supports, the method returns support specific for given argument
167 * (e.g. type statement support need to be specialized based on its argument), otherwise returns null.
170 * argument of statement
171 * @return statement support specific for supplied argument or null
174 StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);
177 * Given a raw string representation of an argument, try to use a shared representation.
181 * @return A potentially-shard instance
183 default String internArgument(final String rawArgument) {
188 * Returns unknown statement form of a regular YANG statement supplied as a parameter to the method.
191 * statement definition of a regular yang statement
192 * @return Optional of unknown statement form of a regular yang statement or
193 * Optional.empty() if it is not supported by this statement support
195 default Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(final StatementDefinition yangStmtDef) {
196 return Optional.empty();
200 * Returns true if this statement support and all its substatements ignore if-feature statements (e.g. yang-data
201 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
202 * implementation returns false.
204 * @return true if this statement support ignores if-feature statements,
208 default boolean isIgnoringIfFeatures() {
213 * Returns true if this statement support and all its substatements ignore config statements (e.g. yang-data
214 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
215 * implementation returns false.
217 * @return true if this statement support ignores config statements,
221 default boolean isIgnoringConfig() {