2f81c12c323094ee9033cafa57d547bac579020f
[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 org.eclipse.jdt.annotation.NonNull;
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.StatementNamespace;
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     ReactorStmtCtx<A, D, E> unmodifiedEffectiveSource() {
54         return source.unmodifiedEffectiveSource();
55     }
56
57     @Override
58     public EffectiveConfig effectiveConfig() {
59         return source.effectiveConfig();
60     }
61
62     @Override
63     public D declared() {
64         return source.declared();
65     }
66
67     @Override
68     public A argument() {
69         return source.argument();
70     }
71
72     @Override
73     public StatementSourceReference sourceReference() {
74         return source.sourceReference();
75     }
76
77     @Override
78     public String rawArgument() {
79         return source.rawArgument();
80     }
81
82     @Override
83     public Optional<StmtContext<A, D, E>> getOriginalCtx() {
84         return source.getOriginalCtx();
85     }
86
87     @Override
88     public Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements() {
89         return source.mutableDeclaredSubstatements();
90     }
91
92     @Override
93     public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
94         return source.mutableEffectiveSubstatements();
95     }
96
97     @Override
98     byte executionOrder() {
99         return source.executionOrder();
100     }
101
102     @Override
103     public CopyHistory history() {
104         return source.history();
105     }
106
107     @Override
108     public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
109         return List.of();
110     }
111
112     @Override
113     ReplicaStatementContext<A, D, E> replicaAsChildOf(final StatementContextBase<?, ?, ?> newParent) {
114         return source.replicaAsChildOf(newParent);
115     }
116
117     @Override
118     public Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(final Mutable<?, ?, ?> newParent, final CopyType type,
119             final QNameModule targetModule) {
120         return source.copyAsChildOf(newParent, type, targetModule);
121     }
122
123     @Override
124     ReactorStmtCtx<?, ?, ?> asEffectiveChildOf(final StatementContextBase<?, ?, ?> newParent, final CopyType type,
125             final QNameModule targetModule) {
126         final ReactorStmtCtx<?, ?, ?> ret = source.asEffectiveChildOf(newParent, type, targetModule);
127         return ret == null ? null : this;
128     }
129
130     @Override
131     StatementDefinitionContext<A, D, E> definition() {
132         return source.definition();
133     }
134
135     @Override
136     void markNoParentRef() {
137         // No-op
138     }
139
140     @Override
141     int sweepSubstatements() {
142         if (haveSourceReference()) {
143             source.decRef();
144         }
145         return 0;
146     }
147
148     @Override
149     public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final Class<@NonNull N> type,
150             final T key, final U value) {
151         throw new UnsupportedOperationException();
152     }
153
154     @Override
155     public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
156         throw new UnsupportedOperationException();
157     }
158
159     @Override
160     public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final Class<@NonNull N> namespace,
161             final KT key, final StmtContext<?, ?, ?> stmt) {
162         throw new UnsupportedOperationException();
163     }
164
165     @Override
166     public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
167         throw new UnsupportedOperationException();
168     }
169
170     @Override
171     public Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
172             final QNameModule targetModule) {
173         throw new UnsupportedOperationException();
174     }
175
176     @Override
177     boolean doTryToCompletePhase(final byte executionOrder) {
178         throw new UnsupportedOperationException();
179     }
180
181     @Override
182     public <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>>
183             Mutable<X, Y, Z> addEffectiveSubstatement(final StatementSupport<X, Y, Z> support, final X arg) {
184         throw new UnsupportedOperationException();
185     }
186
187     @Override
188     public void addEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
189         throw new UnsupportedOperationException();
190     }
191
192     @Override
193     public void addEffectiveSubstatements(final Collection<? extends Mutable<?, ?, ?>> statements) {
194         throw new UnsupportedOperationException();
195     }
196
197     @Override
198     public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef) {
199         throw new UnsupportedOperationException();
200     }
201
202     @Override
203     public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef,
204             final String statementArg) {
205         throw new UnsupportedOperationException();
206     }
207
208     @Override
209     public boolean hasImplicitParentSupport() {
210         throw new UnsupportedOperationException();
211     }
212
213     @Override
214     public StmtContext<?, ?, ?> wrapWithImplicit(final StmtContext<?, ?, ?> original) {
215         throw new UnsupportedOperationException();
216     }
217
218     /*
219      * KEEP THINGS ORGANIZED!
220      *
221      * below methods exist in the same form in InferredStatementContext/SubstatementContext. If any adjustment is made
222      * here, make sure it is properly updated there.
223      */
224     @Override
225     public StatementContextBase<?, ?, ?> getParentContext() {
226         return parent;
227     }
228
229     @Override
230     public StorageNodeType getStorageNodeType() {
231         return StorageNodeType.STATEMENT_LOCAL;
232     }
233
234     @Override
235     public StatementContextBase<?, ?, ?> getParentNamespaceStorage() {
236         return parent;
237     }
238
239     @Override
240     public RootStatementContext<?, ?, ?> getRoot() {
241         return parent.getRoot();
242     }
243
244     @Override
245     protected boolean isIgnoringIfFeatures() {
246         return isIgnoringIfFeatures(parent);
247     }
248
249     @Override
250     protected boolean isIgnoringConfig() {
251         return isIgnoringConfig(parent);
252     }
253
254     @Override
255     protected boolean isParentSupportedByFeatures() {
256         return parent.isSupportedByFeatures();
257     }
258 }