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;
}
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());
}
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;
}
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());
});
}
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");
}
Aggregations