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.base.Preconditions;
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
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.StatementSourceReference;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementDefinitionContext;
24 * Class providing necessary support for processing YANG statement.
26 * This class is intended to be subclassed by developers, which want to
27 * introduce support of statement to parser.
32 * Declared Statement representation
34 * Effective Statement representation
36 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
37 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
39 private final StatementDefinition type;
41 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
42 Preconditions.checkArgument(publicDefinition != this);
43 this.type = Preconditions.checkNotNull(publicDefinition);
48 public final QName getStatementName() {
49 return type.getStatementName();
53 public final QName getArgumentName() {
54 return type.getArgumentName();
59 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
60 return type.getDeclaredRepresentationClass();
65 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
66 return type.getEffectiveRepresentationClass();
70 public final StatementDefinition getPublicView() {
75 public Optional<StatementContextBase<?, ?, ?>> beforeSubStatementCreated(final StmtContext.Mutable<?, ?, ?> stmt,
76 final int offset, final StatementDefinitionContext<?, ?, ?> def, final StatementSourceReference ref,
77 final String argument) {
78 // NOOP for most implementations and also no implicit statements
79 return Optional.empty();
83 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
84 // NOOP for most implementations
90 * Subclasses of this class may override this method to perform actions on
91 * this event or register modification action using
92 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
95 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
96 // NOOP for most implementations
102 * Subclasses of this class may override this method to perform actions on
103 * this event or register modification action using
104 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
107 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
108 // NOOP for most implementations
114 * Subclasses of this class may override this method to perform actions on
115 * this event or register modification action using
116 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
119 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
120 // NOOP for most implementations
126 * Subclasses of this class may override this method to perform actions on
127 * this event or register modification action using
128 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
131 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
132 final SubstatementValidator validator = getSubstatementValidator();
133 if (validator != null) {
134 validator.validate(stmt);
139 public boolean isArgumentYinElement() {
140 return getPublicView().isArgumentYinElement();
144 public boolean hasArgumentSpecificSupports() {
145 // Most of statement supports don't have any argument specific
146 // supports, so return 'false'.
151 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
152 // Most of statement supports don't have any argument specific
153 // supports, so return null.
158 * Returns corresponding substatement validator of a statement support
160 * @return substatement validator or null, if substatement validator is not
164 protected abstract SubstatementValidator getSubstatementValidator();