Remove getSemanticVersion()
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / repo / YangModelDependencyInfo.java
index ff6173d166f781ac8c7a9daa99f180dbe4fa3a1f..73ca392e2041489583c27b5193305b107597dc0a 100644 (file)
@@ -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<ModuleImport> submoduleIncludes;
     private final ImmutableSet<ModuleImport> moduleImports;
     private final ImmutableSet<ModuleImport> dependencies;
 
-    YangModelDependencyInfo(final String name, final String formattedRevision,
-            final ImmutableSet<ModuleImport> imports,
+    YangModelDependencyInfo(final String name, final String formattedRevision, final ImmutableSet<ModuleImport> imports,
             final ImmutableSet<ModuleImport> includes) {
-        this(name, formattedRevision, imports, includes, Optional.empty());
-    }
-
-    YangModelDependencyInfo(final String name, final String formattedRevision,
-            final ImmutableSet<ModuleImport> imports,
-            final ImmutableSet<ModuleImport> includes,
-            final Optional<SemVer> semVer) {
         this.name = name;
         revision = Revision.ofNullable(formattedRevision).orElse(null);
         moduleImports = imports;
         submoduleIncludes = includes;
         dependencies = ImmutableSet.<ModuleImport>builder()
                 .addAll(moduleImports).addAll(submoduleIncludes).build();
-        this.semVer = semVer.orElse(null);
     }
 
     /**
@@ -127,41 +109,19 @@ public abstract class YangModelDependencyInfo {
         return Optional.ofNullable(revision);
     }
 
-    /**
-     * Returns semantic version of module.
-     *
-     * @return semantic version
-     * @deprecated Semantic versioning is deprecated
-     */
-    @Deprecated(since = "8.0.4", forRemoval = true)
-    public Optional<SemVer> 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);
     }
 
     /**
@@ -217,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> semVer = Optional.ofNullable(findSemanticVersion(module, source));
         final ImmutableSet<ModuleImport> imports = parseImports(module, source);
         final ImmutableSet<ModuleImport> includes = parseIncludes(module, source);
 
-        return new ModuleDependencyInfo(name, latestRevision, imports, includes, semVer);
+        return new ModuleDependencyInfo(name, latestRevision, imports, includes);
     }
 
     private static ImmutableSet<ModuleImport> parseImports(final IRStatement module,
@@ -232,28 +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
-    @Deprecated(since = "8.0.4", forRemoval = true)
-    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());
@@ -336,14 +279,13 @@ public abstract class YangModelDependencyInfo {
      */
     public static final class ModuleDependencyInfo extends YangModelDependencyInfo {
         ModuleDependencyInfo(final String name, final String latestRevision, final ImmutableSet<ModuleImport> imports,
-                final ImmutableSet<ModuleImport> includes, final Optional<SemVer> semVer) {
-            super(name, latestRevision, imports, includes, semVer);
+                final ImmutableSet<ModuleImport> includes) {
+            super(name, latestRevision, imports, includes);
         }
 
         @Override
         public String toString() {
             return "Module [name=" + getName() + ", revision=" + getRevision()
-                + ", semanticVersion=" + getSemanticVersion().orElse(null)
                 + ", dependencies=" + getDependencies()
                 + "]";
         }
@@ -372,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()
+                + "]";
         }
     }
 
@@ -383,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
@@ -409,12 +343,6 @@ public abstract class YangModelDependencyInfo {
             return Optional.ofNullable(revision);
         }
 
-        @Override
-        @Deprecated(forRemoval = true)
-        public Optional<SemVer> getSemanticVersion() {
-            return Optional.ofNullable(semVer);
-        }
-
         @Override
         public String getPrefix() {
             throw new UnsupportedOperationException();
@@ -439,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 + "]";
         }
     }
 }