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.spi.meta;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.VerifyException;
15 import java.util.Optional;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.yangtools.concepts.Immutable;
19 import org.opendaylight.yangtools.yang.common.YangVersion;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
26 * Effective view of a {@link StmtContext} for the purposes of creating an {@link EffectiveStatement}.
29 public interface EffectiveStmtCtx extends CommonStmtCtx, Immutable {
31 * Return parent of this context, if there is one. All statements except for top-level source statements, such as
32 * {@code module} and {@code submodule}.
34 * @return Parent context, or null if this statement is the root
36 @Nullable Parent effectiveParent();
39 * Return parent of this context.
41 * @return Parent context
42 * @throws VerifyException if this context is already the root
44 default @NonNull Parent getEffectiveParent() {
45 return verifyNotNull(effectiveParent(), "Attempted to access beyond root context");
49 * Minimum amount of parent state required to build an accurate effective view of a particular child. Child state
50 * is expressed as {@link Current}.
53 interface Parent extends EffectiveStmtCtx {
54 // FIXME: 7.0.0: this should be Optional<Boolean>
55 boolean effectiveConfig();
58 * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
59 * {@link Optional#empty()} is returned.
61 * @return Optional SchemaPath
62 * @deprecated Use of SchemaPath in the context of effective statements is going away. Consider not providing
63 * this information, if your users can exist without it.
65 // FIXME: 7.0.0: this needs to be a tri-state present/absent/disabled
67 @NonNull Optional<SchemaPath> schemaPath();
70 default @NonNull SchemaPath getSchemaPath() {
71 return schemaPath().orElseThrow();
76 * Minimum amount of state required to build an accurate effective view of a statement. This is a strict superset
77 * of information available in {@link Parent}.
79 * @param <A> Argument type
80 * @param <D> Class representing declared version of this statement
83 interface Current<A, D extends DeclaredStatement<A>> extends Parent, BoundStmtCtx<A> {
85 @NonNull CommonStmtCtx root();
87 @NonNull CopyHistory history();
89 @NonNull D declared();
91 <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
94 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
96 @Nullable EffectiveStatement<?, ?> original();
98 @NonNull YangVersion yangVersion();
101 * Summon the <a href="https://en.wikipedia.org/wiki/Rabbit_of_Caerbannog">Rabbit of Caerbannog</a>.
103 * @param <E> Effective Statement representation
104 * @return The {@code Legendary Black Beast of Arrrghhh}.
106 // FIXME: YANGTOOLS-1186: lob the Holy Hand Grenade of Antioch
108 <E extends EffectiveStatement<A, D>> @NonNull StmtContext<A, D, E> caerbannog();