Search in sources :

Example 41 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class EffectiveUsesRefineAndConstraintsTest method refineTest.

@Test
public void refineTest() throws Exception {
    final EffectiveModelContext result = StmtTestUtils.parseYangSource("/stmt-test/uses/refine-test.yang");
    final ModuleEffectiveStatement module = Iterables.getOnlyElement(result.getModuleStatements().values());
    final QNameModule qnameModule = module.localQNameModule();
    final QName rootContainer = QName.create(qnameModule, "root-container");
    final QName containerFromGrouping = QName.create(qnameModule, "container-from-grouping");
    final QName listInContainer = QName.create(qnameModule, "list-in-container");
    final QName choiceFromGrp = QName.create(qnameModule, "choice-from-grp");
    final QName containerFromGrouping2 = QName.create(qnameModule, "container-from-grouping2");
    final QName presenceContainer = QName.create(qnameModule, "presence-container");
    checkRefinedList(module, rootContainer, containerFromGrouping, listInContainer);
    checkRefinedChoice(module, rootContainer, containerFromGrouping, choiceFromGrp);
    checkRefinedContainer(module, rootContainer, containerFromGrouping2, presenceContainer);
    final GroupingEffectiveStatement grp = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow();
    assertEquals(QName.create(qnameModule, "grp-1"), grp.argument());
    checkOriginalList(grp, containerFromGrouping, listInContainer);
    checkOriginalChoice(grp, containerFromGrouping, choiceFromGrp);
    checkOriginalContainer(grp, containerFromGrouping2, presenceContainer);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 42 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class DeclaredStatementsTest method testDeclaredModule.

@Test
public void testDeclaredModule() throws ReactorException, ParseException {
    final StatementStreamSource rootModule = sourceForResource("/declared-statements-test/root-module-declared-test.yang");
    final StatementStreamSource importedModule = sourceForResource("/declared-statements-test/imported-module-declared-test.yang");
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(rootModule, importedModule);
    assertNotNull(schemaContext);
    final Revision revision = Revision.of("2016-09-28");
    final Module testModule = schemaContext.findModule("root-module-declared-test", revision).get();
    assertNotNull(testModule);
    final ModuleStatement moduleStatement = ((ModuleEffectiveStatement) testModule).getDeclared();
    assertEquals(1, moduleStatement.getImports().size());
    final ImportStatement importStatement = moduleStatement.getImports().iterator().next();
    assertEquals("imported-module-declared-test", importStatement.argument());
    assertEquals("imdt", importStatement.getPrefix().argument());
    assertEquals(revision, importStatement.getRevisionDate().argument());
    assertEquals("test description", moduleStatement.getDescription().get().argument());
    assertEquals("test reference", moduleStatement.getReference().get().argument());
    assertEquals("test organization", moduleStatement.getOrganization().get().argument());
    assertEquals("test contact", moduleStatement.getContact().get().argument());
    assertEquals(1, moduleStatement.getRevisions().size());
    final RevisionStatement revisionStatement = moduleStatement.getRevisions().iterator().next();
    assertEquals(revision, revisionStatement.argument());
    assertEquals("test description", revisionStatement.getDescription().get().argument());
    assertEquals("test reference", revisionStatement.getReference().get().argument());
    assertEquals(1, moduleStatement.getExtensions().size());
    final ExtensionStatement extensionStatement = moduleStatement.getExtensions().iterator().next();
    assertEquals(Status.CURRENT, extensionStatement.getStatus().get().argument());
    assertEquals("test description", extensionStatement.getDescription().get().argument());
    assertEquals("test reference", extensionStatement.getReference().get().argument());
    final ArgumentStatement argumentStatement = extensionStatement.getArgument();
    assertEquals("ext-argument", argumentStatement.argument().getLocalName());
    assertTrue(argumentStatement.getYinElement().argument());
    assertEquals(2, moduleStatement.getFeatures().size());
    final FeatureStatement featureStatement = moduleStatement.getFeatures().iterator().next();
    assertEquals(Status.CURRENT, featureStatement.getStatus().get().argument());
    assertEquals("test description", featureStatement.getDescription().get().argument());
    assertEquals("test reference", featureStatement.getReference().get().argument());
    assertEquals("test-feature", featureStatement.argument().getLocalName());
    assertEquals(1, featureStatement.getIfFeatures().size());
    assertEquals(2, moduleStatement.getIdentities().size());
    IdentityStatement identityStatement = null;
    for (final IdentityStatement identity : moduleStatement.getIdentities()) {
        if (identity.argument().getLocalName().equals("test-id")) {
            identityStatement = identity;
        }
    }
    assertEquals("test-base-id", identityStatement.getBases().iterator().next().argument().getLocalName());
    assertEquals(Status.CURRENT, identityStatement.getStatus().get().argument());
    assertEquals("test description", identityStatement.getDescription().get().argument());
    assertEquals("test reference", identityStatement.getReference().get().argument());
    assertEquals("test-id", identityStatement.argument().getLocalName());
    assertEquals(1, moduleStatement.getTypedefs().size());
    final TypedefStatement typedefStatement = moduleStatement.getTypedefs().iterator().next();
    assertEquals(Status.CURRENT, typedefStatement.getStatus().get().argument());
    assertEquals("test description", typedefStatement.getDescription().get().argument());
    assertEquals("test reference", typedefStatement.getReference().get().argument());
    assertEquals("test-typedef", typedefStatement.argument().getLocalName());
    assertEquals("int32", typedefStatement.getType().rawArgument());
    assertEquals("meter", typedefStatement.getUnits().get().argument());
}
Also used : ArgumentStatement(org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement) StatementStreamSource(org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource) ModuleStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement) ImportStatement(org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) ExtensionStatement(org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement) TypedefStatement(org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement) Revision(org.opendaylight.yangtools.yang.common.Revision) IdentityStatement(org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) RevisionStatement(org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement) FeatureStatement(org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement) IfFeatureStatement(org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement) Test(org.junit.Test)

