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.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
22 * Common interface for all statement contexts, exposing information which is always available. Note this includes only
23 * stateless information -- hence we have {@link #rawArgument()} but do not have an equivalent {@code argument()}.
26 public interface CommonStmtCtx {
28 * See {@link StatementSupport#getPublicView()}.
30 @NonNull StatementDefinition publicDefinition();
33 * Return true if this context produces specified {@link DeclaredStatement} representation.
35 * @param <D> Declared Statement representation
36 * @param type DeclaredStatement representation
37 * @return True if this context results in specified {@link DeclaredStatement} representation
39 default <D extends DeclaredStatement<?>> boolean producesDeclared(final Class<? super D> type) {
40 return type.isAssignableFrom(publicDefinition().getDeclaredRepresentationClass());
44 * Return true if this context produces specified {@link EffectiveStatement} representation.
46 * @param <E> Effective Statement representation
47 * @param type EffectiveStatement representation
48 * @return True if this context results in specified {@link EffectiveStatement} representation
50 default <E extends EffectiveStatement<?, ?>> boolean producesEffective(final Class<? super E> type) {
51 return type.isAssignableFrom(publicDefinition().getEffectiveRepresentationClass());
55 * Returns a reference to statement source.
57 * @return reference of statement source
59 @NonNull StatementSourceReference sourceReference();
62 * Return the statement argument in literal format.
64 * @return raw statement argument string, or null if this statement does not have an argument.
66 @Nullable String rawArgument();
69 * Return the statement argument in literal format.
71 * @return raw statement argument string
72 * @throws VerifyException if this statement does not have an argument
74 default @NonNull String getRawArgument() {
75 return verifyNotNull(rawArgument(), "Statement context %s does not have an argument", this);