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 // FIXME: 3.0.0: do not extends ImplicitParentAwareStatementSupport
36 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
37 extends StatementDefinition, StatementFactory<A, D, E>, ImplicitParentAwareStatementSupport {
40 * Returns public statement definition, which will be present in built statements.
43 * Public statement definition may be used to provide different implementation of statement definition,
44 * which will not retain any build 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);
90 // FIXME: 3.0.0: remove this default method
92 default Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
93 return Optional.empty();
97 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
98 * from this and previous phase are available.
101 * Implementation may use method to perform actions on this event or register modification action using
102 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
105 * Context of added statement.
107 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
110 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
111 * from this and previous phase are available.
114 * Implementation may use method to perform actions on this event or register modification action using
115 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
118 * Context of added statement.
119 * @throws SourceException
120 * when an inconsistency is detected.
122 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
125 * Invoked when statement is closed during {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase,
126 * only substatements from this phase are available.
129 * Implementation may use method to perform actions on this event or register modification action using
130 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
133 * Context of added statement. Argument and statement parent is
135 * @throws SourceException
136 * when an inconsistency is detected.
138 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
141 * Invoked when statement is closed during {@link ModelProcessingPhase#FULL_DECLARATION} phase,
142 * only substatements from this phase are available.
145 * Implementation may use method to perform actions on this event or register modification action using
146 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
149 * Context of added statement. Argument and statement parent is
151 * @throws SourceException
152 * when an inconsistency is detected.
154 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
157 * Returns true if this support has argument specific supports.
159 boolean hasArgumentSpecificSupports();
162 * If this support has argument specific supports, the method returns support specific for given argument
163 * (e.g. type statement support need to be specialized based on its argument), otherwise returns null.
166 * argument of statement
167 * @return statement support specific for supplied argument or null
170 StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);
173 * Given a raw string representation of an argument, try to use a shared representation.
177 * @return A potentially-shard instance
179 default String internArgument(final String rawArgument) {
184 * Returns unknown statement form of a regular YANG statement supplied as a parameter to the method.
187 * statement definition of a regular yang statement
188 * @return Optional of unknown statement form of a regular yang statement or
189 * Optional.empty() if it is not supported by this statement support
191 default Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(final StatementDefinition yangStmtDef) {
192 return Optional.empty();
196 * Returns true if this statement support and all its substatements ignore if-feature statements (e.g. yang-data
197 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
198 * implementation returns false.
200 * @return true if this statement support ignores if-feature statements,
204 default boolean isIgnoringIfFeatures() {
209 * Returns true if this statement support and all its substatements ignore config statements (e.g. yang-data
210 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
211 * implementation returns false.
213 * @return true if this statement support ignores config statements,
217 default boolean isIgnoringConfig() {