Seal PathArgumentList
[yangtools.git] / parser / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / ReplicaStatementContext.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
9
10 import static java.util.Objects.requireNonNull;
11
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.parser.spi.meta.CopyHistory;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
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;
27 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
28
29 /**
30  * A replica of a different statement. It does not allow modification, but produces an effective statement from a
31  * designated source.
32  */
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;
37
38     ReplicaStatementContext(final StatementContextBase<?, ?, ?> parent, final ReactorStmtCtx<A, D, E> source) {
39         super(source, null);
40         this.parent = requireNonNull(parent);
41         this.source = requireNonNull(source);
42         if (source.isSupportedToBuildEffective()) {
43             source.incRef();
44         }
45     }
46
47     @Override
48     E createEffective() {
49         return source.buildEffective();
50     }
51
52     @Override
53     E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx,
54             final Stream<? extends StmtContext<?, ?, ?>> declared,
55             final Stream<? extends StmtContext<?, ?, ?>> effective) {
56         return source.createInferredEffective(factory, ctx, declared, effective);
57     }
58
59     @Override
60     ReactorStmtCtx<A, D, E> unmodifiedEffectiveSource() {
61         return source.unmodifiedEffectiveSource();
62     }
63
64     @Override
65     public EffectiveConfig effectiveConfig() {
66         return source.effectiveConfig();
67     }
68
69     @Override
70     public D declared() {
71         return source.declared();
72     }
73
74     @Override
75     public A argument() {
76         return source.argument();
77     }
78
79     @Override
80     public StatementSourceReference sourceReference() {
81         return source.sourceReference();
82     }
83
84     @Override
85     public String rawArgument() {
86         return source.rawArgument();
87     }
88
89     @Override
90     public Optional<StmtContext<A, D, E>> getOriginalCtx() {
91         return source.getOriginalCtx();
92     }
93
94     @Override
95     public Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements() {
96         return source.mutableDeclaredSubstatements();
97     }
98
99     @Override
100     public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
101         return source.mutableEffectiveSubstatements();
102     }
103
104     @Override
105     byte executionOrder() {
106         return source.executionOrder();
107     }
108
109     @Override
110     public CopyHistory history() {
111         return source.history();
112     }
113
114     @Override
115     public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
116         return List.of();
117     }
118
119     @Override
120     ReplicaStatementContext<A, D, E> replicaAsChildOf(final StatementContextBase<?, ?, ?> newParent) {
121         return source.replicaAsChildOf(newParent);
122     }
123
124     @Override
125     public Optional<Mutable<A, D, E>> copyAsChildOf(final Mutable<?, ?, ?> newParent, final CopyType type,
126             final QNameModule targetModule) {
127         return source.copyAsChildOf(newParent, type, targetModule);
128     }
129
130     @Override
131     ReactorStmtCtx<?, ?, ?> asEffectiveChildOf(final StatementContextBase<?, ?, ?> newParent, final CopyType type,
132             final QNameModule targetModule) {
133         final ReactorStmtCtx<?, ?, ?> ret = source.asEffectiveChildOf(newParent, type, targetModule);
134         return ret == null ? null : this;
135     }
136
137     @Override
138     StatementDefinitionContext<A, D, E> definition() {
139         return source.definition();
140     }
141
142     @Override
143     void markNoParentRef() {
144         // No-op
145     }
146
147     @Override
148     int sweepSubstatements() {
149         if (haveSourceReference()) {
150             source.decRef();
151         }
152         return 0;
153     }
154
155     @Override
156     @Deprecated
157     public <K, V, T extends K, U extends V> void addToNs(final ParserNamespace<K, V> type, final T key, final U value) {
158         throw new UnsupportedOperationException();
159     }
160
161     @Override
162     @Deprecated
163     public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
164         throw new UnsupportedOperationException();
165     }
166
167     @Override
168     @Deprecated
169     public <K, KT extends K, C extends StmtContext<?, ?, ?>> void addContext(
170             final ParserNamespace<K, ? super C> namespace, final KT key, final C stmt) {
171         throw new UnsupportedOperationException();
172     }
173
174     @Override
175     @Deprecated
176     public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
177         throw new UnsupportedOperationException();
178     }
179
180     @Override
181     @Deprecated
182     public Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
183             final QNameModule targetModule) {
184         throw new UnsupportedOperationException();
185     }
186
187     @Override
188     @Deprecated
189     boolean doTryToCompletePhase(final byte executionOrder) {
190         throw new UnsupportedOperationException();
191     }
192
193     @Override
194     @Deprecated
195     public <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>>
196             Mutable<X, Y, Z> createUndeclaredSubstatement(final StatementSupport<X, Y, Z> support, final X arg) {
197         throw new UnsupportedOperationException();
198     }
199
200     @Override
201     @Deprecated
202     public void addEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
203         throw new UnsupportedOperationException();
204     }
205
206     @Override
207     @Deprecated
208     public void addEffectiveSubstatements(final Collection<? extends Mutable<?, ?, ?>> statements) {
209         throw new UnsupportedOperationException();
210     }
211
212     @Override
213     @Deprecated
214     public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef) {
215         throw new UnsupportedOperationException();
216     }
217
218     @Override
219     @Deprecated
220     public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef,
221             final String statementArg) {
222         throw new UnsupportedOperationException();
223     }
224
225     @Override
226     @Deprecated
227     public boolean hasImplicitParentSupport() {
228         throw new UnsupportedOperationException();
229     }
230
231     @Override
232     @Deprecated
233     public StmtContext<?, ?, ?> wrapWithImplicit(final StmtContext<?, ?, ?> original) {
234         throw new UnsupportedOperationException();
235     }
236
237     /*
238      * KEEP THINGS ORGANIZED!
239      *
240      * below methods exist in the same form in InferredStatementContext/SubstatementContext. If any adjustment is made
241      * here, make sure it is properly updated there.
242      */
243     @Override
244     public StatementContextBase<?, ?, ?> getParentContext() {
245         return parent;
246     }
247
248     @Override
249     public StorageNodeType getStorageNodeType() {
250         return StorageNodeType.STATEMENT_LOCAL;
251     }
252
253     @Override
254     public StatementContextBase<?, ?, ?> getParentNamespaceStorage() {
255         return parent;
256     }
257
258     @Override
259     public RootStatementContext<?, ?, ?> getRoot() {
260         return parent.getRoot();
261     }
262
263     @Override
264     protected boolean isIgnoringIfFeatures() {
265         return isIgnoringIfFeatures(parent);
266     }
267
268     @Override
269     protected boolean isIgnoringConfig() {
270         return isIgnoringConfig(parent);
271     }
272
273     @Override
274     protected boolean isParentSupportedByFeatures() {
275         return parent.isSupportedByFeatures();
276     }
277 }