Search in sources :

Example 1 with StatementDefinition

use of org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition in project yangtools by opendaylight.

the class YangTextSnippetIterator method pushStatement.

/**
 * Push a statement to the stack. A successfully-pushed statement results in strings not being empty.
 *
 * @param stmt Statement to push into strings
 * @return True if the statement was pushed. False if the statement was suppressed.
 */
private boolean pushStatement(final DeclaredStatement<?> stmt) {
    final StatementDefinition def = stmt.statementDefinition();
    if (ignoredStatements.contains(def)) {
        return false;
    }
    final Collection<? extends DeclaredStatement<?>> children = stmt.declaredSubstatements();
    if (omitDefaultStatements && children.isEmpty()) {
        // This statement does not have substatements, check if its value matches the declared default, like
        // "config true", "mandatory false", etc.
        final String suppressValue = DEFAULT_STATEMENTS.get(def);
        if (suppressValue != null && suppressValue.equals(stmt.rawArgument())) {
            return false;
        }
    }
    // New statement: push indent
    addIndent();
    // Add statement prefixed with namespace if needed
    final Optional<String> prefix = resolver.findPrefix(stmt);
    if (prefix.isPresent()) {
        strings.add(prefix.get());
        strings.add(":");
    }
    strings.add(def.getStatementName().getLocalName());
    // Add argument, quoted and properly indented if need be
    addArgument(def, stmt.rawArgument());
    if (!children.isEmpty()) {
        // Open the statement and push child iterator
        strings.add(" {\n");
        stack.push(children.iterator());
    } else {
        // Close the statement
        strings.add(";\n");
    }
    return true;
}
Also used : StatementDefinition(org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition)

Example 2 with StatementDefinition

use of org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition in project yangtools by opendaylight.

the class AbstractDeviateStatementSupport method replaceStatement.

private static void replaceStatement(final StmtContext<?, ?, ?> stmtCtxToBeReplaced, final Mutable<?, ?, ?> targetCtx) {
    final StatementDefinition stmtToBeReplaced = stmtCtxToBeReplaced.publicDefinition();
    if (YangStmtMapping.DEFAULT.equals(stmtToBeReplaced) && YangStmtMapping.LEAF_LIST.equals(targetCtx.publicDefinition())) {
        LOG.error("Deviation cannot replace substatement {} in target leaf-list {} because a leaf-list can " + "have multiple default statements. At line: {}", stmtToBeReplaced.getStatementName(), targetCtx.argument(), stmtCtxToBeReplaced.sourceReference());
        return;
    }
    for (StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.effectiveSubstatements()) {
        if (stmtToBeReplaced.equals(targetCtxSubstatement.publicDefinition())) {
            targetCtx.removeStatementFromEffectiveSubstatements(stmtToBeReplaced);
            copyStatement(stmtCtxToBeReplaced, targetCtx);
            return;
        }
    }
    for (Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
        if (stmtToBeReplaced.equals(targetCtxSubstatement.publicDefinition())) {
            targetCtxSubstatement.setUnsupported();
            copyStatement(stmtCtxToBeReplaced, targetCtx);
            return;
        }
    }
    // However, according to RFC6020/RFC7950, these properties are always implicitly present.
    if (IMPLICIT_STATEMENTS.contains(stmtToBeReplaced)) {
        addStatement(stmtCtxToBeReplaced, targetCtx);
        return;
    }
    throw new InferenceException(stmtCtxToBeReplaced, "Deviation cannot replace substatement %s in target node %s because it does not exist in target node.", stmtToBeReplaced.getStatementName(), targetCtx.argument());
}
Also used : StatementDefinition(org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition) InferenceException(org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException)

Example 3 with StatementDefinition

use of org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition in project yangtools by opendaylight.

the class ListStatementSupport method isInstantied.

private static boolean isInstantied(final EffectiveStmtCtx ctx) {
    Parent parent = ctx.effectiveParent();
    while (parent != null) {
        final StatementDefinition parentDef = parent.publicDefinition();
        if (UNINSTANTIATED_DATATREE_STATEMENTS.contains(parentDef)) {
            return false;
        }
        final Parent grandParent = parent.effectiveParent();
        if (YangStmtMapping.AUGMENT == parentDef && grandParent != null) {
            // If this is an augment statement and its parent is either a 'module' or 'submodule' statement, we are
            // dealing with an uninstantiated context.
            final StatementDefinition grandParentDef = grandParent.publicDefinition();
            if (YangStmtMapping.MODULE == grandParentDef || YangStmtMapping.SUBMODULE == grandParentDef) {
                return false;
            }
        }
        parent = grandParent;
    }
    return true;
}
Also used : StatementDefinition(org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition) Parent(org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Parent)

Example 4 with StatementDefinition

use of org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition in project yangtools by opendaylight.

the class StmtContextUtils method disallowIfFeatureAndWhenOnListKeys.

private static void disallowIfFeatureAndWhenOnListKeys(final StmtContext<?, ?, ?> leafStmtCtx) {
    leafStmtCtx.allSubstatements().forEach(leafSubstmtCtx -> {
        final StatementDefinition statementDef = leafSubstmtCtx.publicDefinition();
        SourceException.throwIf(YangStmtMapping.IF_FEATURE.equals(statementDef) || YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx, "%s statement is not allowed in %s leaf statement which is specified as a list key.", statementDef.getStatementName(), leafStmtCtx.argument());
    });
}
Also used : StatementDefinition(org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition)

Example 5 with StatementDefinition

use of org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition in project yangtools by opendaylight.

the class AnnotationStatementSupport method onStatementAdded.

@Override
public void onStatementAdded(final Mutable<QName, AnnotationStatement, AnnotationEffectiveStatement> stmt) {
    final StatementDefinition parentDef = stmt.coerceParentContext().publicDefinition();
    SourceException.throwIf(YangStmtMapping.MODULE != parentDef && YangStmtMapping.SUBMODULE != parentDef, stmt, "Annotations may only be defined at root of either a module or a submodule");
}
Also used : StatementDefinition(org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition)

Aggregations

StatementDefinition (org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition)15 QNameToStatementDefinition (org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition)4 QName (org.opendaylight.yangtools.yang.common.QName)2 ArgumentDefinition (org.opendaylight.yangtools.yang.model.api.meta.ArgumentDefinition)2 ResumedStatement (org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter.ResumedStatement)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)1 XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)1 SchemaNodeIdentifier (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier)1 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)1 Descendant (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant)1 ExtensionNamespace (org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace)1 Parent (org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Parent)1 InferenceException (org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException)1 ModuleCtxToModuleQName (org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName)1