Rename StatementSource to StatementOrigin
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / meta / AbstractImplicitStatementSupport.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.rfc7950.stmt.meta;
9
10 import com.google.common.collect.ImmutableList;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
20
21 /**
22  * A massively-misnamed superclass for statements which are both schema tree participants and can be created as implicit
23  * nodes. This covers {@code case}, {@code input} and {@code output} statements.
24  *
25  * @param <D> Declared Statement representation
26  * @param <E> Effective Statement representation
27  */
28 abstract class AbstractImplicitStatementSupport<D extends DeclaredStatement<QName>,
29         E extends SchemaTreeEffectiveStatement<D>> extends AbstractSchemaTreeStatementSupport<D, E> {
30     AbstractImplicitStatementSupport(final StatementDefinition publicDefinition,
31             final StatementPolicy<QName, D> policy) {
32         super(publicDefinition, policy);
33     }
34
35     @Override
36     public final E copyEffective(final Current<QName, D> stmt, final E original) {
37         final StatementOrigin source = stmt.origin();
38         switch (source) {
39             case CONTEXT:
40                 return copyUndeclaredEffective(stmt, original);
41             case DECLARATION:
42                 return copyDeclaredEffective(stmt, original);
43             default:
44                 throw new IllegalStateException("Unhandled statement source " + source);
45         }
46     }
47
48     @Override
49     protected E createEffective(final Current<QName, D> stmt,
50             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
51         final StatementOrigin origin = stmt.origin();
52         switch (origin) {
53             case CONTEXT:
54                 return createUndeclaredEffective(stmt, substatements);
55             case DECLARATION:
56                 return createDeclaredEffective(stmt, substatements);
57             default:
58                 throw new IllegalStateException("Unhandled statement origin " + origin);
59         }
60     }
61
62     abstract @NonNull E copyDeclaredEffective(@NonNull Current<QName, D> stmt, @NonNull E original);
63
64     abstract @NonNull E copyUndeclaredEffective(@NonNull Current<QName, D> stmt, @NonNull E original);
65
66     abstract @NonNull E createDeclaredEffective(@NonNull Current<QName, D> stmt,
67             @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
68
69     abstract @NonNull E createUndeclaredEffective(@NonNull Current<QName, D> stmt,
70             @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
71 }