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.rfc7950.stmt;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
20 * Base stateless superclass for statements which (logically) always have an associated {@link DeclaredStatement}. This
21 * is notably not true for all {@code case} statements, some of which may actually be implied.
24 * Note implementations are not strictly required to make the declared statement available, they are free to throw
25 * {@link UnsupportedOperationException} from {@link #getDeclared()}, rendering any services relying on declared
26 * statement to be not available.
28 * @param <A> Argument type ({@link Void} if statement does not have argument.)
29 * @param <D> Class representing declared version of this statement.
32 public abstract class AbstractDeclaredEffectiveStatement<A, D extends DeclaredStatement<A>>
33 extends AbstractEffectiveStatement<A, D> {
35 public final StatementSource getStatementSource() {
36 return StatementSource.DECLARATION;
40 public final StatementDefinition statementDefinition() {
41 return getDeclared().statementDefinition();
45 public abstract @NonNull D getDeclared();
48 * A stateful version of {@link AbstractDeclaredEffectiveStatement}, which holds (and requires) a declared
51 * @param <A> Argument type ({@link Void} if statement does not have argument.)
52 * @param <D> Class representing declared version of this statement.
54 public abstract static class Default<A, D extends DeclaredStatement<A>>
55 extends AbstractDeclaredEffectiveStatement<A, D> {
56 private final @NonNull D declared;
58 protected Default(final D declared) {
59 this.declared = requireNonNull(declared);
63 public final D getDeclared() {
69 * An extra building block on top of {@link Default}, which is wiring {@link #argument()} to the declared statement.
70 * This is mostly useful for arguments that are not subject to inference transformation -- for example Strings in
71 * {@code description}, etc. This explicitly is not true of statements which underwent namespace binding via
72 * {@code uses} or similar.
74 * @param <A> Argument type ({@link Void} if statement does not have argument.)
75 * @param <D> Class representing declared version of this statement.
77 public abstract static class DefaultArgument<A, D extends DeclaredStatement<A>> extends Default<A, D> {
78 protected DefaultArgument(final D declared) {
83 public final @Nullable A argument() {
84 return getDeclared().argument();