private static boolean containsPresenceSubStmt(final StmtContext<?, ?, ?> stmtCtx) { return findFirstSubstatement(stmtCtx, PresenceStatement.class) != null; }
/** * Checks whether supplied statement context is conditional augment * statement. * * @param ctx * statement context to be checked * * @return true if supplied statement context is conditional augment * statement, otherwise false */ private static boolean isConditionalAugmentStmt(final StmtContext<?, ?, ?> ctx) { return ctx.getPublicDefinition() == YangStmtMapping.AUGMENT && StmtContextUtils.findFirstSubstatement(ctx, WhenStatement.class) != null; }
/** * Checks whether all of StmtContext's ancestors of specified type have a child of specified type. * * @param ctx StmtContext to be checked * @param ancestorType type of ancestor to search for * @param ancestorChildType type of child to search for in the specified ancestor type * @return true if all of StmtContext's ancestors of specified type have a child of specified type, otherwise false */ public static <A, D extends DeclaredStatement<A>> boolean hasAncestorOfTypeWithChildOfType( final StmtContext<?, ?, ?> ctx, final StatementDefinition ancestorType, final StatementDefinition ancestorChildType) { requireNonNull(ctx); requireNonNull(ancestorType); requireNonNull(ancestorChildType); StmtContext<?, ?, ?> current = ctx.coerceParentContext(); StmtContext<?, ?, ?> parent = current.getParentContext(); while (parent != null) { if (ancestorType.equals(current.getPublicDefinition())) { @SuppressWarnings("unchecked") final Class<D> ancestorChildTypeClass = (Class<D>) ancestorChildType.getDeclaredRepresentationClass(); if (findFirstSubstatement(current, ancestorChildTypeClass) == null) { return false; } } current = parent; parent = current.getParentContext(); } return true; }
@Override public boolean isConfiguration() { if (isIgnoringConfig()) { return true; } if (OptionalBoolean.isPresent(configuration)) { return OptionalBoolean.get(configuration); } final StmtContext<Boolean, ?, ?> configStatement = StmtContextUtils.findFirstSubstatement(this, ConfigStatement.class); final boolean parentIsConfig = parent.isConfiguration(); final boolean isConfig; if (configStatement != null) { isConfig = configStatement.coerceStatementArgument(); // Validity check: if parent is config=false this cannot be a config=true InferenceException.throwIf(isConfig && !parentIsConfig, getStatementSourceReference(), "Parent node has config=false, this node must not be specifed as config=true"); } else { // If "config" statement is not specified, the default is the same as the parent's "config" value. isConfig = parentIsConfig; } // Resolved, make sure we cache this return configuration = OptionalBoolean.of(isConfig); return isConfig; }