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 org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
18 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
21 * Common interface for all statement contexts, exposing information which is always available. Note this includes only
22 * stateless information -- hence we have {@link #rawArgument()} but do not have an equivalent {@code argument()}.
25 public interface CommonStmtCtx {
27 * See {@link StatementSupport#getPublicView()}.
29 @NonNull StatementDefinition publicDefinition();
32 * Returns a reference to statement source.
34 * @return reference of statement source
36 @NonNull StatementSourceReference sourceReference();
39 * Returns the origin of the statement.
41 * @return origin of statement
43 default @NonNull StatementSource source() {
44 return sourceReference().getStatementSource();
48 * Return the statement argument in literal format.
50 * @return raw statement argument string, or null if this statement does not have an argument.
52 @Nullable String rawArgument();
55 * Return the statement argument in literal format.
57 * @return raw statement argument string
58 * @throws VerifyException if this statement does not have an argument
60 default @NonNull String getRawArgument() {
61 return verifyNotNull(rawArgument(), "Statement context %s does not have an argument", this);