@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { if (failed.contains(imported)) { throw new InferenceException(stmt.getStatementSourceReference(), "Imported module [%s] was not found.", moduleName); } } });
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(sourceGroupingPre), usesNode.getStatementSourceReference(), "Grouping '%s' was not resolved.", groupingName); throw new InferenceException("Unknown error occurred.", usesNode.getStatementSourceReference()); } });
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(typePrereq), stmt.getStatementSourceReference(), "Type [%s] was not found.", typeQName); } });
defaultCase = InferenceException.throwIfNull(cases.get(qname), ctx.getStatementSourceReference(), "Default statement refers to missing case %s", qname); } else {
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(imported), stmt.getStatementSourceReference(), "Imported module [%s] was not found.", moduleName); } });
@Override public final void onFullDefinitionDeclared(final Mutable<String, IdentityRefSpecification, EffectiveStatement<String, IdentityRefSpecification>> stmt) { super.onFullDefinitionDeclared(stmt); final Collection<StmtContext<QName, BaseStatement, ?>> baseStatements = StmtContextUtils.findAllDeclaredSubstatements(stmt, BaseStatement.class); for (StmtContext<QName, BaseStatement, ?> baseStmt : baseStatements) { final QName baseIdentity = baseStmt.coerceStatementArgument(); final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(IdentityNamespace.class, baseIdentity); InferenceException.throwIfNull(stmtCtx, stmt.getStatementSourceReference(), "Referenced base identity '%s' doesn't exist in given scope (module, imported modules, submodules)", baseIdentity.getLocalName()); } } }
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { if (failed.contains(imported)) { throw new InferenceException(stmt.getStatementSourceReference(), "Unable to find module compatible with requested import [%s(%s)].", moduleName, getRequestedImportVersionString(stmt)); } } });
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(requiresCtxPrerequisite), stmt.getStatementSourceReference(), "Included submodule '%s' was not found: ", stmt.getStatementArgument()); } });
InferenceException.throwIfNull(qnameModule, ctx.getStatementSourceReference(), "Cannot resolve QNameModule for '%s'", value), localName);
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { if (failed.contains(belongsToPrereq)) { throw new InferenceException(belongsToCtx.getStatementSourceReference(), "Module '%s' from belongs-to was not found", belongsToCtx.getStatementArgument()); } } });
@Override public List<ValueRange> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { final List<ValueRange> ranges = new ArrayList<>(); for (final String singleRange : ArgumentUtils.PIPE_SPLITTER.split(value)) { final Iterator<String> boundaries = ArgumentUtils.TWO_DOTS_SPLITTER.split(singleRange).iterator(); final Number min = parseIntegerConstraintValue(ctx, boundaries.next()); final Number max; if (boundaries.hasNext()) { max = parseIntegerConstraintValue(ctx, boundaries.next()); // if min larger than max then error SourceException.throwIf(ArgumentUtils.compareNumbers(min, max) == 1, ctx.getStatementSourceReference(), "Length constraint %s has descending order of boundaries; should be ascending.", singleRange); SourceException.throwIf(boundaries.hasNext(), ctx.getStatementSourceReference(), "Wrong number of boundaries in length constraint %s.", singleRange); } else { max = min; } // some of intervals overlapping InferenceException.throwIf(ranges.size() > 1 && ArgumentUtils.compareNumbers(min, Iterables.getLast(ranges).upperBound()) != 1, ctx.getStatementSourceReference(), "Some of the length ranges in %s are not disjoint", value); ranges.add(ValueRange.of(min, max)); } return ranges; }
if (InferenceException.throwIfNull(def, ref, "Statement %s does not have type mapping defined.", name) .hasArgument()) { SourceException.throwIfNull(argument, ref, "Statement %s requires an argument", name);
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { throw new InferenceException(deviateStmtCtx.coerceParentContext().getStatementSourceReference(), "Deviation target '%s' not found.", deviationTarget); } });
@Override public List<ValueRange> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String rangeArgument) { final List<ValueRange> ranges = new ArrayList<>(); for (final String singleRange : ArgumentUtils.PIPE_SPLITTER.split(rangeArgument)) { final Iterator<String> boundaries = ArgumentUtils.TWO_DOTS_SPLITTER.split(singleRange).iterator(); final Number min = parseDecimalConstraintValue(ctx, boundaries.next()); final Number max; if (boundaries.hasNext()) { max = parseDecimalConstraintValue(ctx, boundaries.next()); // if min larger than max then error SourceException.throwIf(ArgumentUtils.compareNumbers(min, max) == 1, ctx.getStatementSourceReference(), "Range constraint %s has descending order of boundaries; should be ascending", singleRange); SourceException.throwIf(boundaries.hasNext(), ctx.getStatementSourceReference(), "Wrong number of boundaries in range constraint %s", singleRange); } else { max = min; } // some of intervals overlapping InferenceException.throwIf(ranges.size() > 1 && ArgumentUtils.compareNumbers(min, Iterables.getLast(ranges).upperBound()) != 1, ctx.getStatementSourceReference(), "Some of the value ranges in %s are not disjoint", rangeArgument); ranges.add(ValueRange.of(min, max)); } return ranges; }
Optional<SourceException> failModifiers(final ModelProcessingPhase identifier) { final List<SourceException> exceptions = new ArrayList<>(); for (final ModifierImpl mod : modifiers.get(identifier)) { try { mod.failModifier(); } catch (final SourceException e) { exceptions.add(e); } } if (exceptions.isEmpty()) { return Optional.empty(); } final String message = String.format("Yang model processing phase %s failed", identifier); final InferenceException e = new InferenceException(message, root.getStatementSourceReference(), exceptions.get(0)); exceptions.listIterator(1).forEachRemaining(e::addSuppressed); return Optional.of(e); }
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()); }
/** * Throw an instance of this exception if an expression evaluates to true. If the expression evaluates to false, * this method does nothing. * * @param expression Expression to be evaluated * @param source Statement source reference * @param format Format string, according to {@link String#format(String, Object...)}. * @param args Format string arguments, according to {@link String#format(String, Object...)} * @throws InferenceException if the expression evaluates to true. */ public static void throwIf(final boolean expression, final @NonNull StatementSourceReference source, final @NonNull String format, final Object... args) { if (expression) { throw new InferenceException(source, format, args); } } }
private static void validateDeviationTarget(final StmtContext<?, ?, ?> deviateSubStmtCtx, final StmtContext<?, ?, ?> targetCtx) { InferenceException.throwIf(!isSupportedDeviationTarget(deviateSubStmtCtx, targetCtx, targetCtx.getRootVersion()), deviateSubStmtCtx.getStatementSourceReference(), "%s is not a valid deviation target for substatement %s.", targetCtx.getStatementArgument(), deviateSubStmtCtx.getPublicDefinition().getStatementName()); }
@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { throw new InferenceException(baseStmtCtx.getStatementSourceReference(), "Unable to resolve identity %s and base identity %s", baseParentCtx.getStatementArgument(), baseStmtCtx.getStatementArgument()); } });
private static void performRefine(final Mutable<?, ?, ?> subStmtCtx, final StmtContext<?, ?, ?> usesParentCtx) { final Object refineArgument = subStmtCtx.getStatementArgument(); InferenceException.throwIf(!(refineArgument instanceof SchemaNodeIdentifier), subStmtCtx.getStatementSourceReference(), "Invalid refine argument %s. It must be instance of SchemaNodeIdentifier.", refineArgument); final Optional<StmtContext<?, ?, ?>> optRefineTargetCtx = ChildSchemaNodeNamespace.findNode( usesParentCtx, (SchemaNodeIdentifier) refineArgument); InferenceException.throwIf(!optRefineTargetCtx.isPresent(), subStmtCtx.getStatementSourceReference(), "Refine target node %s not found.", refineArgument); final StmtContext<?, ?, ?> refineTargetNodeCtx = optRefineTargetCtx.get(); if (StmtContextUtils.isUnknownStatement(refineTargetNodeCtx)) { LOG.trace("Refine node '{}' in uses '{}' has target node unknown statement '{}'. " + "Refine has been skipped. At line: {}", subStmtCtx.getStatementArgument(), subStmtCtx.coerceParentContext().getStatementArgument(), refineTargetNodeCtx.getStatementArgument(), subStmtCtx.getStatementSourceReference()); subStmtCtx.addAsEffectOfStatement(refineTargetNodeCtx); return; } Verify.verify(refineTargetNodeCtx instanceof StatementContextBase); addOrReplaceNodes(subStmtCtx, (StatementContextBase<?, ?, ?>) refineTargetNodeCtx); subStmtCtx.addAsEffectOfStatement(refineTargetNodeCtx); }