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 java.util.Optional;
12 import javax.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementDefinitionContext;
24 * Support for processing concrete YANG statement.
26 * This interface is intended to be implemented by developers, which want to
27 * introduce support of statement to parser. Consider subclassing
28 * {@link AbstractStatementSupport} for easier implementation of this interface.
33 * Declared Statement representation
35 * Effective Statement representation
37 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
38 StatementDefinition, StatementFactory<A, D, E> {
41 * Returns public statement definition, which will be present in built
44 * Public statement definition may be used to provide different
45 * implementation of statement definition, which will not retain any build
46 * specific data or context.
48 * @return public statement definition, which will be present in built
51 StatementDefinition getPublicView();
55 * Parses textual representation of argument in object representation.
58 * Context, which may be used to access source-specific
59 * namespaces required for parsing.
61 * String representation of value, as was present in text source.
62 * @return Parsed value
63 * @throws SourceException when an inconsistency is detected.
65 A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value);
68 * Invoked when a statement supported by this instance is added to build context. This allows implementations
69 * of this interface to start tracking the statement and perform any modifications to the build context hierarchy,
70 * accessible via {@link StmtContext#getParentContext()}. One such use is populating the parent's namespaces to
71 * allow it to locate this child statement.
74 * Context of added statement. No substatements are available.
76 void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
79 * Invoked before a substatement with specified offset, definition,
80 * reference and argument is created and added to parent statement. This
81 * allows implementations of this interface perform any modifications to the
82 * build context hierarchy before a substatement is created. One such use is
83 * creating an implicit statement.
86 * Context of parent statement where a new substatement should be
87 * created. No substatements are available.
95 * substatement argument
96 * @return optional of an implicit substatement
98 Optional<StatementContextBase<?, ?, ?>> beforeSubStatementCreated(final Mutable<?, ?, ?> stmt, final int offset,
99 final StatementDefinitionContext<?, ?, ?> def, final StatementSourceReference ref, final String argument);
102 * Invoked when statement is closed during
103 * {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements
104 * from this and previous phase are available.
106 * Implementation may use method to perform actions on this event or
107 * register modification action using
108 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
111 * Context of added statement.
113 void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
116 * Invoked when statement is closed during
117 * {@link ModelProcessingPhase#SOURCE_LINKAGE} phase, only substatements
118 * from this and previous phase are available.
120 * Implementation may use method to perform actions on this event or
121 * register modification action using
122 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
125 * Context of added statement.
126 * @throws SourceException when an inconsistency is detected.
128 void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt);
131 * Invoked when statement is closed during
132 * {@link ModelProcessingPhase#STATEMENT_DEFINITION} phase, only
133 * substatements from this phase are available.
135 * Implementation may use method to perform actions on this event or
136 * register modification action using
137 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
140 * Context of added statement. Argument and statement parent is
142 * @throws SourceException when an inconsistency is detected.
144 void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
147 * Invoked when statement is closed during
148 * {@link ModelProcessingPhase#FULL_DECLARATION} phase.
150 * Invoked when statement is closed during
151 * {@link ModelProcessingPhase#FULL_DECLARATION} phase, only substatements
152 * from this phase are available.
154 * Implementation may use method to perform actions on this event or
155 * register modification action using
156 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
160 * Context of added statement. Argument and statement parent is
162 * @throws SourceException when an inconsistency is detected.
164 void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt);
167 * Returns true if this support has argument specific supports.
169 boolean hasArgumentSpecificSupports();
172 * If this support has argument specific supports, the method returns
173 * support specific for given argument (e.g. type statement support need to
174 * be specialized based on its argument), otherwise returns null.
177 * argument of statement
178 * @return statement support specific for supplied argument or null
181 StatementSupport<?, ?, ?> getSupportSpecificForArgument(String argument);