/** * Checks whether a statement context is a statement of supplied statement * definition and whether it is not mandatory leaf, choice, anyxml, list or * leaf-list according to RFC6020. * * @param stmtCtx * statement context * @param stmtDef * statement definition * @return true if supplied statement context is a statement of supplied * statement definition and if it is not mandatory leaf, choice, * anyxml, list or leaf-list according to RFC6020 */ public static boolean isNotMandatoryNodeOfType(final StmtContext<?, ?, ?> stmtCtx, final StatementDefinition stmtDef) { return stmtCtx.getPublicDefinition().equals(stmtDef) && !isMandatoryNode(stmtCtx); }
private static void checkForMandatoryNodes(final StmtContext<?, ?, ?> 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. */ sourceCtx.allSubstatementsStream().forEach(AbstractAugmentStatementSupport::checkForMandatoryNodes); } 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()); }