Eliminate YangModelDependencyInfo
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / source / SourceDependency.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.api.source;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Serializable;
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.model.api.stmt.BelongsToStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
22
23 /**
24  * Common interface expressing a dependency on a source, be it a {@link ModuleStatement}
25  * or a {@link SubmoduleStatement}.
26  */
27 @NonNullByDefault
28 public sealed interface SourceDependency extends Serializable
29         permits SourceDependency.Import, SourceDependency.Include, SourceDependency.BelongsTo {
30     /**
31      * The name of the required source.
32      *
33      * @return name of the required source
34      */
35     Unqualified name();
36
37     /**
38      * Returns required source revision. If specified, this dependency can be satisfied only by the specified revision
39      * or its semantic equivalent (think semantic version of imports). If unspecified, this dependency can be satisfied
40      * by any source with a matching {@link #name()}.
41      *
42      * @return required source revision, {@code null} if unspecified
43      */
44     @Nullable Revision revision();
45
46     /**
47      * A dependency created by a {@link BelongsToStatement}.
48      */
49     record BelongsTo(Unqualified name, Unqualified prefix) implements SourceDependency {
50         @java.io.Serial
51         private static final long serialVersionUID = 0L;
52
53         public BelongsTo {
54             requireNonNull(name);
55             requireNonNull(prefix);
56         }
57
58         @Override
59         public @Nullable Revision revision() {
60             return null;
61         }
62     }
63
64     /**
65      * A dependency created by an {@link ImportStatement}.
66      */
67     record Import(Unqualified name, Unqualified prefix, @Nullable Revision revision) implements SourceDependency {
68         @java.io.Serial
69         private static final long serialVersionUID = 0L;
70
71         public Import {
72             requireNonNull(name);
73             requireNonNull(prefix);
74         }
75
76         public Import(final Unqualified name, final Unqualified prefix) {
77             this(name, prefix, null);
78         }
79     }
80
81     /**
82      * A dependency created by an {@link IncludeStatement}.
83      */
84     record Include(Unqualified name, @Nullable Revision revision) implements SourceDependency {
85         @java.io.Serial
86         private static final long serialVersionUID = 0L;
87
88         public Include {
89             requireNonNull(name);
90         }
91
92         public Include(final Unqualified name) {
93             this(name, null);
94         }
95     }
96 }