X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=parser%2Fyang-parser-rfc7950%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frfc7950%2Frepo%2FYangModelDependencyInfo.java;h=73ca392e2041489583c27b5193305b107597dc0a;hb=4d34b74e078e4e7f9c9a3fe6f263a3d04560346d;hp=c81bf3a8843bd07eeff1e9cba0a1f0d2709f492f;hpb=23bfbdabd5296bb721b5e021fbeb93699d9c2f56;p=yangtools.git diff --git a/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangModelDependencyInfo.java b/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangModelDependencyInfo.java index c81bf3a884..73ca392e20 100644 --- a/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangModelDependencyInfo.java +++ b/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangModelDependencyInfo.java @@ -10,8 +10,6 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.repo; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; -import com.google.common.annotations.Beta; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.util.HashSet; @@ -20,9 +18,6 @@ import java.util.Optional; import java.util.Set; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.opendaylight.yangtools.concepts.SemVer; -import org.opendaylight.yangtools.openconfig.model.api.OpenConfigStatements; -import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.model.api.YangStmtMapping; @@ -61,33 +56,20 @@ public abstract class YangModelDependencyInfo { private static final String REVISION_DATE = YangStmtMapping.REVISION_DATE.getStatementName().getLocalName(); private static final String SUBMODULE = YangStmtMapping.SUBMODULE.getStatementName().getLocalName(); - private static final String OPENCONFIG_VERSION = OpenConfigStatements.OPENCONFIG_VERSION.getStatementName() - .getLocalName(); - private final String name; private final Revision revision; - private final SemVer semVer; private final ImmutableSet submoduleIncludes; private final ImmutableSet moduleImports; private final ImmutableSet dependencies; - YangModelDependencyInfo(final String name, final String formattedRevision, - final ImmutableSet imports, + YangModelDependencyInfo(final String name, final String formattedRevision, final ImmutableSet imports, final ImmutableSet includes) { - this(name, formattedRevision, imports, includes, Optional.empty()); - } - - YangModelDependencyInfo(final String name, final String formattedRevision, - final ImmutableSet imports, - final ImmutableSet includes, - final Optional semVer) { this.name = name; revision = Revision.ofNullable(formattedRevision).orElse(null); moduleImports = imports; submoduleIncludes = includes; dependencies = ImmutableSet.builder() .addAll(moduleImports).addAll(submoduleIncludes).build(); - this.semVer = semVer.orElse(null); } /** @@ -127,39 +109,19 @@ public abstract class YangModelDependencyInfo { return Optional.ofNullable(revision); } - /** - * Returns semantic version of module. - * - * @return semantic version - */ - public Optional getSemanticVersion() { - return Optional.ofNullable(semVer); - } - @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Objects.hashCode(name); result = prime * result + Objects.hashCode(revision); - result = prime * result + Objects.hashCode(semVer); return result; } @Override public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof YangModelDependencyInfo)) { - return false; - } - final YangModelDependencyInfo other = (YangModelDependencyInfo) obj; - return Objects.equals(name, other.name) && Objects.equals(revision, other.revision) - && Objects.equals(semVer, other.semVer); + return this == obj || obj instanceof YangModelDependencyInfo other + && Objects.equals(name, other.name) && Objects.equals(revision, other.revision); } /** @@ -215,11 +177,10 @@ public abstract class YangModelDependencyInfo { final SourceIdentifier source) { final String name = safeStringArgument(source, module, "module name"); final String latestRevision = getLatestRevision(module, source); - final Optional semVer = Optional.ofNullable(findSemanticVersion(module, source)); final ImmutableSet imports = parseImports(module, source); final ImmutableSet includes = parseIncludes(module, source); - return new ModuleDependencyInfo(name, latestRevision, imports, includes, semVer); + return new ModuleDependencyInfo(name, latestRevision, imports, includes); } private static ImmutableSet parseImports(final IRStatement module, @@ -230,27 +191,12 @@ public abstract class YangModelDependencyInfo { final String importedModuleName = safeStringArgument(source, substatement, "imported module name"); final String revisionDateStr = getRevisionDateString(substatement, source); final Revision revisionDate = Revision.ofNullable(revisionDateStr).orElse(null); - final SemVer importSemVer = findSemanticVersion(substatement, source); - result.add(new ModuleImportImpl(importedModuleName, revisionDate, importSemVer)); + result.add(new ModuleImportImpl(importedModuleName, revisionDate)); } } return ImmutableSet.copyOf(result); } - @Beta - public static SemVer findSemanticVersion(final IRStatement statement, final SourceIdentifier source) { - String semVerString = null; - for (final IRStatement substatement : statement.statements()) { - // FIXME: this should also check we are using a prefix - if (OPENCONFIG_VERSION.equals(substatement.keyword().identifier())) { - semVerString = safeStringArgument(source, substatement, "version string"); - break; - } - } - - return Strings.isNullOrEmpty(semVerString) ? null : SemVer.valueOf(semVerString); - } - private static boolean isBuiltin(final IRStatement stmt, final String localName) { final IRKeyword keyword = stmt.keyword(); return keyword instanceof Unqualified && localName.equals(keyword.identifier()); @@ -316,7 +262,10 @@ public abstract class YangModelDependencyInfo { static String safeStringArgument(final SourceIdentifier source, final IRStatement stmt, final String desc) { final StatementSourceReference ref = getReference(source, stmt); final IRArgument arg = stmt.argument(); - checkArgument(arg != null, "Missing %s at %s", desc, ref); + if (arg == null) { + throw new IllegalArgumentException("Missing " + desc + " at " + ref); + } + // TODO: we probably need to understand yang version first.... return ArgumentContextUtils.rfc6020().stringFromStringContext(arg, ref); } @@ -330,14 +279,13 @@ public abstract class YangModelDependencyInfo { */ public static final class ModuleDependencyInfo extends YangModelDependencyInfo { ModuleDependencyInfo(final String name, final String latestRevision, final ImmutableSet imports, - final ImmutableSet includes, final Optional semVer) { - super(name, latestRevision, imports, includes, semVer); + final ImmutableSet includes) { + super(name, latestRevision, imports, includes); } @Override public String toString() { return "Module [name=" + getName() + ", revision=" + getRevision() - + ", semanticVersion=" + getSemanticVersion().orElse(null) + ", dependencies=" + getDependencies() + "]"; } @@ -366,9 +314,9 @@ public abstract class YangModelDependencyInfo { @Override public String toString() { - return "Submodule [name=" + getName() + ", revision=" - + getRevision() + ", dependencies=" + getDependencies() - + "]"; + return "Submodule [name=" + getName() + ", revision=" + getRevision() + + ", dependencies=" + getDependencies() + + "]"; } } @@ -377,25 +325,17 @@ public abstract class YangModelDependencyInfo { */ // FIXME: this is a rather nasty misuse of APIs :( private static final class ModuleImportImpl implements ModuleImport { - + private final @NonNull String moduleName; private final Revision revision; - private final SemVer semVer; - private final String name; ModuleImportImpl(final @NonNull String moduleName, final @Nullable Revision revision) { - this(moduleName, revision, null); - } - - ModuleImportImpl(final @NonNull String moduleName, final @Nullable Revision revision, - final @Nullable SemVer semVer) { - name = requireNonNull(moduleName, "Module name must not be null."); + this.moduleName = requireNonNull(moduleName, "Module name must not be null."); this.revision = revision; - this.semVer = semVer; } @Override public String getModuleName() { - return name; + return moduleName; } @Override @@ -403,14 +343,9 @@ public abstract class YangModelDependencyInfo { return Optional.ofNullable(revision); } - @Override - public Optional getSemanticVersion() { - return Optional.ofNullable(semVer); - } - @Override public String getPrefix() { - return null; + throw new UnsupportedOperationException(); } @Override @@ -432,29 +367,20 @@ public abstract class YangModelDependencyInfo { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(moduleName); result = prime * result + Objects.hashCode(revision); - result = prime * result + Objects.hashCode(semVer); return result; } @Override public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof ModuleImportImpl)) { - return false; - } - final ModuleImportImpl other = (ModuleImportImpl) obj; - return name.equals(other.name) && Objects.equals(revision, other.revision) - && Objects.equals(getSemanticVersion(), other.getSemanticVersion()); + return this == obj || obj instanceof ModuleImportImpl other + && moduleName.equals(other.moduleName) && Objects.equals(revision, other.revision); } @Override public String toString() { - return "ModuleImportImpl [name=" + name + ", revision=" - + QName.formattedRevision(Optional.ofNullable(revision)) + ", semanticVersion=" + semVer + "]"; + return "ModuleImportImpl [name=" + moduleName + ", revision=" + revision + "]"; } } }