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.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 * Support for processing concrete YANG statement.
25 * This interface is intended to be implemented by developers, which want to
26 * introduce support of statement to parser. Consider subclassing
27 * {@link AbstractStatementSupport} for easier implementation of this interface.
32 * Declared Statement representation
34 * Effective Statement representation
36 // FIXME: 3.0.0: do not extends ImplicitParentAwareStatementSupport
37 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
38 extends StatementDefinition, StatementFactory<A, D, E>, ImplicitParentAwareStatementSupport {
41 * Returns public statement definition, which will be present in built statements.
44 * Public statement definition may be used to provide different implementation of statement definition,
45 * which will not retain any build specific data or context.
47 * @return public statement definition, which will be present in built
50 StatementDefinition getPublicView();
53 * Parses textual representation of argument in object representation.
56 * Context, which may be used to access source-specific
57 * namespaces required for parsing.
59 * String representation of value, as was present in text source.
60 * @return Parsed value
61 * @throws SourceException
62 * when an inconsistency is detected.
64 A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value);
67 * Adapts the argument value to match a new module.
70 * Context, which may be used to access source-specific
71 * namespaces required for parsing.
73 * Target module, may not be null.
74 * @return Adapted argument value. The default implementation returns original value stored in context.
76 default A adaptArgumentValue(final StmtContext<A, D, E> ctx, final QNameModule targetModule) {
77 return ctx.getStatementArgument();
81 * Invoked when a statement supported by this instance is added to build context. This allows implementations
82 * of this interface to start tracking the statement and perform any modifications to the build context hierarchy,
83 * accessible via {@link StmtContext#getParentContext()}. One such use is populating the parent's namespaces to
84 * allow it to locate this child statement.
87 * Context of added statement. No substatements are available.
89 void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
91 // FIXME: 3.0.0: remove this default method
93 default Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
94 return Optional.empty();
98 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
99 * from this and previous phase are available.
102 * Implementation may use method to perform actions on this event or register modification action using
103 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
106 * Context of added statement.
108 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
111 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
112 * from this and previous phase are available.
115 * Implementation may use method to perform actions on this event or register modification action using
116 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
119 * Context of added statement.
120 * @throws SourceException
121 * when an inconsistency is detected.
123 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
126 * Invoked when statement is closed during {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase,
127 * only substatements from this phase are available.
130 * Implementation may use method to perform actions on this event or register modification action using
131 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
134 * Context of added statement. Argument and statement parent is
136 * @throws SourceException
137 * when an inconsistency is detected.
139 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
142 * Invoked when statement is closed during {@link ModelProcessingPhase#FULL_DECLARATION} phase,
143 * only substatements from this phase are available.
146 * Implementation may use method to perform actions on this event or register modification action using
147 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
150 * Context of added statement. Argument and statement parent is
152 * @throws SourceException
153 * when an inconsistency is detected.
155 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
158 * Returns true if this support has argument specific supports.
160 boolean hasArgumentSpecificSupports();
163 * If this support has argument specific supports, the method returns support specific for given argument
164 * (e.g. type statement support need to be specialized based on its argument), otherwise returns null.
167 * argument of statement
168 * @return statement support specific for supplied argument or null
171 StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);
174 * Given a raw string representation of an argument, try to use a shared representation.
178 * @return A potentially-shard instance
180 default String internArgument(final String rawArgument) {
185 * Returns unknown statement form of a regular YANG statement supplied as a parameter to the method.
188 * statement definition of a regular yang statement
189 * @return Optional of unknown statement form of a regular yang statement or
190 * Optional.empty() if it is not supported by this statement support
192 default Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(final StatementDefinition yangStmtDef) {
193 return Optional.empty();
197 * Returns true if this statement support and all its substatements ignore if-feature statements (e.g. yang-data
198 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
199 * implementation returns false.
201 * @return true if this statement support ignores if-feature statements,
205 default boolean isIgnoringIfFeatures() {
210 * Returns true if this statement support and all its substatements ignore config statements (e.g. yang-data
211 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
212 * implementation returns false.
214 * @return true if this statement support ignores config statements,
218 default boolean isIgnoringConfig() {
223 default QName getStatementName() {
224 return getPublicView().getStatementName();
228 default QName getArgumentName() {
229 return getPublicView().getArgumentName();
233 default Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
234 return getPublicView().getDeclaredRepresentationClass();
238 default Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
239 return getPublicView().getEffectiveRepresentationClass();
243 default boolean isArgumentYinElement() {
244 return getPublicView().isArgumentYinElement();