Search in sources :

Example 1 with BaseEffectiveStatement

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

the class AbstractTypeObjectGenerator method bindTypeDefinition.

void bindTypeDefinition(final GeneratorContext context) {
    if (baseGen != null) {
        // We have registered with baseGen, it will push the type to us
        return;
    }
    final QName arg = type.argument();
    if (TypeDefinitions.IDENTITYREF.equals(arg)) {
        refType = TypeReference.identityRef(type.streamEffectiveSubstatements(BaseEffectiveStatement.class).map(BaseEffectiveStatement::argument).map(context::resolveIdentity).collect(Collectors.toUnmodifiableList()));
    } else if (TypeDefinitions.LEAFREF.equals(arg)) {
        final AbstractTypeObjectGenerator<?, ?> targetGenerator = context.resolveLeafref(type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow());
        checkArgument(targetGenerator != this, "Effective model contains self-referencing leaf %s", statement().argument());
        refType = TypeReference.leafRef(targetGenerator);
    } else if (TypeDefinitions.UNION.equals(arg)) {
        unionDependencies = new UnionDependencies(type, context);
        LOG.trace("Resolved union {} to dependencies {}", type, unionDependencies);
    }
    LOG.trace("Resolved base {} to generator {}", type, refType);
    bindDerivedGenerators(refType);
}
Also used : BaseEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement) PathEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement) QName(org.opendaylight.yangtools.yang.common.QName)

Example 2 with BaseEffectiveStatement

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

the class IdentityRefSpecificationSupport method createEffective.

@Override
protected EffectiveStatement<QName, IdentityRefSpecification> createEffective(final Current<QName, IdentityRefSpecification> stmt, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    if (substatements.isEmpty()) {
        throw noBase(stmt);
    }
    final IdentityrefTypeBuilder builder = BaseTypes.identityrefTypeBuilder(stmt.argumentAsTypeQName());
    for (final EffectiveStatement<?, ?> subStmt : substatements) {
        if (subStmt instanceof BaseEffectiveStatement) {
            final QName identityQName = ((BaseEffectiveStatement) subStmt).argument();
            final IdentityEffectiveStatement baseIdentity = verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, identityQName)).buildEffective();
            verify(baseIdentity instanceof IdentitySchemaNode, "Statement %s is not an IdentitySchemaNode", baseIdentity);
            builder.addIdentity((IdentitySchemaNode) baseIdentity);
        }
    }
    return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
Also used : BaseEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement) IdentityEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement) IdentityrefTypeBuilder(org.opendaylight.yangtools.yang.model.ri.type.IdentityrefTypeBuilder) QName(org.opendaylight.yangtools.yang.common.QName) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)

Example 3 with BaseEffectiveStatement

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

the class IdentityStatementSupport method createEffective.

@Override
protected IdentityEffectiveStatement createEffective(final Current<QName, IdentityStatement> stmt, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    if (substatements.isEmpty()) {
        return EffectiveStatements.createIdentity(stmt.declared());
    }
    final List<IdentitySchemaNode> identities = new ArrayList<>();
    for (EffectiveStatement<?, ?> substatement : substatements) {
        if (substatement instanceof BaseEffectiveStatement) {
            final QName qname = ((BaseEffectiveStatement) substatement).argument();
            final IdentityEffectiveStatement identity = verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, qname), "Failed to find identity %s", qname).buildEffective();
            verify(identity instanceof IdentitySchemaNode, "%s is not a IdentitySchemaNode", identity);
            identities.add((IdentitySchemaNode) identity);
        }
    }
    return EffectiveStatements.createIdentity(stmt.declared(), new FlagsBuilder().setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT)).toFlags(), substatements, ImmutableSet.copyOf(identities));
}
Also used : BaseEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement) IdentityEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement) QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) FlagsBuilder(org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode) StatusEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement)

Aggregations

QName (org.opendaylight.yangtools.yang.common.QName)3 BaseEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement)3 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)2 IdentityEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement)2 ArrayList (java.util.ArrayList)1 PathEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement)1 StatusEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement)1 IdentityrefTypeBuilder (org.opendaylight.yangtools.yang.model.ri.type.IdentityrefTypeBuilder)1 FlagsBuilder (org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder)1