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 com.google.common.base.Verify.verify;
11 import static java.util.Objects.requireNonNull;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Optional;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
31 * A replica of a different statement. It does not allow modification, but produces an effective statement from a
34 final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
35 extends ReactorStmtCtx<A, D, E> {
36 private final StatementContextBase<?, ?, ?> parent;
37 private final ReactorStmtCtx<A, D, E> source;
39 ReplicaStatementContext(final StatementContextBase<?, ?, ?> parent, final ReactorStmtCtx<A, D, E> source) {
41 this.parent = requireNonNull(parent);
42 this.source = requireNonNull(source);
43 if (source.isSupportedToBuildEffective()) {
44 verify(source.fullyDefined(), "Source %s is not fully defined", 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 public Mutable<A, D, E> replicaAsChildOf(final Mutable<?, ?, ?> 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 return source.asEffectiveChildOf(newParent, type, targetModule);
127 StatementDefinitionContext<A, D, E> definition() {
128 return source.definition();
132 void markNoParentRef() {
137 int sweepSubstatements() {
138 if (fullyDefined()) {
145 public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final Class<@NonNull N> type,
146 final T key, final U value) {
147 throw new UnsupportedOperationException();
151 public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
152 throw new UnsupportedOperationException();
156 public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final Class<@NonNull N> namespace,
157 final KT key, final StmtContext<?, ?, ?> stmt) {
158 throw new UnsupportedOperationException();
162 public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
163 throw new UnsupportedOperationException();
167 public Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
168 final QNameModule targetModule) {
169 throw new UnsupportedOperationException();
172 @Override boolean doTryToCompletePhase(final ModelProcessingPhase phase) {
173 throw new UnsupportedOperationException();
177 * KEEP THINGS ORGANIZED!
179 * below methods exist in the same form in InferredStatementContext/SubstatementContext. If any adjustment is made
180 * here, make sure it is properly updated there.
184 public Optional<SchemaPath> schemaPath() {
185 return substatementGetSchemaPath();
189 public StatementContextBase<?, ?, ?> getParentContext() {
194 public StorageNodeType getStorageNodeType() {
195 return StorageNodeType.STATEMENT_LOCAL;
199 public StatementContextBase<?, ?, ?> getParentNamespaceStorage() {
204 public RootStatementContext<?, ?, ?> getRoot() {
205 return parent.getRoot();
209 protected boolean isIgnoringIfFeatures() {
210 return isIgnoringIfFeatures(parent);
214 protected boolean isIgnoringConfig() {
215 return isIgnoringConfig(parent);
219 protected boolean isParentSupportedByFeatures() {
220 return parent.isSupportedByFeatures();