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%2FImportStatementDefinition.java;h=6bf310158fc9a866697310dada0ce70bca48d082;hb=04fa25a4fe8957f6492618aa9a1e9a4f9af39df4;hp=0dbd2c3ee3d66ff261a7543dff40c4aea39f58a1;hpb=ae9af9e65c08648c6308184ce3c8c8273e2b5c25;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java index 0dbd2c3ee3..6bf310158f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java @@ -26,6 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement; import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl; import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace; +import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator; import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport; import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder; @@ -38,6 +39,9 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ImportEffec public class ImportStatementDefinition extends AbstractStatementSupport> { + private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = + SubstatementValidator.builder(Rfc6020Mapping.IMPORT) + .add(Rfc6020Mapping.PREFIX, 1, 1).add(Rfc6020Mapping.REVISION_DATE, 0, 1).build(); public ImportStatementDefinition() { super(Rfc6020Mapping.IMPORT); @@ -49,8 +53,7 @@ public class ImportStatementDefinition } @Override - public ImportStatement createDeclared( - final StmtContext ctx) { + public ImportStatement createDeclared(final StmtContext ctx) { return new ImportStatementImpl(ctx); } @@ -60,6 +63,13 @@ public class ImportStatementDefinition return new ImportEffectiveStatementImpl(ctx); } + @Override + public void onFullDefinitionDeclared( + final Mutable> stmt) { + super.onFullDefinitionDeclared(stmt); + SUBSTATEMENT_VALIDATOR.validate(stmt); + } + @Override public void onLinkageDeclared( final Mutable> stmt) { @@ -71,12 +81,12 @@ public class ImportStatementDefinition importAction.apply(new InferenceAction() { @Override - public void apply() throws InferenceException { + public void apply() { StmtContext importedModule = null; ModuleIdentifier importedModuleIdentifier = null; if (impIdentifier.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP) { - Entry>> recentModuleEntry = findRecentModule( - impIdentifier, stmt.getAllFromNamespace(ModuleNamespace.class)); + Entry>> recentModuleEntry = + findRecentModule(impIdentifier, stmt.getAllFromNamespace(ModuleNamespace.class)); if (recentModuleEntry != null) { importedModuleIdentifier = recentModuleEntry.getKey(); importedModule = recentModuleEntry.getValue(); @@ -104,9 +114,11 @@ public class ImportStatementDefinition Entry>> recentModuleEntry = null; for (Entry>> moduleEntry : allModules.entrySet()) { - if (moduleEntry.getKey().getName().equals(impIdentifier.getName()) - && moduleEntry.getKey().getRevision().compareTo(recentModuleIdentifier.getRevision()) > 0) { - recentModuleIdentifier = moduleEntry.getKey(); + final ModuleIdentifier id = moduleEntry.getKey(); + + if (id.getName().equals(impIdentifier.getName()) + && id.getRevision().compareTo(recentModuleIdentifier.getRevision()) > 0) { + recentModuleIdentifier = id; recentModuleEntry = moduleEntry; } } @@ -117,11 +129,13 @@ public class ImportStatementDefinition @Override public void prerequisiteFailed(final Collection> failed) { if (failed.contains(imported)) { - throw new InferenceException(String.format("Imported module [%s] was not found.", impIdentifier), - stmt.getStatementSourceReference()); + throw new InferenceException(stmt.getStatementSourceReference(), + "Imported module [%s] was not found.", impIdentifier); } } }); + + } private static ModuleIdentifier getImportedModuleIdentifier(final Mutable stmt) {