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;
23 * Class providing necessary support for processing a YANG statement.
25 * This class is intended to be subclassed by developers, who want to
26 * introduce support of statement to parser.
31 * Declared Statement representation
33 * Effective Statement representation
35 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
36 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
38 private final StatementDefinition type;
40 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
41 Preconditions.checkArgument(publicDefinition != this);
42 this.type = Preconditions.checkNotNull(publicDefinition);
47 public final QName getStatementName() {
48 return type.getStatementName();
52 public final QName getArgumentName() {
53 return type.getArgumentName();
58 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
59 return type.getDeclaredRepresentationClass();
64 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
65 return type.getEffectiveRepresentationClass();
69 public final StatementDefinition getPublicView() {
74 public Optional<StatementContextBase<?, ?, ?>> beforeSubStatementCreated(final StmtContext.Mutable<?, ?, ?> stmt,
75 final int offset, final StatementDefinitionContext<?, ?, ?> def, final StatementSourceReference ref,
76 final String argument) {
77 // NOOP for most implementations and also no implicit statements
78 return Optional.empty();
82 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
83 // NOOP for most implementations
89 * Subclasses of this class may override this method to perform actions on
90 * this event or register modification action using
91 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
94 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
95 // NOOP for most implementations
101 * Subclasses of this class may override this method to perform actions on
102 * this event or register modification action using
103 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
106 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
107 // NOOP for most implementations
113 * Subclasses of this class may override this method to perform actions on
114 * this event or register modification action using
115 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
118 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
119 // NOOP for most implementations
125 * Subclasses of this class may override this method to perform actions on
126 * this event or register modification action using
127 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
130 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
131 final SubstatementValidator validator = getSubstatementValidator();
132 if (validator != null) {
133 validator.validate(stmt);
138 public boolean isArgumentYinElement() {
139 return getPublicView().isArgumentYinElement();
143 public boolean hasArgumentSpecificSupports() {
144 // Most of statement supports don't have any argument specific
145 // supports, so return 'false'.
150 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
151 // Most of statement supports don't have any argument specific
152 // supports, so return null.
157 * Returns corresponding substatement validator of a statement support
159 * @return substatement validator or null, if substatement validator is not
163 protected abstract SubstatementValidator getSubstatementValidator();