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
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.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.ArgumentDefinition;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 * Support for processing concrete YANG statement.
26 * This interface is intended to be implemented by developers, which want to introduce support of statement to parser.
27 * Consider subclassing {@link AbstractStatementSupport} for easier implementation of this interface.
29 * @param <A> Argument type
30 * @param <D> Declared Statement representation
31 * @param <E> Effective Statement representation
33 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
34 extends StatementDefinition, StatementFactory<A, D, E> {
37 * Returns public statement definition, which will be present in built statements.
40 * Public statement definition may be used to provide different implementation of statement definition,
41 * which will not retain any build specific data or context.
43 * @return public statement definition, which will be present in built statements.
45 @NonNull StatementDefinition getPublicView();
48 * Parses textual representation of argument in object representation.
50 * @param ctx Context, which may be used to access source-specific namespaces required for parsing.
51 * @param value String representation of value, as was present in text source.
52 * @return Parsed value
53 * @throws SourceException when an inconsistency is detected.
55 A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value);
58 * Adapts the argument value to match a new module.
61 * Context, which may be used to access source-specific
62 * namespaces required for parsing.
64 * Target module, may not be null.
65 * @return Adapted argument value. The default implementation returns original value stored in context.
67 default A adaptArgumentValue(final StmtContext<A, D, E> ctx, final QNameModule targetModule) {
68 return ctx.getStatementArgument();
72 * Invoked when a statement supported by this instance is added to build context. This allows implementations
73 * of this interface to start tracking the statement and perform any modifications to the build context hierarchy,
74 * accessible via {@link StmtContext#getParentContext()}. One such use is populating the parent's namespaces to
75 * allow it to locate this child statement.
78 * Context of added statement. No substatements are available.
80 void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
83 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
84 * from this and previous phase are available.
87 * Implementation may use method to perform actions on this event or register modification action using
88 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
91 * Context of added statement.
93 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
96 * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
97 * from this and previous phase are available.
100 * Implementation may use method to perform actions on this event or register modification action using
101 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
104 * Context of added statement.
105 * @throws SourceException
106 * when an inconsistency is detected.
108 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
111 * Invoked when statement is closed during {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase,
112 * only substatements from this 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. Argument and statement parent is
121 * @throws SourceException
122 * when an inconsistency is detected.
124 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
127 * Invoked when statement is closed during {@link ModelProcessingPhase#FULL_DECLARATION} phase,
128 * only substatements from this phase are available.
131 * Implementation may use method to perform actions on this event or register modification action using
132 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
135 * Context of added statement. Argument and statement parent is
137 * @throws SourceException
138 * when an inconsistency is detected.
140 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
143 * Returns true if this support has argument specific supports.
145 boolean hasArgumentSpecificSupports();
148 * If this support has argument specific supports, the method returns support specific for given argument
149 * (e.g. type statement support need to be specialized based on its argument), otherwise returns null.
152 * argument of statement
153 * @return statement support specific for supplied argument or null
155 @Nullable StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);
158 * Given a raw string representation of an argument, try to use a shared representation.
162 * @return A potentially-shard instance
164 default String internArgument(final String rawArgument) {
169 * Returns unknown statement form of a regular YANG statement supplied as a parameter to the method.
172 * statement definition of a regular yang statement
173 * @return Optional of unknown statement form of a regular yang statement or
174 * Optional.empty() if it is not supported by this statement support
176 default Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(final StatementDefinition yangStmtDef) {
177 return Optional.empty();
181 * Returns true if this statement support and all its substatements ignore if-feature statements (e.g. yang-data
182 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
183 * implementation returns false.
185 * @return true if this statement support ignores if-feature statements,
189 default boolean isIgnoringIfFeatures() {
194 * Returns true if this statement support and all its substatements ignore config statements (e.g. yang-data
195 * extension defined in <a href="https://tools.ietf.org/html/rfc8040#section-8">RFC 8040</a>). Default
196 * implementation returns false.
198 * @return true if this statement support ignores config statements,
202 default boolean isIgnoringConfig() {
207 default QName getStatementName() {
208 return getPublicView().getStatementName();
212 default @NonNull Optional<ArgumentDefinition> getArgumentDefinition() {
213 return getPublicView().getArgumentDefinition();
217 default Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
218 return getPublicView().getDeclaredRepresentationClass();
222 default Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
223 return getPublicView().getEffectiveRepresentationClass();