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;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.common.YangVersion;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 * A {@link CommonStmtCtx} which has additionally been bound to a {@link StatementSupport}. It provides
22 * {@link #argument()} as interpreted by that support.
24 * @param <A> Argument type
27 public interface BoundStmtCtx<A> extends CommonStmtCtx {
29 * Return the statement argument.
31 * @return statement argument, or null if this statement does not have an argument
33 @Nullable A argument();
36 * Return the statement argument in literal format.
38 * @return raw statement argument string
39 * @throws VerifyException if this statement does not have an argument
41 default @NonNull A getArgument() {
42 return verifyNotNull(argument(), "Attempted to use non-existent argument of %s", this);
46 * Return the {@link YangVersion} associated with this statement.
48 * @return YANG version used to bind this statement
50 @NonNull YangVersion yangVersion();
53 * Search of any child statement context of specified type and return its argument. If such a statement exists, it
54 * is assumed to have the right argument. Users should be careful to use this method for statements which have
55 * cardinality {@code 0..1}, otherwise this method can return any one of the statement's argument.
57 * @param <X> Substatement argument type
58 * @param <Z> Substatement effective statement representation
59 * @param type Effective statement representation being look up
60 * @return {@link Optional#empty()} if no statement exists, otherwise the argument value
62 <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(@NonNull Class<Z> type);
65 * Check if there is any child statement context of specified type.
67 * @param type Effective statement representation being look up
68 * @return True if such a child statement exists, false otherwise
70 boolean hasSubstatement(@NonNull Class<? extends EffectiveStatement<?, ?>> type);