Add SchemaSourceInfo
[yangtools.git] / model / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / source / SourceInfo.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.spi.source;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableSet;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.Revision;
16 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
17 import org.opendaylight.yangtools.yang.common.YangVersion;
18 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
19
20 /**
21  * Linkage information about a particular {@link SourceRepresentation}. It has two specializations
22  * <ol>
23  *   <li>{@link ModuleSourceInfo} pertaining to {@link SourceRepresentation} which have {@code module} as its root
24  *       statement</li>
25  *   <li>{@link SubmoduleSourceInfo} pertaining to {@link SourceRepresentation} which have {@code submodule} as its root
26  *       statement</li>
27  * </ol>
28  *
29  * <p>
30  * This interface captures the basic metadata needed for interpretation and linkage of the source, as represented by the
31  * following ABNF constructs placed at the start of a YANG file:
32  * <ul>
33  *   <li>{@code module-header-stmts} or {@code submodule-header-stmts}</li>
34  *   <li>{@code linkage-stmts}</li>
35  *   <li>{@code revision-stmts}<li>
36  * </ul>
37  */
38 @NonNullByDefault
39 public sealed interface SourceInfo permits ModuleSourceInfo, SubmoduleSourceInfo {
40     record Import(Unqualified name, String prefix, @Nullable Revision revision) {
41         public Import {
42             requireNonNull(name);
43             requireNonNull(prefix);
44         }
45     }
46
47     record Include(Unqualified name, @Nullable Revision revision) {
48         public Include {
49             requireNonNull(name);
50         }
51     }
52
53     /**
54      * The name of this source, as expressed by the argument of {@code module} or {@code submodule} statement.
55      *
56      * @return name of this source.
57      */
58     Unqualified name();
59
60     /**
61      * {@link YangVersion} of the source. If no {@code yang-version} is present, this method will return
62      * {@link YangVersion#VERSION_1}.
63      *
64      * @return {@link YangVersion} of the source
65      */
66     YangVersion yangVersion();
67
68     ImmutableSet<Revision> revisions();
69
70     ImmutableSet<Import> imports();
71
72     ImmutableSet<Include> includes();
73 }