import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
}
if (typeOfCopy == CopyType.ADDED_BY_AUGMENTATION && reguiredCheckOfMandatoryNodes(sourceCtx, targetCtx)) {
- final List<StatementContextBase<?, ?, ?>> sourceSubStatements = new Builder<StatementContextBase<?, ?, ?>>()
- .addAll(sourceCtx.declaredSubstatements()).addAll(sourceCtx.effectiveSubstatements()).build();
-
- for (final StatementContextBase<?, ?, ?> sourceSubStatement : sourceSubStatements) {
- InferenceException.throwIf(MandatoryStatement.class.equals(sourceSubStatement.getPublicDefinition()
- .getDeclaredRepresentationClass()), sourceCtx.getStatementSourceReference(),
- "An augment cannot add node '%s' because it is mandatory and in module different from target",
- sourceCtx.rawStatementArgument());
- }
+ checkForMandatoryNodes(sourceCtx);
}
final List<StatementContextBase<?, ?, ?>> targetSubStatements = new Builder<StatementContextBase<?, ?, ?>>()
}
}
+ private static void checkForMandatoryNodes(final StatementContextBase<?, ?, ?> sourceCtx) {
+ if (StmtContextUtils.isNonPresenceContainer(sourceCtx)) {
+ /*
+ * We need to iterate over both declared and effective sub-statements,
+ * because a mandatory node can be:
+ * a) declared in augment body
+ * b) added to augment body also via uses of a grouping and
+ * such sub-statements are stored in effective sub-statements collection.
+ */
+ for (final StatementContextBase<?, ?, ?> sourceSubStatement : Iterables.concat(
+ sourceCtx.declaredSubstatements(), sourceCtx.declaredSubstatements())) {
+ checkForMandatoryNodes(sourceSubStatement);
+ }
+ }
+
+ InferenceException.throwIf(StmtContextUtils.isMandatoryNode(sourceCtx),
+ sourceCtx.getStatementSourceReference(),
+ "An augment cannot add node '%s' because it is mandatory and in module different than target",
+ sourceCtx.rawStatementArgument());
+ }
+
private static boolean reguiredCheckOfMandatoryNodes(final StatementContextBase<?, ?, ?> sourceCtx,
StatementContextBase<?, ?, ?> targetCtx) {
/*
* the same module, return false and skip mandatory nodes
* validation
*/
- if (Utils.isPresenceContainer(targetCtx)) {
+ if (StmtContextUtils.isPresenceContainer(targetCtx)) {
return false;
}
}