@Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(typePrereq), stmt.getStatementSourceReference(), "Type [%s] was not found.", typeQName); } });
@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 void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(requiresCtxPrerequisite), stmt.getStatementSourceReference(), "Included submodule '%s' was not found: ", stmt.getStatementArgument()); } });
@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 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; }
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()); }
@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; }
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()); }
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); }
private static void validateNodeCanBeCopiedByAugment(final StmtContext<?, ?, ?> sourceCtx, final StatementContextBase<?, ?, ?> targetCtx, final CopyType typeOfCopy, final boolean skipCheckOfMandatoryNodes) { if (WhenStatement.class.equals(sourceCtx.getPublicDefinition().getDeclaredRepresentationClass())) { return; } if (!skipCheckOfMandatoryNodes && typeOfCopy == CopyType.ADDED_BY_AUGMENTATION && reguiredCheckOfMandatoryNodes(sourceCtx, targetCtx)) { checkForMandatoryNodes(sourceCtx); } // Data definition statements must not collide on their namespace if (DataDefinitionStatement.class.isAssignableFrom( sourceCtx.getPublicDefinition().getDeclaredRepresentationClass())) { for (final StmtContext<?, ?, ?> subStatement : targetCtx.allSubstatements()) { if (DataDefinitionStatement.class.isAssignableFrom( subStatement.getPublicDefinition().getDeclaredRepresentationClass())) { InferenceException.throwIf( Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument()), sourceCtx.getStatementSourceReference(), "An augment cannot add node named '%s' because this name is already used in target", sourceCtx.rawStatementArgument()); } } } }
private static void addStatement(final Mutable<?, ?, ?> stmtCtxToBeAdded, final StatementContextBase<?, ?, ?> targetCtx) { if (!StmtContextUtils.isUnknownStatement(stmtCtxToBeAdded)) { final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.getPublicDefinition(); if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded) && YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition())) { for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) { InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.getPublicDefinition()), stmtCtxToBeAdded.getStatementSourceReference(), "Deviation cannot add substatement %s to target node %s because it is already defined " + "in target and can appear only once.", stmtToBeAdded.getStatementName(), targetCtx.getStatementArgument()); } } } copyStatement(stmtCtxToBeAdded, targetCtx); }
@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; }