2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.stmt.reactor;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Collection;
13 import java.util.List;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
30 * A replica of a different statement. It does not allow modification, but produces an effective statement from a
33 final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
34 extends ReactorStmtCtx<A, D, E> {
35 private final StatementContextBase<?, ?, ?> parent;
36 private final ReactorStmtCtx<A, D, E> source;
38 ReplicaStatementContext(final StatementContextBase<?, ?, ?> parent, final ReactorStmtCtx<A, D, E> source) {
40 this.parent = requireNonNull(parent);
41 this.source = requireNonNull(source);
42 if (source.isSupportedToBuildEffective()) {
44 // FIXME: is this call really needed? it is inherited from source
51 return source.buildEffective();
55 public EffectiveConfig effectiveConfig() {
56 return source.effectiveConfig();
61 return source.declared();
66 return source.argument();
70 public StatementSourceReference sourceReference() {
71 return source.sourceReference();
75 public String rawArgument() {
76 return source.rawArgument();
80 public Optional<StmtContext<A, D, E>> getOriginalCtx() {
81 return source.getOriginalCtx();
85 public Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements() {
86 return source.mutableDeclaredSubstatements();
90 public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
91 return source.mutableEffectiveSubstatements();
95 public ModelProcessingPhase getCompletedPhase() {
96 return source.getCompletedPhase();
100 public CopyHistory history() {
101 return source.history();
105 public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
110 ReplicaStatementContext<A, D, E> replicaAsChildOf(final StatementContextBase<?, ?, ?> newParent) {
111 return source.replicaAsChildOf(newParent);
115 public Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(final Mutable<?, ?, ?> newParent, final CopyType type,
116 final QNameModule targetModule) {
117 return source.copyAsChildOf(newParent, type, targetModule);
121 ReactorStmtCtx<?, ?, ?> asEffectiveChildOf(final StatementContextBase<?, ?, ?> newParent, final CopyType type,
122 final QNameModule targetModule) {
123 final ReactorStmtCtx<?, ?, ?> ret = source.asEffectiveChildOf(newParent, type, targetModule);
124 return ret == null ? null : this;
128 StatementDefinitionContext<A, D, E> definition() {
129 return source.definition();
133 void markNoParentRef() {
138 int sweepSubstatements() {
139 if (fullyDefined()) {
146 public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final Class<@NonNull N> type,
147 final T key, final U value) {
148 throw new UnsupportedOperationException();
152 public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
153 throw new UnsupportedOperationException();
157 public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final Class<@NonNull N> namespace,
158 final KT key, final StmtContext<?, ?, ?> stmt) {
159 throw new UnsupportedOperationException();
163 public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
164 throw new UnsupportedOperationException();
168 public Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
169 final QNameModule targetModule) {
170 throw new UnsupportedOperationException();
173 @Override boolean doTryToCompletePhase(final ModelProcessingPhase phase) {
174 throw new UnsupportedOperationException();
178 * KEEP THINGS ORGANIZED!
180 * below methods exist in the same form in InferredStatementContext/SubstatementContext. If any adjustment is made
181 * here, make sure it is properly updated there.
185 public SchemaPath schemaPath() {
186 return substatementGetSchemaPath();
190 public StatementContextBase<?, ?, ?> getParentContext() {
195 public StorageNodeType getStorageNodeType() {
196 return StorageNodeType.STATEMENT_LOCAL;
200 public StatementContextBase<?, ?, ?> getParentNamespaceStorage() {
205 public RootStatementContext<?, ?, ?> getRoot() {
206 return parent.getRoot();
210 protected boolean isIgnoringIfFeatures() {
211 return isIgnoringIfFeatures(parent);
215 protected boolean isIgnoringConfig() {
216 return isIgnoringConfig(parent);
220 protected boolean isParentSupportedByFeatures() {
221 return parent.isSupportedByFeatures();