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 java.util.stream.Stream;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 import org.opendaylight.yangtools.yang.model.api.meta.StatementSourceReference;
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.ParserNamespace;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementFactory;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
29 * A replica of a different statement. It does not allow modification, but produces an effective statement from a
32 final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
33 extends ReactorStmtCtx<A, D, E> {
34 private final StatementContextBase<?, ?, ?> parent;
35 private final ReactorStmtCtx<A, D, E> source;
36 // We need to drop source's reference count when we are being swept.
37 private final boolean haveSourceRef;
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()) {
47 haveSourceRef = false;
53 return source.buildEffective();
57 E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx,
58 final Stream<? extends ReactorStmtCtx<?, ?, ?>> declared,
59 final Stream<? extends ReactorStmtCtx<?, ?, ?>> effective) {
60 return source.createInferredEffective(factory, ctx, declared, effective);
64 ReactorStmtCtx<A, D, E> unmodifiedEffectiveSource() {
65 return source.unmodifiedEffectiveSource();
69 public EffectiveConfig effectiveConfig() {
70 return source.effectiveConfig();
75 return source.declared();
80 return source.argument();
84 public StatementSourceReference sourceReference() {
85 return source.sourceReference();
89 public String rawArgument() {
90 return source.rawArgument();
94 public Optional<StmtContext<A, D, E>> getOriginalCtx() {
95 return source.getOriginalCtx();
99 public Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements() {
100 return source.mutableDeclaredSubstatements();
104 public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
105 return source.mutableEffectiveSubstatements();
109 byte executionOrder() {
110 return source.executionOrder();
114 public CopyHistory history() {
115 return source.history();
119 public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
124 ReplicaStatementContext<A, D, E> replicaAsChildOf(final StatementContextBase<?, ?, ?> newParent) {
125 return source.replicaAsChildOf(newParent);
129 public Optional<Mutable<A, D, E>> copyAsChildOf(final Mutable<?, ?, ?> newParent, final CopyType type,
130 final QNameModule targetModule) {
131 return source.copyAsChildOf(newParent, type, targetModule);
135 ReactorStmtCtx<?, ?, ?> asEffectiveChildOf(final StatementContextBase<?, ?, ?> newParent, final CopyType type,
136 final QNameModule targetModule) {
137 final ReactorStmtCtx<?, ?, ?> ret = source.asEffectiveChildOf(newParent, type, targetModule);
138 return ret == null ? null : this;
142 StatementDefinitionContext<A, D, E> definition() {
143 return source.definition();
147 void markNoParentRef() {
152 int sweepSubstatements() {
161 public <K, V> void addToNs(final ParserNamespace<K, V> type, final K key, final V value) {
162 throw new UnsupportedOperationException();
167 public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
168 throw new UnsupportedOperationException();
173 public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
174 throw new UnsupportedOperationException();
179 public Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
180 final QNameModule targetModule) {
181 throw new UnsupportedOperationException();
186 boolean doTryToCompletePhase(final byte executionOrder) {
187 throw new UnsupportedOperationException();
192 public <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>>
193 Mutable<X, Y, Z> createUndeclaredSubstatement(final StatementSupport<X, Y, Z> support, final X arg) {
194 throw new UnsupportedOperationException();
199 public void addEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
200 throw new UnsupportedOperationException();
205 public void addEffectiveSubstatements(final Collection<? extends Mutable<?, ?, ?>> statements) {
206 throw new UnsupportedOperationException();
211 public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef) {
212 throw new UnsupportedOperationException();
217 public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef,
218 final String statementArg) {
219 throw new UnsupportedOperationException();
224 public boolean hasImplicitParentSupport() {
225 throw new UnsupportedOperationException();
230 public StmtContext<?, ?, ?> wrapWithImplicit(final StmtContext<?, ?, ?> original) {
231 throw new UnsupportedOperationException();
235 * KEEP THINGS ORGANIZED!
237 * below methods exist in the same form in InferredStatementContext/SubstatementContext. If any adjustment is made
238 * here, make sure it is properly updated there.
241 public StatementContextBase<?, ?, ?> getParentContext() {
246 public StatementContextBase<?, ?, ?> getParentStorage() {
251 public RootStatementContext<?, ?, ?> getRoot() {
252 return parent.getRoot();
256 protected boolean isIgnoringIfFeatures() {
257 return isIgnoringIfFeatures(parent);
261 protected boolean isIgnoringConfig() {
262 return isIgnoringConfig(parent);
266 boolean computeSupportedByFeatures() {
267 return source.isSupportedByFeatures();
271 protected boolean isParentSupportedByFeatures() {
272 return parent.isSupportedByFeatures();