Introduce NamespaceStmtCtx
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / EffectiveStmtCtx.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.spi.meta;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.VerifyException;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.concepts.Immutable;
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
22 /**
23  * Effective view of a {@link StmtContext} for the purposes of creating an {@link EffectiveStatement}.
24  */
25 @Beta
26 public interface EffectiveStmtCtx extends CommonStmtCtx, StmtContextCompat, Immutable {
27     /**
28      * Return parent of this context, if there is one. All statements except for top-level source statements, such as
29      * {@code module} and {@code submodule}.
30      *
31      * @return Parent context, or null if this statement is the root
32      */
33     @Nullable Parent effectiveParent();
34
35     /**
36      * Return parent of this context.
37      *
38      * @return Parent context
39      * @throws VerifyException if this context is already the root
40      */
41     default @NonNull Parent getEffectiveParent() {
42         return verifyNotNull(effectiveParent(), "Attempted to access beyond root context");
43     }
44
45     /**
46      * Minimum amount of parent state required to build an accurate effective view of a particular child. Child state
47      * is expressed as {@link Current}.
48      */
49     @Beta
50     interface Parent extends EffectiveStmtCtx {
51         // FIXME: 7.0.0: this should be Optional<Boolean>
52         boolean effectiveConfig();
53
54         /**
55          * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
56          * {@link Optional#empty()} is returned.
57          *
58          * @return Optional SchemaPath
59          * @deprecated Use of SchemaPath in the context of effective statements is going away. Consider not providing
60          *             this information, if your users can exist without it.
61          */
62         // FIXME: 7.0.0: this needs to be a tri-state present/absent/disabled
63         @Deprecated
64         @NonNull Optional<SchemaPath> schemaPath();
65
66         @Deprecated
67         default @NonNull SchemaPath getSchemaPath() {
68             return schemaPath().orElseThrow();
69         }
70     }
71
72     /**
73      * Minimum amount of state required to build an accurate effective view of a statement. This is a strict superset
74      * of information available in {@link Parent}.
75      *
76      * @param <A> Argument type
77      * @param <D> Class representing declared version of this statement
78      */
79     @Beta
80     interface Current<A, D extends DeclaredStatement<A>> extends Parent, BoundStmtCtx<A>, NamespaceStmtCtx {
81
82         @NonNull CommonStmtCtx root();
83
84         @NonNull D declared();
85
86         @Nullable EffectiveStatement<?, ?> original();
87
88         /**
89          * Summon the <a href="https://en.wikipedia.org/wiki/Rabbit_of_Caerbannog">Rabbit of Caerbannog</a>.
90          *
91          * @param <E> Effective Statement representation
92          * @return The {@code Legendary Black Beast of Arrrghhh}.
93          */
94         // FIXME: YANGTOOLS-1186: lob the Holy Hand Grenade of Antioch
95         @Deprecated
96         <E extends EffectiveStatement<A, D>> @NonNull StmtContext<A, D, E> caerbannog();
97     }
98 }