2 * Copyright (c) 2024 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.model.api.source;
10 import static java.util.Objects.requireNonNull;
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;
24 * Common interface expressing a dependency on a source, be it a {@link ModuleStatement}
25 * or a {@link SubmoduleStatement}.
28 public sealed interface SourceDependency extends Serializable
29 permits SourceDependency.Import, SourceDependency.Include, SourceDependency.BelongsTo {
31 * The name of the required source.
33 * @return name of the required source
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()}.
42 * @return required source revision, {@code null} if unspecified
44 @Nullable Revision revision();
47 * A dependency created by a {@link BelongsToStatement}.
49 record BelongsTo(Unqualified name, Unqualified prefix) implements SourceDependency {
51 private static final long serialVersionUID = 0L;
55 requireNonNull(prefix);
59 public @Nullable Revision revision() {
65 * A dependency created by an {@link ImportStatement}.
67 record Import(Unqualified name, Unqualified prefix, @Nullable Revision revision) implements SourceDependency {
69 private static final long serialVersionUID = 0L;
73 requireNonNull(prefix);
76 public Import(final Unqualified name, final Unqualified prefix) {
77 this(name, prefix, null);
82 * A dependency created by an {@link IncludeStatement}.
84 record Include(Unqualified name, @Nullable Revision revision) implements SourceDependency {
86 private static final long serialVersionUID = 0L;
92 public Include(final Unqualified name) {