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;
24 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
25 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
26 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
29 * Effective view of a {@link StmtContext} for the purposes of creating an {@link EffectiveStatement}.
32 public interface EffectiveStmtCtx extends Immutable {
34 * Return parent of this context, if there is one. All statements except for top-level source statements, such as
35 * {@code module} and {@code submodule}.
37 * @return Parent context, or null if this statement is the root
39 // FIXME: YANGTOOLS-1185: rename to effectiveParent()
40 @Nullable Parent parent();
43 * Return parent of this context.
45 * @return Parent context
46 * @throws VerifyException if this context is already the root
48 // FIXME: YANGTOOLS-1185: rename to getEffectiveParent()
49 default @NonNull Parent getParent() {
50 return verifyNotNull(parent(), "Attempted to access beyond root context");
54 * Minimum amount of parent state required to build an accurate effective view of a particular child. Child state
55 * is expressed as {@link Current}.
58 interface Parent extends EffectiveStmtCtx {
59 // FIXME: 7.0.0: this should be Optional<Boolean>
60 boolean effectiveConfig();
62 // FIXME: 7.0.0: this needs to be a tri-state present/absent/disabled
64 @NonNull Optional<SchemaPath> schemaPath();
67 default @NonNull SchemaPath getSchemaPath() {
68 return schemaPath().orElseThrow();
71 @NonNull StatementDefinition publicDefinition();
75 * Minimum amount of state required to build an accurate effective view of a statement. This is a strict superset
76 * of information available in {@link Parent}.
78 * @param <A> Argument type
79 * @param <D> Class representing declared version of this statement
82 interface Current<A, D extends DeclaredStatement<A>> extends Parent {
83 default @NonNull StatementSource source() {
84 return sourceReference().getStatementSource();
87 @NonNull StatementSourceReference sourceReference();
89 @NonNull CopyHistory history();
91 @NonNull D declared();
93 <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
96 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
98 @Nullable A argument();
100 default @NonNull A coerceArgument() {
101 return verifyNotNull(argument(), "Attempted to use non-existent argument");
104 @Nullable String rawArgument();
106 @Nullable EffectiveStatement<?, ?> original();
108 @NonNull YangVersion yangVersion();
111 * Summon the <a href="https://en.wikipedia.org/wiki/Rabbit_of_Caerbannog">Rabbit of Caerbannog</a>.
113 * @param <E> Effective Statement representation
114 * @return The {@code Legendary Black Beast of Arrrghhh}.
116 // FIXME: YANGTOOLS-1186: lob the Holy Hand Grenade of Antioch
118 <E extends EffectiveStatement<A, D>> @NonNull StmtContext<A, D, E> caerbannog();