Example 43 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class ModuleStatementSupport method onLinkageDeclared.

@Override
public void onLinkageDeclared(final Mutable<Unqualified, ModuleStatement, ModuleEffectiveStatement> stmt) {
    final XMLNamespace moduleNs = SourceException.throwIfNull(firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class), stmt, "Namespace of the module [%s] is missing", stmt.argument());
    final Optional<Revision> revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements());
    final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
    final StmtContext<?, ModuleStatement, ModuleEffectiveStatement> possibleDuplicateModule = stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
    if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
        throw new SourceException(stmt, "Module namespace collision: %s. At %s", qNameModule.getNamespace(), possibleDuplicateModule.sourceReference());
    }
    final String moduleName = stmt.getRawArgument();
    final SourceIdentifier moduleIdentifier = RevisionSourceIdentifier.create(moduleName, revisionDate);
    stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
    stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleIdentifier.getName(), stmt);
    stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
    final String modulePrefix = SourceException.throwIfNull(firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt, "Prefix of the module [%s] is missing", stmt.argument());
    stmt.addToNs(QNameModuleNamespace.class, Empty.value(), qNameModule);
    stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
    stmt.addToNs(ModuleNameToModuleQName.class, moduleName, qNameModule);
    stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
    stmt.addToNs(ModuleCtxToSourceIdentifier.class, stmt, moduleIdentifier);
    stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, moduleName);
    stmt.addToNs(ImportPrefixToModuleCtx.class, modulePrefix, stmt);
    if (semanticVersioning) {
        addToSemVerModuleNamespace(stmt, moduleIdentifier);
    }
}
Also used : NamespaceStatement(org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement) Revision(org.opendaylight.yangtools.yang.common.Revision) ModuleStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) ModuleCtxToSourceIdentifier(org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) SourceException(org.opendaylight.yangtools.yang.parser.spi.source.SourceException) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) PrefixStatement(org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement)

Example 44 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project mdsal by opendaylight.

the class YangSourceDefinition method of.

public static Optional<YangSourceDefinition> of(final Module module) {
    final ModuleEffectiveStatement effective = module.asEffectiveStatement();
    final ModuleStatement declared = effective.getDeclared();
    if (declared != null) {
        return Optional.of(new Single(effective, module));
    }
    return Optional.empty();
}
Also used : ModuleStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)

Example 45 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project mdsal by opendaylight.

the class GeneratorReactor method mapToGenerator.

// Map a statement to the corresponding generator
@NonNull
private AbstractTypeAwareGenerator<?, ?, ?> mapToGenerator() {
    // Some preliminaries first: we need to be in the correct module to walk the path
    final ModuleEffectiveStatement module = inferenceStack.currentModule();
    final ModuleGenerator gen = verifyNotNull(generators.get(module.localQNameModule()), "Cannot find generator for %s", module);
    // Now kick of the search
    final List<EffectiveStatement<?, ?>> stmtPath = inferenceStack.toInference().statementPath();
    final AbstractExplicitGenerator<?, ?> found = gen.findGenerator(stmtPath);
    if (found instanceof AbstractTypeAwareGenerator) {
        return (AbstractTypeAwareGenerator<?, ?, ?>) found;
    }
    throw new VerifyException("Statements " + stmtPath + " resulted in unexpected " + found);
}
Also used : ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) EffectiveStatement(org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement) VerifyException(com.google.common.base.VerifyException) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)45 Test (org.junit.Test)28 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)20 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)12 NonNull (org.eclipse.jdt.annotation.NonNull)9 Objects.requireNonNull (java.util.Objects.requireNonNull)8 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)5 QName (org.opendaylight.yangtools.yang.common.QName)4 LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)4 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)4 SubmoduleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement)4 ModuleStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Revision (org.opendaylight.yangtools.yang.common.Revision)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2