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.SubstatementValidator;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementDefinitionContext;
25 * Class providing necessary support for processing YANG statement.
27 * This class is intended to be subclassed by developers, which want to
28 * introduce support of statement to parser.
33 * Declared Statement representation
35 * Effective Statement representation
37 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
38 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
40 private final StatementDefinition type;
42 protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
43 Preconditions.checkArgument(publicDefinition != this);
44 this.type = Preconditions.checkNotNull(publicDefinition);
49 public final QName getStatementName() {
50 return type.getStatementName();
54 public final QName getArgumentName() {
55 return type.getArgumentName();
60 public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
61 return type.getDeclaredRepresentationClass();
66 public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
67 return type.getEffectiveRepresentationClass();
71 public final StatementDefinition getPublicView() {
76 public Optional<StatementContextBase<?, ?, ?>> beforeSubStatementCreated(final StmtContext.Mutable<?, ?, ?> stmt,
77 final int offset, final StatementDefinitionContext<?, ?, ?> def, final StatementSourceReference ref,
78 final String argument) {
79 // NOOP for most implementations and also no implicit statements
80 return Optional.empty();
84 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
85 // NOOP for most implementations
91 * Subclasses of this class may override this method to perform actions on
92 * this event or register modification action using
93 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
96 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
97 // NOOP for most implementations
103 * Subclasses of this class may override this method to perform actions on
104 * this event or register modification action using
105 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
108 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
109 // NOOP for most implementations
115 * Subclasses of this class may override this method to perform actions on
116 * this event or register modification action using
117 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
120 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
121 // NOOP for most implementations
127 * Subclasses of this class may override this method to perform actions on
128 * this event or register modification action using
129 * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
132 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
133 final SubstatementValidator validator = getSubstatementValidator();
134 if (validator != null) {
135 validator.validate(stmt);
140 public boolean isArgumentYinElement() {
141 return getPublicView().isArgumentYinElement();
145 * Returns corresponding substatement validator of a statement support
147 * @return substatement validator or null, if substatement validator is not
151 protected abstract SubstatementValidator getSubstatementValidator();