X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2Feffective%2FImportEffectiveStatementImpl.java;h=a76576d37f4a9d7401cb25376b8f49460e1517af;hb=437ce7f365bc3f1e916cd7f109fc3875356f0a74;hp=8209c346a8eb0a2fbfc538d1720a3276024b2921;hpb=ac6b1c788424ca50221ce7b243e4255a8b6fe4c4;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java index 8209c346a8..a76576d37f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java @@ -11,17 +11,19 @@ import com.google.common.base.MoreObjects; import java.util.Date; import java.util.Objects; import org.opendaylight.yangtools.concepts.SemVer; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement; 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.SourceException; -public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase implements - ModuleImport { +public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase + implements ModuleImport { private final String moduleName; private final Date revision; @@ -34,7 +36,7 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase super(ctx); moduleName = ctx.getStatementArgument(); - PrefixEffectiveStatementImpl prefixStmt = firstEffective(PrefixEffectiveStatementImpl.class); + final PrefixEffectiveStatementImpl prefixStmt = firstEffective(PrefixEffectiveStatementImpl.class); if (prefixStmt != null) { this.prefix = prefixStmt.argument(); } else { @@ -43,21 +45,34 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase } if (!ctx.isEnabledSemanticVersioning()) { - RevisionDateEffectiveStatementImpl revisionDateStmt = firstEffective(RevisionDateEffectiveStatementImpl.class); - this.revision = (revisionDateStmt == null) ? SimpleDateFormatUtil.DEFAULT_DATE_IMP : revisionDateStmt - .argument(); + final RevisionDateEffectiveStatementImpl revisionDateStmt = firstEffective( + RevisionDateEffectiveStatementImpl.class); + this.revision = revisionDateStmt == null ? getImportedRevision(ctx) : revisionDateStmt.argument(); this.semVer = Module.DEFAULT_SEMANTIC_VERSION; } else { - ModuleIdentifier importedModuleIdentifier = ctx.getFromNamespace(ImpPrefixToSemVerModuleIdentifier.class, prefix); + final ModuleIdentifier importedModuleIdentifier = ctx.getFromNamespace( + ImpPrefixToSemVerModuleIdentifier.class, prefix); revision = importedModuleIdentifier.getRevision(); semVer = importedModuleIdentifier.getSemanticVersion(); } - DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class); - this.description = (descriptionStmt != null) ? descriptionStmt.argument() : null; + final DescriptionEffectiveStatementImpl descriptionStmt = firstEffective( + DescriptionEffectiveStatementImpl.class); + this.description = descriptionStmt != null ? descriptionStmt.argument() : null; - ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class); - this.reference = (referenceStmt != null) ? referenceStmt.argument() : null; + final ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class); + this.reference = referenceStmt != null ? referenceStmt.argument() : null; + } + + private Date getImportedRevision(final StmtContext ctx) { + /* + * When 'revision-date' of an import is not specified in yang source, we + * need to find revision of imported module. + */ + 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(); } @Override @@ -106,7 +121,7 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase if (getClass() != obj.getClass()) { return false; } - ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj; + final ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj; return Objects.equals(moduleName, other.moduleName) && Objects.equals(revision, other.revision) && Objects.equals(semVer, other.semVer) && Objects.equals(prefix, other.prefix) && Objects.equals(description, other.description) && Objects.equals(reference, other.reference);