Cleanup DocumentedNode
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ImportEffectiveStatementImpl.java
index 82b173621b16cc397e345382cefc56cdc249b7eb..d3feaad3de45f35256c166f685e518b01e6e558b 100644 (file)
@@ -8,25 +8,25 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
 import com.google.common.base.MoreObjects;
-import java.util.Date;
 import java.util.Objects;
 import java.util.Optional;
 import org.opendaylight.yangtools.concepts.SemVer;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToSemVerModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, ImportStatement>
         implements ModuleImport {
 
     private final String moduleName;
-    private final Date revision;
+    private final Revision revision;
     private final SemVer semVer;
     private final String prefix;
     private final String description;
@@ -50,9 +50,9 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase
             this.revision = revisionDateStmt == null ? getImportedRevision(ctx) : revisionDateStmt.argument();
             this.semVer = null;
         } else {
-            final ModuleIdentifier importedModuleIdentifier = ctx.getFromNamespace(
-                ImpPrefixToSemVerModuleIdentifier.class, prefix);
-            revision = importedModuleIdentifier.getRevision();
+            final SemVerSourceIdentifier importedModuleIdentifier = ctx.getFromNamespace(
+                ImportPrefixToSemVerSourceIdentifier.class, prefix);
+            revision = importedModuleIdentifier.getRevision().orElse(null);
             semVer = importedModuleIdentifier.getSemanticVersion().orElse(null);
         }
 
@@ -64,7 +64,7 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase
         this.reference = referenceStmt != null ? referenceStmt.argument() : null;
     }
 
-    private Date getImportedRevision(final StmtContext<String, ImportStatement, ?> ctx) {
+    private Revision getImportedRevision(final StmtContext<String, ImportStatement, ?> ctx) {
         /*
          * When 'revision-date' of an import is not specified in yang source, we
          * need to find revision of imported module.
@@ -72,7 +72,7 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase
         final QNameModule importedModule = StmtContextUtils.getModuleQNameByPrefix(ctx, this.prefix);
         SourceException.throwIfNull(importedModule, ctx.getStatementSourceReference(),
                 "Unable to find import of module %s with prefix %s.", this.moduleName, this.prefix);
-        return importedModule.getRevision();
+        return importedModule.getRevision().orElse(null);
     }
 
     @Override
@@ -81,8 +81,8 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase
     }
 
     @Override
-    public Date getRevision() {
-        return revision;
+    public Optional<Revision> getRevision() {
+        return Optional.ofNullable(revision);
     }
 
     @Override
@@ -96,13 +96,13 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase
     }
 
     @Override
-    public String getDescription() {
-        return description;
+    public Optional<String> getDescription() {
+        return Optional.ofNullable(description);
     }
 
     @Override
-    public String getReference() {
-        return reference;
+    public Optional<String> getReference() {
+        return Optional.ofNullable(reference);
     }
 
     @Override
@@ -129,9 +129,8 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase
 
     @Override
     public String toString() {
-        return MoreObjects.toStringHelper(this).add("moduleName", getModuleName())
-                .add("revision", getRevision()).add("semantic version", getSemanticVersion())
-                .add("prefix", getPrefix()).add("description", getDescription())
-                .add("reference", getReference()).toString();
+        return MoreObjects.toStringHelper(this).omitNullValues().add("moduleName", getModuleName())
+                .add("revision", revision).add("version", semVer).add("prefix", getPrefix())
+                .add("description", description).add("reference", reference).toString();
     }
 }