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 com.google.common.collect.ImmutableList;
14 import java.util.Collection;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 * An abstract base class for {@link DeclaredStatement} implementations. This is a direct competition to
22 * {@link org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement}, providing lower-footprint
26 public abstract class AbstractDeclaredStatement<A> extends AbstractModelStatement<A> implements DeclaredStatement<A> {
27 protected AbstractDeclaredStatement() {
31 public final StatementSource getStatementSource() {
32 return StatementSource.DECLARATION;
36 public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
37 // Default to reduce load on subclasses and keep the number of implementations down
38 return ImmutableList.of();
42 * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}.
44 * @param masked list to unmask
45 * @return Unmasked list
46 * @throws NullPointerException if masked is null
47 * @throws ClassCastException if masked object does not match DeclaredStatement
49 @SuppressWarnings({ "rawtypes", "unchecked" })
50 protected static final @NonNull ImmutableList<? extends DeclaredStatement<?>> unmaskList(
51 final @NonNull Object masked) {
52 return (ImmutableList) unmaskList(masked, DeclaredStatement.class);
55 public abstract static class WithRawArgument<A> extends AbstractDeclaredStatement<A> {
56 private final String rawArgument;
58 protected WithRawArgument(final StmtContext<A, ?, ?> context) {
59 rawArgument = context.rawStatementArgument();
63 public final String rawArgument() {
68 public abstract static class WithRawStringArgument extends WithRawArgument<String> {
69 protected WithRawStringArgument(final StmtContext<String, ?, ?> context) {
74 public final String argument() {
79 public abstract static class WithArgument<A> extends WithRawArgument<A> {
80 private final A argument;
82 protected WithArgument(final StmtContext<A, ?, ?> context) {
84 argument = context.getStatementArgument();
88 public final A argument() {
93 public abstract static class ArgumentToString<A> extends AbstractDeclaredStatement<A> {
94 private final @NonNull A argument;
96 protected ArgumentToString(final A argument) {
97 this.argument = requireNonNull(argument);
101 public final @NonNull A argument() {
106 public final String rawArgument() {
107 return argument.toString();