final String argument) {
final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
checkState(inProgressPhase != ModelProcessingPhase.EFFECTIVE_MODEL,
- "Declared statement cannot be added in effective phase at: %s", getStatementSourceReference());
+ "Declared statement cannot be added in effective phase at: %s", sourceReference());
final Optional<StatementSupport<?, ?, ?>> implicitParent =
definition().getImplicitParentFor(def.getPublicView());
@SuppressWarnings("unchecked")
final Mutable<QName, Y, Z> ret = (Mutable<QName, Y, Z>) copySubstatement((Mutable<?, ?, ?>) template)
- .orElseThrow(() -> new InferenceException(getStatementSourceReference(),
+ .orElseThrow(() -> new InferenceException(sourceReference(),
"Failed to materialize child %s template %s", qname, template));
ensureCompletedPhase(ret);
addMaterialized(template, ret);
final StatementSourceReference ref, final String rawArgument) {
super(def, ref, rawArgument);
this.sourceContext = requireNonNull(sourceContext);
- this.argument = def.parseArgumentValue(this, rawStatementArgument());
+ this.argument = def.parseArgumentValue(this, rawArgument());
}
RootStatementContext(final SourceSpecificContext sourceContext, final StatementDefinitionContext<A, D, E> def,
void setRootVersionImpl(final YangVersion version) {
checkArgument(sourceContext.globalContext().getSupportedVersions().contains(version),
- "Unsupported yang version %s in %s", version, getStatementSourceReference());
+ "Unsupported yang version %s in %s", version, sourceReference());
checkState(this.rootVersion == null, "Version of root %s has been already set to %s", argument,
this.rootVersion);
this.rootVersion = requireNonNull(version);
root.getRootIdentifier());
} else {
final QName rootStatement = root.definition().getStatementName();
- final String rootArgument = root.rawStatementArgument();
+ final String rootArgument = root.rawArgument();
checkState(Objects.equals(def.getStatementName(), rootStatement) && Objects.equals(argument, rootArgument),
"Root statement was already defined as '%s %s'.", rootStatement, rootArgument);
}
final String message = String.format("Yang model processing phase %s failed", identifier);
- final InferenceException e = new InferenceException(message, root.getStatementSourceReference(),
- exceptions.get(0));
+ final InferenceException e = new InferenceException(message, root.sourceReference(), exceptions.get(0));
exceptions.listIterator(1).forEachRemaining(e::addSuppressed);
return Optional.of(e);
final Iterator<StatementContextBase<?, ?, ?>> iterator = effective.iterator();
while (iterator.hasNext()) {
final Mutable<?, ?, ?> next = iterator.next();
- if (statementDef.equals(next.publicDefinition()) && statementArg.equals(next.rawStatementArgument())) {
+ if (statementDef.equals(next.publicDefinition()) && statementArg.equals(next.rawArgument())) {
iterator.remove();
}
}
// FIXME: YANGTOOLS-652: This does not need to be a SubstatementContext, in can be a specialized
// StatementContextBase subclass.
final Mutable<X, Y, Z> ret = new SubstatementContext<>(this, new StatementDefinitionContext<>(support),
- ImplicitSubstatement.of(getStatementSourceReference()), rawArg);
+ ImplicitSubstatement.of(sourceReference()), rawArg);
support.onStatementAdded(ret);
addEffectiveSubstatement(ret);
return ret;
final List<StatementContextBase<?, ?, ?>> effective, final int toAdd) {
// We cannot allow statement to be further mutated
verify(completedPhase != ModelProcessingPhase.EFFECTIVE_MODEL, "Cannot modify finished statement at %s",
- getStatementSourceReference());
+ sourceReference());
return beforeAddEffectiveStatementUnsafe(effective, toAdd);
}
final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION
|| inProgressPhase == ModelProcessingPhase.EFFECTIVE_MODEL,
- "Effective statement cannot be added in declared phase at: %s", getStatementSourceReference());
+ "Effective statement cannot be added in declared phase at: %s", sourceReference());
return effective.isEmpty() ? new ArrayList<>(toAdd) : effective;
}
* @throws NullPointerException if any of the arguments is null
*/
void addPhaseCompletedListener(final ModelProcessingPhase phase, final OnPhaseFinished listener) {
- checkNotNull(phase, "Statement context processing phase cannot be null at: %s", getStatementSourceReference());
- checkNotNull(listener, "Statement context phase listener cannot be null at: %s", getStatementSourceReference());
+ checkNotNull(phase, "Statement context processing phase cannot be null at: %s", sourceReference());
+ checkNotNull(listener, "Statement context phase listener cannot be null at: %s", sourceReference());
ModelProcessingPhase finishedPhase = completedPhase;
while (finishedPhase != null) {
ModelProcessingPhase finishedPhase = completedPhase;
while (finishedPhase != null) {
checkState(!phase.equals(finishedPhase), "Mutation registered after phase was completed at: %s",
- getStatementSourceReference());
+ sourceReference());
finishedPhase = finishedPhase.getPreviousPhase();
}
if (implicitParent.isPresent()) {
final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(implicitParent.get());
- result = new SubstatementContext(this, def, original.getStatementSourceReference(),
- original.rawStatementArgument(), original.getStatementArgument(), type);
+ result = new SubstatementContext(this, def, original.sourceReference(), original.rawArgument(),
+ original.argument(), type);
final CopyType childCopyType;
switch (type) {
final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(optImplicit.get());
final CopyType type = original.getCopyHistory().getLastOperation();
final SubstatementContext<?, ?, ?> result = new SubstatementContext(original.getParentContext(), def,
- original.getStatementSourceReference(), original.rawStatementArgument(), original.getStatementArgument(),
- type);
+ original.sourceReference(), original.rawArgument(), original.argument(), type);
result.addEffectiveSubstatement(original.reparent(result));
result.setCompletedPhase(original.getCompletedPhase());
isConfig = optConfig.orElseThrow();
if (isConfig) {
// Validity check: if parent is config=false this cannot be a config=true
- InferenceException.throwIf(!parent.isConfiguration(), getStatementSourceReference(),
+ InferenceException.throwIf(!parent.isConfiguration(), sourceReference(),
"Parent node has config=false, this node must not be specifed as config=true");
}
} else {
}
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("definition", definition).add("rawArgument", rawStatementArgument());
+ return toStringHelper.add("definition", definition).add("rawArgument", rawArgument());
}
}
final StatementSourceReference ref, final String rawArgument) {
super(def, ref, rawArgument);
this.parent = requireNonNull(parent, "Parent must not be null");
- this.argument = def.parseArgumentValue(this, rawStatementArgument());
+ this.argument = def.parseArgumentValue(this, rawArgument());
}
// FIXME: YANGTOOLS-784: this constructor is only called in contexts where a different implementation
final String name) {
return SourceException.throwIfNull(
StmtContextUtils.firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class),
- stmt.getStatementSourceReference(), "Unable to resolve prefix for %s %s.", type, name);
+ stmt.sourceReference(), "Unable to resolve prefix for %s %s.", type, name);
}
// Alright. this is quite ugly
return Boolean.FALSE;
} else {
final StatementDefinition def = ctx.publicDefinition();
- throw new SourceException(ctx.getStatementSourceReference(),
+ throw new SourceException(ctx.sourceReference(),
"Invalid '%s' statement %s '%s', it can be either 'true' or 'false'",
def.getStatementName(), def.getArgumentDefinition().get().getArgumentName(), input);
}
try {
qnames.add(StmtContextUtils.parseNodeIdentifier(ctx, nodeName));
} catch (final RuntimeException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
+ throw new SourceException(ctx.sourceReference(), e,
"Failed to parse node '%s' in path '%s'", nodeName, path);
}
}
if (qnames.isEmpty()) {
- throw new SourceException("Schema node identifier must not be empty", ctx.getStatementSourceReference());
+ throw new SourceException("Schema node identifier must not be empty", ctx.sourceReference());
}
return qnames;
}
try {
parsed = parser.parseExpression(xpath);
} catch (XPathExpressionException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
- "Argument \"%s\" is not valid XPath string", xpath);
+ throw new SourceException(ctx.sourceReference(), e, "Argument \"%s\" is not valid XPath string", xpath);
}
if (ctx.getRootVersion().compareTo(parsed.getYangVersion()) < 0) {
LOG.warn("{} features required in {} context to parse expression '{}' [at {}]",
parsed.getYangVersion().getReference(), ctx.getRootVersion().getReference(), xpath,
- ctx.getStatementSourceReference());
+ ctx.sourceReference());
}
return parsed;
}
@Override
public final SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
SourceException.throwIf(PATH_REL_PATTERN1.matcher(value).matches()
- || PATH_REL_PATTERN2.matcher(value).matches(), ctx.getStatementSourceReference(),
+ || PATH_REL_PATTERN2.matcher(value).matches(), ctx.sourceReference(),
"Augment argument \'%s\' is not valid, it can be only absolute path; or descendant if used in uses",
value);
copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx);
augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx);
} catch (final SourceException e) {
- LOG.warn("Failed to add augmentation {} defined at {}",
- augmentTargetCtx.getStatementSourceReference(),
- augmentSourceCtx.getStatementSourceReference(), e);
+ LOG.warn("Failed to add augmentation {} defined at {}", augmentTargetCtx.sourceReference(),
+ augmentSourceCtx.sourceReference(), e);
}
}
if (targetNode.isPresent() && StmtContextUtils.isUnknownStatement(targetNode.get())) {
augmentNode.setIsSupportedToBuildEffective(false);
LOG.warn("Uses-augment to unknown node {}. Augmentation has not been performed. At line: {}",
- augmentArg, augmentNode.getStatementSourceReference());
+ augmentArg, augmentNode.sourceReference());
return;
}
}
- throw new InferenceException(augmentNode.getStatementSourceReference(),
- "Augment target '%s' not found", augmentNode.getStatementArgument());
+ throw new InferenceException(augmentNode.sourceReference(), "Augment target '%s' not found",
+ augmentNode.getStatementArgument());
}
});
}
if (sourceCtx.producesDeclared(DataDefinitionStatement.class)) {
for (final StmtContext<?, ?, ?> subStatement : targetCtx.allSubstatements()) {
if (subStatement.producesDeclared(DataDefinitionStatement.class)) {
- InferenceException.throwIf(
- Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument()),
- sourceCtx.getStatementSourceReference(),
+ InferenceException.throwIf(Objects.equals(sourceCtx.argument(), subStatement.argument()),
+ sourceCtx.sourceReference(),
"An augment cannot add node named '%s' because this name is already used in target",
- sourceCtx.rawStatementArgument());
+ sourceCtx.rawArgument());
}
}
}
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());
+ InferenceException.throwIf(StmtContextUtils.isMandatoryNode(sourceCtx), sourceCtx.sourceReference(),
+ "An augment cannot add node '%s' because it is mandatory and in module different than target",
+ sourceCtx.rawArgument());
}
private static boolean requireCheckOfMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx,
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- throw new InferenceException(baseStmtCtx.getStatementSourceReference(),
+ throw new InferenceException(baseStmtCtx.sourceReference(),
"Unable to resolve identity %s and base identity %s",
baseParentCtx.getStatementArgument(), baseStmtCtx.getStatementArgument());
}
@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());
+ throw new InferenceException(belongsToCtx.sourceReference(),
+ "Module '%s' from belongs-to was not found", belongsToCtx.argument());
}
}
});
try {
qname = QName.create(stmt.getArgument(), defaultArg);
} catch (IllegalArgumentException e) {
- throw new SourceException(stmt.sourceReference(), "Default statement has invalid name '%s'",
- defaultArg, e);
+ throw new SourceException(stmt.sourceReference(), "Default statement has invalid name '%s'", defaultArg,
+ e);
}
// FIXME: this does not work with submodules, as they are
@Override
public final DeviateKind parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value),
- ctx.getStatementSourceReference(), "String '%s' is not valid deviate argument", value);
+ return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value), ctx.sourceReference(),
+ "String '%s' is not valid deviate argument", value);
}
@Override
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- throw new InferenceException(deviateStmtCtx.coerceParentContext().getStatementSourceReference(),
+ throw new InferenceException(deviateStmtCtx.coerceParentContext().sourceReference(),
"Deviation target '%s' not found.", deviationTarget);
}
});
&& YangStmtMapping.LEAF.equals(targetCtx.publicDefinition())) {
for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) {
InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.publicDefinition()),
- stmtCtxToBeAdded.getStatementSourceReference(),
+ stmtCtxToBeAdded.sourceReference(),
"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());
&& YangStmtMapping.LEAF_LIST.equals(targetCtx.publicDefinition())) {
LOG.error("Deviation cannot replace substatement {} in target leaf-list {} because a leaf-list can "
+ "have multiple default statements. At line: {}", stmtToBeReplaced.getStatementName(),
- targetCtx.getStatementArgument(), stmtCtxToBeReplaced.getStatementSourceReference());
+ targetCtx.getStatementArgument(), stmtCtxToBeReplaced.sourceReference());
return;
}
return;
}
- throw new InferenceException(stmtCtxToBeReplaced.getStatementSourceReference(), "Deviation cannot replace "
+ throw new InferenceException(stmtCtxToBeReplaced.sourceReference(), "Deviation cannot replace "
+ "substatement %s in target node %s because it does not exist in target node.",
stmtToBeReplaced.getStatementName(), targetCtx.getStatementArgument());
}
LOG.error("Deviation cannot delete substatement {} with argument '{}' in target node {} because it does "
+ "not exist in the target node. At line: {}", stmtToBeDeleted.getStatementName(), stmtArgument,
- targetCtx.getStatementArgument(), stmtCtxToBeDeleted.getStatementSourceReference());
+ targetCtx.getStatementArgument(), stmtCtxToBeDeleted.sourceReference());
}
private static void copyStatement(final Mutable<?, ?, ?> stmtCtxToBeCopied,
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.publicDefinition().getStatementName());
+ targetCtx.getRootVersion()), deviateSubStmtCtx.sourceReference(),
+ "%s is not a valid deviation target for substatement %s.", targetCtx.argument(),
+ deviateSubStmtCtx.publicDefinition().getStatementName());
}
private static boolean isSupportedDeviationTarget(final StmtContext<?, ?, ?> deviateSubstatementCtx,
.getModule();
if (currentModule.equals(targetModule)) {
- throw new InferenceException(ctx.getStatementSourceReference(),
+ throw new InferenceException(ctx.sourceReference(),
"Deviation must not target the same module as the one it is defined in: %s", currentModule);
}
}
@Override
protected UnrecognizedStatement createDeclared(final StmtContext<String, UnrecognizedStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new UnrecognizedStatementImpl(ctx.rawStatementArgument(), ctx.publicDefinition(), substatements);
+ return new UnrecognizedStatementImpl(ctx.rawArgument(), ctx.publicDefinition(), substatements);
}
@Override
try {
fractionDigits = Integer.parseInt(value);
} catch (NumberFormatException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
- "%s is not valid fraction-digits integer argument", value);
+ throw new SourceException(ctx.sourceReference(), e, "%s is not valid fraction-digits integer argument",
+ value);
}
if (fractionDigits < 1 || fractionDigits > 18) {
throw new SourceException("fraction-digits argument should be integer within [1..18]",
- ctx.getStatementSourceReference());
+ ctx.sourceReference());
}
return fractionDigits;
}
private static void checkConflict(final StmtContext<?, ?, ?> parent, final StmtContext<QName, ?, ?> stmt) {
final QName arg = stmt.coerceStatementArgument();
final StmtContext<?, ?, ?> existing = parent.getFromNamespace(GroupingNamespace.class, arg);
- SourceException.throwIf(existing != null, stmt.getStatementSourceReference(), "Duplicate name for grouping %s",
- arg);
+ SourceException.throwIf(existing != null, stmt.sourceReference(), "Duplicate name for grouping %s", arg);
}
}
\ No newline at end of file
final Mutable<QName, IdentityStatement, IdentityEffectiveStatement> stmt) {
final QName qname = stmt.coerceStatementArgument();
final StmtContext<?, ?, ?> prev = stmt.getFromNamespace(IdentityNamespace.class, qname);
- SourceException.throwIf(prev != null, stmt.getStatementSourceReference(), "Duplicate identity definition %s",
- qname);
+ SourceException.throwIf(prev != null, stmt.sourceReference(), "Duplicate identity definition %s", qname);
stmt.addToNs(IdentityNamespace.class, qname, stmt);
}
unresolvedFeatures.add(verifyNotNull(backRef.get(prereq)));
}
- throw new InferenceException(stmt.getStatementSourceReference(),
- "Failed to resolve feature references %s in \"%s\"", unresolvedFeatures,
- stmt.rawStatementArgument());
+ throw new InferenceException(stmt.sourceReference(),
+ "Failed to resolve feature references %s in \"%s\"", unresolvedFeatures, stmt.rawArgument());
}
});
}
final IfFeatureExpressionLexer lexer = new IfFeatureExpressionLexer(CharStreams.fromString(value));
final IfFeatureExpressionParser parser = new IfFeatureExpressionParser(new CommonTokenStream(lexer));
final IfFeatureExpr ret = new IfFeaturePredicateVisitor(ctx).visit(SourceExceptionParser.parse(lexer, parser,
- parser::if_feature_expr, ctx.getStatementSourceReference()));
+ parser::if_feature_expr, ctx.sourceReference()));
return ret;
}
}
throw new SourceException("Unexpected grammar context during parsing of IfFeature expression. "
- + "Most probably IfFeature grammar has been changed.", stmtCtx.getStatementSourceReference());
+ + "Most probably IfFeature grammar has been changed.", stmtCtx.sourceReference());
}
@Override
moduleName);
Verify.verifyNotNull(importedModuleNamespace);
final String impPrefix = SourceException.throwIfNull(
- firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class),
- stmt.getStatementSourceReference(), "Missing prefix statement");
+ firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt.sourceReference(),
+ "Missing prefix statement");
stmt.addToNs(ImpPrefixToNamespace.class, impPrefix, importedModuleNamespace);
}
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- InferenceException.throwIf(failed.contains(imported), stmt.getStatementSourceReference(),
+ InferenceException.throwIf(failed.contains(imported), stmt.sourceReference(),
"Imported module [%s] was not found.", moduleName);
}
});
final StmtContext<?, ?, ?> importedModule = imported.resolve(ctx);
final QNameModule mod = InferenceException.throwIfNull(stmt.getFromNamespace(
- ModuleCtxToModuleQName.class, importedModule), stmt.getStatementSourceReference(),
+ ModuleCtxToModuleQName.class, importedModule), stmt.sourceReference(),
"Failed to find module of %s", importedModule);
linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class,
@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);
+ throw new InferenceException(stmt.sourceReference(), "Imported module [%s] was not found.",
+ moduleName);
}
}
});
stmt.addToNs(ImportPrefixToSemVerSourceIdentifier.class, impPrefix, semVerModuleIdentifier);
final QNameModule mod = InferenceException.throwIfNull(stmt.getFromNamespace(
- ModuleCtxToModuleQName.class, importedModule), stmt.getStatementSourceReference(),
+ ModuleCtxToModuleQName.class, importedModule), stmt.sourceReference(),
"Failed to find module of %s", importedModule);
final URI modNs = firstAttributeOf(importedModule.declaredSubstatements(),
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
if (failed.contains(imported)) {
- throw new InferenceException(stmt.getStatementSourceReference(),
+ throw new InferenceException(stmt.sourceReference(),
"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(),
+ InferenceException.throwIf(failed.contains(requiresCtxPrerequisite), stmt.sourceReference(),
"Included submodule '%s' was not found: ", stmt.getStatementArgument());
}
});
// Throws NPE on nulls, retains first inserted value, cannot be modified
final ImmutableSet<QName> ret = builder.build();
- SourceException.throwIf(ret.size() != tokens, ctx.getStatementSourceReference(),
- "Key argument '%s' contains duplicates", value);
+ SourceException.throwIf(ret.size() != tokens, ctx.sourceReference(), "Key argument '%s' contains duplicates",
+ value);
return ret;
}
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);
+ SourceException.throwIf(ArgumentUtils.compareNumbers(min, max) == 1, ctx.sourceReference(),
+ "Length constraint %s has descending order of boundaries; should be ascending.", singleRange);
+ SourceException.throwIf(boundaries.hasNext(), ctx.sourceReference(),
+ "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);
+ ctx.sourceReference(), "Some of the length ranges in %s are not disjoint", value);
ranges.add(ValueRange.of(min, max));
}
try {
return new BigInteger(value);
} catch (final NumberFormatException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e, "Value %s is not a valid integer", value);
+ throw new SourceException(ctx.sourceReference(), e, "Value %s is not a valid integer", value);
}
}
}
\ No newline at end of file
((Mutable<?, ?, ?>) warnCtx).addToNs(ConfigListWarningNamespace.class, Boolean.TRUE, Boolean.TRUE);
LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
+ "this is fine with OpenDaylight, it can cause interoperability issues with other systems "
- + "[defined at {}]", ctx.getStatementArgument(), warnCtx.getStatementSourceReference());
+ + "[defined at {}]", ctx.getStatementArgument(), warnCtx.sourceReference());
}
}
try {
return Integer.valueOf(value);
} catch (NumberFormatException e) {
- throw new SourceException("Invalid min-elements argument", ctx.getStatementSourceReference(), e);
+ throw new SourceException("Invalid min-elements argument", ctx.sourceReference(), e);
}
}
@Override
public ModifierKind parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return SourceException.unwrap(ModifierKind.parse(value), ctx.getStatementSourceReference(),
+ return SourceException.unwrap(ModifierKind.parse(value), ctx.sourceReference(),
"'%s' is not valid argument of modifier statement", value);
}
import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
abstract class AbstractModuleStatementSupport
extends BaseStatementSupport<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> {
try {
return UnqualifiedQName.of(value);
} catch (IllegalArgumentException e) {
- throw new SourceException(e.getMessage(), ctx.getStatementSourceReference(), e);
+ throw new SourceException(e.getMessage(), ctx.sourceReference(), e);
}
}
final String moduleName = stmt.coerceRawStatementArgument();
final URI moduleNs = firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class);
- SourceException.throwIfNull(moduleNs, stmt.getStatementSourceReference(),
+ SourceException.throwIfNull(moduleNs, stmt.sourceReference(),
"Namespace of the module [%s] is missing", moduleName);
stmt.addToNs(ModuleNameToNamespace.class, moduleName, moduleNs);
final String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
- SourceException.throwIfNull(modulePrefix, stmt.getStatementSourceReference(),
+ SourceException.throwIfNull(modulePrefix, stmt.sourceReference(),
"Prefix of the module [%s] is missing", moduleName);
stmt.addToNs(ImpPrefixToNamespace.class, modulePrefix, moduleNs);
final Optional<URI> moduleNs = Optional.ofNullable(firstAttributeOf(stmt.declaredSubstatements(),
NamespaceStatement.class));
- SourceException.throwIf(!moduleNs.isPresent(), stmt.getStatementSourceReference(),
+ SourceException.throwIf(!moduleNs.isPresent(), stmt.sourceReference(),
"Namespace of the module [%s] is missing", stmt.getStatementArgument());
final Optional<Revision> revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements());
final StmtContext<?, ModuleStatement, ModuleEffectiveStatement> possibleDuplicateModule =
stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
- throw new SourceException(stmt.getStatementSourceReference(), "Module namespace collision: %s. At %s",
- qNameModule.getNamespace(), possibleDuplicateModule.getStatementSourceReference());
+ throw new SourceException(stmt.sourceReference(), "Module namespace collision: %s. At %s",
+ qNameModule.getNamespace(), possibleDuplicateModule.sourceReference());
}
final String moduleName = stmt.coerceRawStatementArgument();
stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
final String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
- SourceException.throwIfNull(modulePrefix, stmt.getStatementSourceReference(),
+ SourceException.throwIfNull(modulePrefix, stmt.sourceReference(),
"Prefix of the module [%s] is missing", stmt.getStatementArgument());
stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
@Override
protected final ModuleStatement createEmptyDeclared(final StmtContext<UnqualifiedQName, ModuleStatement, ?> ctx) {
- throw noNamespace(ctx.getStatementSourceReference());
+ throw noNamespace(ctx);
}
@Override
protected final ModuleEffectiveStatement createEffective(final Current<UnqualifiedQName, ModuleStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noNamespace(stmt.sourceReference());
+ throw noNamespace(stmt);
}
final List<Submodule> submodules = new ArrayList<>();
return submodules == null ? List.of() : submodules.values();
}
- private static SourceException noNamespace(final @NonNull StatementSourceReference ref) {
- return new SourceException("No namespace declared in module", ref);
+ private static SourceException noNamespace(final @NonNull CommonStmtCtx stmt) {
+ return new SourceException("No namespace declared in module", stmt.sourceReference());
}
private static void addToSemVerModuleNamespace(
try {
return new URI(value);
} catch (URISyntaxException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid namespace \"%s\"", value);
+ throw new SourceException(ctx.sourceReference(), e, "Invalid namespace \"%s\"", value);
}
}
try {
return Ordering.forArgument(value);
} catch (IllegalArgumentException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid ordered-by argument '%s'", value);
+ throw new SourceException(ctx.sourceReference(), e, "Invalid ordered-by argument '%s'", value);
}
}
final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromString(pathArg));
final LeafRefPathParser parser = new LeafRefPathParser(new CommonTokenStream(lexer));
final Path_argContext path = SourceExceptionParser.parse(lexer, parser, parser::path_arg,
- ctx.getStatementSourceReference());
+ ctx.sourceReference());
final ParseTree childPath = path.getChild(0);
final Steps steps;
try {
Pattern.compile(pattern);
} catch (final PatternSyntaxException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
- "Pattern \"%s\" failed to compile", pattern);
+ throw new SourceException(ctx.sourceReference(), e, "Pattern \"%s\" failed to compile", pattern);
}
return PatternExpression.of(value, pattern);
}
try {
return Uint32.valueOf(value).intern();
} catch (IllegalArgumentException e) {
- throw new SourceException(String.format("Bit position value %s is not valid integer", value),
- ctx.getStatementSourceReference(), e);
+ throw new SourceException(ctx.sourceReference(), e, "Bit position value %s is not valid integer", value);
}
}
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(),
+ SourceException.throwIf(ArgumentUtils.compareNumbers(min, max) == 1, ctx.sourceReference(),
+ "Range constraint %s has descending order of boundaries; should be ascending", singleRange);
+ SourceException.throwIf(boundaries.hasNext(), ctx.sourceReference(),
"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);
+ ctx.sourceReference(), "Some of the value ranges in %s are not disjoint", rangeArgument);
ranges.add(ValueRange.of(min, max));
}
try {
return value.indexOf('.') != -1 ? new BigDecimal(value) : new BigInteger(value);
} catch (final NumberFormatException e) {
- throw new SourceException(String.format("Value %s is not a valid decimal number", value),
- ctx.getStatementSourceReference(), e);
+ throw new SourceException(ctx.sourceReference(), e, "Value %s is not a valid decimal number", value);
}
}
}
\ No newline at end of file
try {
return Revision.of(value);
} catch (DateTimeParseException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
+ throw new SourceException(ctx.sourceReference(), e,
"Revision value %s is not in required format yyyy-MM-dd", value);
}
}
try {
return Revision.of(value);
} catch (DateTimeParseException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
+ throw new SourceException(ctx.sourceReference(), e,
"Revision value %s is not in required format yyyy-MM-dd", value);
}
}
case "obsolete":
return Status.OBSOLETE;
default:
- throw new SourceException(ctx.getStatementSourceReference(),
+ throw new SourceException(ctx.sourceReference(),
"Invalid status '%s', must be one of 'current', 'deprecated' or 'obsolete'", value);
}
}
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
abstract class AbstractSubmoduleStatementSupport
extends BaseStatementSupport<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> {
try {
return UnqualifiedQName.of(value);
} catch (IllegalArgumentException e) {
- throw new SourceException(e.getMessage(), ctx.getStatementSourceReference(), e);
+ throw new SourceException(e.getMessage(), ctx.sourceReference(), e);
}
}
final StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>
possibleDuplicateSubmodule = stmt.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
if (possibleDuplicateSubmodule != null && possibleDuplicateSubmodule != stmt) {
- throw new SourceException(stmt.getStatementSourceReference(), "Submodule name collision: %s. At %s",
- stmt.rawStatementArgument(), possibleDuplicateSubmodule.getStatementSourceReference());
+ throw new SourceException(stmt.sourceReference(), "Submodule name collision: %s. At %s",
+ stmt.rawArgument(), possibleDuplicateSubmodule.sourceReference());
}
stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
final String belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(), BelongsToStatement.class);
final StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(stmt, 0,
BelongsToStatement.class, PrefixStatement.class);
- SourceException.throwIfNull(prefixSubStmtCtx, stmt.getStatementSourceReference(),
- "Prefix of belongsTo statement is missing in submodule [%s]", stmt.rawStatementArgument());
+ SourceException.throwIfNull(prefixSubStmtCtx, stmt.sourceReference(),
+ "Prefix of belongsTo statement is missing in submodule [%s]", stmt.rawArgument());
- final String prefix = prefixSubStmtCtx.rawStatementArgument();
+ final String prefix = prefixSubStmtCtx.rawArgument();
stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
}
@Override
protected final SubmoduleStatement createEmptyDeclared(
final StmtContext<UnqualifiedQName, SubmoduleStatement, ?> ctx) {
- throw noBelongsTo(ctx.getStatementSourceReference());
+ throw noBelongsTo(ctx);
}
@Override
protected SubmoduleEffectiveStatement createEffective(final Current<UnqualifiedQName, SubmoduleStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noBelongsTo(stmt.sourceReference());
+ throw noBelongsTo(stmt);
}
return new SubmoduleEffectiveStatementImpl(stmt, substatements);
}
- private static SourceException noBelongsTo(final StatementSourceReference ref) {
- return new SourceException("No belongs-to declared in submodule", ref);
+ private static SourceException noBelongsTo(final CommonStmtCtx stmt) {
+ return new SourceException("No belongs-to declared in submodule", stmt.sourceReference());
}
}
private static @NonNull String findSubmodulePrefix(final StmtContext<UnqualifiedQName, ?, ?> ctx) {
final String name = ctx.getRawArgument();
final StmtContext<?, ?, ?> belongsTo = SourceException.throwIfNull(
- StmtContextUtils.findFirstDeclaredSubstatement(ctx, BelongsToStatement.class),
- ctx.sourceReference(), "Unable to find belongs-to statement in submodule %s.", name);
+ StmtContextUtils.findFirstDeclaredSubstatement(ctx, BelongsToStatement.class), ctx.sourceReference(),
+ "Unable to find belongs-to statement in submodule %s.", name);
return findPrefix(belongsTo, "submodule", name);
}
}
import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
abstract class AbstractIdentityRefSpecificationSupport
extends BaseStatementSupport<String, IdentityRefSpecification,
for (StmtContext<QName, BaseStatement, ?> baseStmt : baseStatements) {
final QName baseIdentity = baseStmt.coerceStatementArgument();
final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(IdentityNamespace.class, baseIdentity);
- InferenceException.throwIfNull(stmtCtx, stmt.getStatementSourceReference(),
+ InferenceException.throwIfNull(stmtCtx, stmt.sourceReference(),
"Referenced base identity '%s' doesn't exist in given scope (module, imported modules, submodules)",
baseIdentity.getLocalName());
}
@Override
protected final IdentityRefSpecification createEmptyDeclared(
final StmtContext<String, IdentityRefSpecification, ?> ctx) {
- throw noBase(ctx.getStatementSourceReference());
+ throw noBase(ctx);
}
@Override
final Current<String, IdentityRefSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noBase(stmt.sourceReference());
+ throw noBase(stmt);
}
final IdentityrefTypeBuilder builder = BaseTypes.identityrefTypeBuilder(stmt.getSchemaPath());
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noBase(final StatementSourceReference ref) {
+ private static SourceException noBase(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.10.2
*
* statement, MUST be present at least once if the type is
* "identityref".
*/
- return new SourceException("At least one base statement has to be present", ref);
+ return new SourceException("At least one base statement has to be present", stmt.sourceReference());
}
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.LeafrefTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
abstract class AbstractLeafrefSpecificationSupport
extends BaseStatementSupport<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> {
@Override
protected final LeafrefSpecification createEmptyDeclared(final StmtContext<String, LeafrefSpecification, ?> ctx) {
- throw noPath(ctx.getStatementSourceReference());
+ throw noPath(ctx);
}
@Override
final Current<String, LeafrefSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noPath(stmt.sourceReference());
+ throw noPath(stmt);
}
final LeafrefTypeBuilder builder = BaseTypes.leafrefTypeBuilder(stmt.getSchemaPath());
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noPath(final StatementSourceReference ref) {
+ private static SourceException noPath(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.12
*
* When the type is "union", the "type" statement (Section 7.4) MUST be
* present.
*/
- return new SourceException("A path statement has to be present", ref);
+ return new SourceException("A path statement has to be present", stmt.sourceReference());
}
}
\ No newline at end of file
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- InferenceException.throwIf(failed.contains(typePrereq), stmt.getStatementSourceReference(),
+ InferenceException.throwIf(failed.contains(typePrereq), stmt.sourceReference(),
"Type [%s] was not found.", typeQName);
}
});
return BuiltinEffectiveStatement.UINT64;
default:
final QName qname = StmtContextUtils.parseNodeIdentifier(ctx.caerbannog(), argument);
- final StmtContext<?, TypedefStatement, TypedefEffectiveStatement> typedef =
- SourceException.throwIfNull(ctx.getFromNamespace(TypeNamespace.class, qname),
- ctx.sourceReference(), "Type '%s' not found", qname);
+ final StmtContext<?, TypedefStatement, TypedefEffectiveStatement> typedef = SourceException.throwIfNull(
+ ctx.getFromNamespace(TypeNamespace.class, qname), ctx.sourceReference(),
+ "Type '%s' not found", qname);
return typedef.buildEffective().asTypeEffectiveStatement();
}
}
try {
return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
} catch (InvalidRangeConstraintException e) {
- throw new SourceException(ctx.sourceReference(), e, "Invalid range constraint: %s",
- e.getOffendingRanges());
+ throw new SourceException(ctx.sourceReference(), e, "Invalid range constraint: %s", e.getOffendingRanges());
}
}
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.BitsTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
final class BitsSpecificationSupport
extends BaseStatementSupport<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> {
@Override
protected BitsSpecification createEmptyDeclared(final StmtContext<String, BitsSpecification, ?> ctx) {
- throw noBits(ctx.getStatementSourceReference());
+ throw noBits(ctx);
}
@Override
final Current<String, BitsSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noBits(stmt.sourceReference());
+ throw noBits(stmt);
}
final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(stmt.getSchemaPath());
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noBits(final StatementSourceReference ref) {
+ private static SourceException noBits(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.7.4:
*
* The "bit" statement, which is a substatement to the "type" statement,
* MUST be present if the type is "bits".
*/
- return new SourceException("At least one bit statement has to be present", ref);
+ return new SourceException("At least one bit statement has to be present", stmt.sourceReference());
}
}
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
final class Decimal64SpecificationSupport extends BaseStatementSupport<String, Decimal64Specification,
EffectiveStatement<String, Decimal64Specification>> {
@Override
protected Decimal64Specification createEmptyDeclared(final StmtContext<String, Decimal64Specification, ?> ctx) {
- throw noFracDigits(ctx.getStatementSourceReference());
+ throw noFracDigits(ctx);
}
@Override
final Current<String, Decimal64Specification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noFracDigits(stmt.sourceReference());
+ throw noFracDigits(stmt);
}
final DecimalTypeBuilder builder = BaseTypes.decimalTypeBuilder(stmt.getSchemaPath());
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noFracDigits(final StatementSourceReference ref) {
+ private static SourceException noFracDigits(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.3.4
*
* The "fraction-digits" statement, which is a substatement to the
* "type" statement, MUST be present if the type is "decimal64".
*/
- return new SourceException("At least one fraction-digits statement has to be present", ref);
+ return new SourceException("At least one fraction-digits statement has to be present", stmt.sourceReference());
}
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.EnumerationTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
final class EnumSpecificationSupport
extends BaseStatementSupport<String, EnumSpecification, EffectiveStatement<String, EnumSpecification>> {
@Override
protected EnumSpecification createEmptyDeclared(final StmtContext<String, EnumSpecification, ?> ctx) {
- throw noEnum(ctx.getStatementSourceReference());
+ throw noEnum(ctx);
}
@Override
final Current<String, EnumSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noEnum(stmt.sourceReference());
+ throw noEnum(stmt);
}
final EnumerationTypeBuilder builder = BaseTypes.enumerationTypeBuilder(stmt.getSchemaPath());
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noEnum(final StatementSourceReference ref) {
+ private static SourceException noEnum(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.6.4
*
* The "enum" statement, which is a substatement to the "type"
* statement, MUST be present if the type is "enumeration".
*/
- return new SourceException("At least one enum statement has to be present", ref);
+ return new SourceException("At least one enum statement has to be present", stmt.sourceReference());
}
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.UnionTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
final class UnionSpecificationSupport
extends BaseStatementSupport<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> {
@Override
protected UnionSpecification createEmptyDeclared(final StmtContext<String, UnionSpecification, ?> ctx) {
- throw noType(ctx.getStatementSourceReference());
+ throw noType(ctx);
}
@Override
final Current<String, UnionSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noType(stmt.sourceReference());
+ throw noType(stmt);
}
final UnionTypeBuilder builder = BaseTypes.unionTypeBuilder(stmt.getSchemaPath());
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noType(final @NonNull StatementSourceReference ref) {
+ private static SourceException noType(final @NonNull CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.12
*
* When the type is "union", the "type" statement (Section 7.4) MUST be
* present.
*/
- return new SourceException("At least one type statement has to be present", ref);
+ return new SourceException("At least one type statement has to be present", stmt.sourceReference());
}
}
final QName arg = stmt.coerceStatementArgument();
final StmtContext<?, ?, ?> existing = parent.getFromNamespace(TypeNamespace.class, arg);
// RFC7950 sections 5.5 and 6.2.1: identifiers must not be shadowed
- SourceException.throwIf(existing != null, stmt.getStatementSourceReference(), "Duplicate name for typedef %s",
- arg);
+ SourceException.throwIf(existing != null, stmt.sourceReference(), "Duplicate name for typedef %s", arg);
}
private static void checkDeclared(final StmtContext<QName, TypedefStatement, ?> ctx) {
@Override
public ImmutableSet<Descendant> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
final ImmutableSet<Descendant> uniqueConstraints = parseUniqueConstraintArgument(ctx, value);
- SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.getStatementSourceReference(),
- "Invalid argument value '%s' of unique statement. The value must contains at least "
- + "one descendant schema node identifier.", value);
+ SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.sourceReference(),
+ "Invalid argument value '%s' of unique statement. The value must contains at least one descendant schema "
+ + "node identifier.", value);
return uniqueConstraints;
}
final Set<Descendant> uniqueConstraintNodes = new HashSet<>();
for (final String uniqueArgToken : SEP_SPLITTER.split(nocrlf)) {
final SchemaNodeIdentifier nodeIdentifier = ArgumentUtils.nodeIdentifierFromPath(ctx, uniqueArgToken);
- SourceException.throwIf(nodeIdentifier instanceof Absolute, ctx.getStatementSourceReference(),
- "Unique statement argument '%s' contains schema node identifier '%s' "
- + "which is not in the descendant node identifier form.", argumentValue, uniqueArgToken);
+ SourceException.throwIf(nodeIdentifier instanceof Absolute, ctx.sourceReference(),
+ "Unique statement argument '%s' contains schema node identifier '%s' which is not in the descendant "
+ + "node identifier form.", argumentValue, uniqueArgToken);
uniqueConstraintNodes.add((Descendant) nodeIdentifier);
}
return ImmutableSet.copyOf(uniqueConstraintNodes);
@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());
+ InferenceException.throwIf(failed.contains(sourceGroupingPre), usesNode.sourceReference(),
+ "Grouping '%s' was not resolved.", groupingName);
+ throw new InferenceException("Unknown error occurred.", usesNode.sourceReference());
}
});
}
private static void performRefine(final Mutable<?, ?, ?> subStmtCtx, final StmtContext<?, ?, ?> usesParentCtx) {
final Object refineArgument = subStmtCtx.getStatementArgument();
- InferenceException.throwIf(!(refineArgument instanceof SchemaNodeIdentifier),
- subStmtCtx.getStatementSourceReference(),
+ InferenceException.throwIf(!(refineArgument instanceof SchemaNodeIdentifier), subStmtCtx.sourceReference(),
"Invalid refine argument %s. It must be instance of SchemaNodeIdentifier.", refineArgument);
final Optional<StmtContext<?, ?, ?>> optRefineTargetCtx = SchemaTreeNamespace.findNode(
usesParentCtx, (SchemaNodeIdentifier) refineArgument);
- InferenceException.throwIf(!optRefineTargetCtx.isPresent(), subStmtCtx.getStatementSourceReference(),
+ InferenceException.throwIf(!optRefineTargetCtx.isPresent(), subStmtCtx.sourceReference(),
"Refine target node %s not found.", refineArgument);
final StmtContext<?, ?, ?> refineTargetNodeCtx = optRefineTargetCtx.get();
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());
+ refineTargetNodeCtx.getStatementArgument(), subStmtCtx.sourceReference());
subStmtCtx.addAsEffectOfStatement(refineTargetNodeCtx);
return;
}
final StatementDefinition refineSubstatementDef = refineSubstatementCtx.publicDefinition();
SourceException.throwIf(!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx),
- refineSubstatementCtx.getStatementSourceReference(),
+ refineSubstatementCtx.sourceReference(),
"Error in module '%s' in the refine of uses '%s': can not perform refine of '%s' for the target '%s'.",
- refineSubstatementCtx.getRoot().rawStatementArgument(),
- refineSubstatementCtx.coerceParentContext().getStatementArgument(),
+ refineSubstatementCtx.getRoot().rawArgument(), refineSubstatementCtx.coerceParentContext().argument(),
refineSubstatementCtx.publicDefinition(), refineTargetNodeCtx.publicDefinition());
if (isAllowedToAddByRefine(refineSubstatementDef)) {
try {
return Integer.valueOf(value);
} catch (NumberFormatException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e,
+ throw new SourceException(ctx.sourceReference(), e,
"%s is not valid value statement integer argument in a range of -2147483648..2147483647", value);
}
}
@Override
public YangVersion parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return SourceException.unwrap(YangVersion.parse(value), ctx.getStatementSourceReference(),
- "Unsupported YANG version %s", value);
+ return SourceException.unwrap(YangVersion.parse(value), ctx.sourceReference(), "Unsupported YANG version %s",
+ value);
}
@Override
@Before
public void before() {
- doReturn(ref).when(ctx).getStatementSourceReference();
+ doReturn(ref).when(ctx).sourceReference();
}
@Test
return null;
}
- @SuppressWarnings("unchecked")
@Override
+ @SuppressWarnings("unchecked")
public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) {
final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
SchemaTreeNamespace.class, key, value);
if (prev != null) {
- throw new SourceException(value.getStatementSourceReference(),
+ throw new SourceException(value.sourceReference(),
"Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
- value.getRoot().rawStatementArgument(), key, prev.getStatementArgument(),
- prev.getStatementSourceReference());
+ value.getRoot().rawArgument(), key, prev.argument(), prev.sourceReference());
}
}
final Collection<? extends StmtContext<?, ?, ?>> unknownSubstatements = StmtContextUtils.findAllSubstatements(
current, UnknownStatement.class);
for (final StmtContext<?, ?, ?> unknownSubstatement : unknownSubstatements) {
- if (localName.equals(unknownSubstatement.rawStatementArgument())) {
+ if (localName.equals(unknownSubstatement.rawArgument())) {
return unknownSubstatement;
}
}
private final String rawArgument;
protected AbstractDeclaredStatement(final StmtContext<A, ?, ?> context) {
- rawArgument = context.rawStatementArgument();
+ rawArgument = context.rawArgument();
argument = context.argument();
source = context.source();
definition = context.publicDefinition();
return source();
}
- // TODO: gradually migrate callers of this method
+ @Deprecated(forRemoval = true)
default @NonNull StatementSourceReference getStatementSourceReference() {
return sourceReference();
}
* Return the statement argument in literal format.
*
* @return raw statement argument string, or null if this statement does not have an argument.
+ * @deprecated Use {@link #rawArgument()} instead.
*/
- // TODO: gradually migrate callers of this method
+ @Deprecated(forRemoval = true)
default @Nullable String rawStatementArgument() {
return rawArgument();
}
leafStmtCtx.allSubstatements().forEach(leafSubstmtCtx -> {
final StatementDefinition statementDef = leafSubstmtCtx.publicDefinition();
SourceException.throwIf(YangStmtMapping.IF_FEATURE.equals(statementDef)
- || YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx.getStatementSourceReference(),
+ || YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx.sourceReference(),
"%s statement is not allowed in %s leaf statement which is specified as a list key.",
statementDef.getStatementName(), leafStmtCtx.getStatementArgument());
});
}
}
- return internedQName(ctx,
- InferenceException.throwIfNull(qnameModule, ctx.getStatementSourceReference(),
+ return internedQName(ctx, InferenceException.throwIfNull(qnameModule, ctx.sourceReference(),
"Cannot resolve QNameModule for '%s'", value), localName);
}
* @throws SourceException if the string is not a valid YANG identifier
*/
public static QName parseIdentifier(final StmtContext<?, ?, ?> ctx, final String str) {
- SourceException.throwIf(str.isEmpty(), ctx.getStatementSourceReference(),
- "Identifier may not be an empty string");
+ SourceException.throwIf(str.isEmpty(), ctx.sourceReference(), "Identifier may not be an empty string");
return internedQName(ctx, str);
}
public static QName parseNodeIdentifier(final StmtContext<?, ?, ?> ctx, final String prefix,
final String localName) {
return internedQName(ctx,
- InferenceException.throwIfNull(getModuleQNameByPrefix(ctx, prefix), ctx.getStatementSourceReference(),
+ InferenceException.throwIfNull(getModuleQNameByPrefix(ctx, prefix), ctx.sourceReference(),
"Cannot resolve QNameModule for '%s'", prefix),
localName);
}
* @throws SourceException if the string is not a valid YANG node identifier
*/
public static QName parseNodeIdentifier(final StmtContext<?, ?, ?> ctx, final String str) {
- SourceException.throwIf(str.isEmpty(), ctx.getStatementSourceReference(),
- "Node identifier may not be an empty string");
+ SourceException.throwIf(str.isEmpty(), ctx.sourceReference(), "Node identifier may not be an empty string");
final int colon = str.indexOf(':');
if (colon == -1) {
}
final String prefix = str.substring(0, colon);
- SourceException.throwIf(prefix.isEmpty(), ctx.getStatementSourceReference(),
- "String '%s' has an empty prefix", str);
+ SourceException.throwIf(prefix.isEmpty(), ctx.sourceReference(), "String '%s' has an empty prefix", str);
final String localName = str.substring(colon + 1);
- SourceException.throwIf(localName.isEmpty(), ctx.getStatementSourceReference(),
- "String '%s' has an empty identifier", str);
+ SourceException.throwIf(localName.isEmpty(), ctx.sourceReference(), "String '%s' has an empty identifier", str);
return parseNodeIdentifier(ctx, prefix, localName);
}
try {
template = QName.create(module, localName);
} catch (IllegalArgumentException e) {
- throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid identifier '%s'", localName);
+ throw new SourceException(ctx.sourceReference(), e, "Invalid identifier '%s'", localName);
}
return template.intern();
}
if (cardinality == null) {
if (ctx.getFromNamespace(ExtensionNamespace.class, key.getStatementName()) == null) {
- throw new InvalidSubstatementException(ctx.getStatementSourceReference(),
- "%s is not valid for %s. Error in module %s (%s)", key, currentStatement,
- ctx.getRoot().rawStatementArgument(),
- ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()));
+ final StmtContext<?, ?, ?> root = ctx.getRoot();
+ throw new InvalidSubstatementException(ctx.sourceReference(),
+ "%s is not valid for %s. Error in module %s (%s)", key, currentStatement, root.rawArgument(),
+ ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
}
continue;
if (cardinality.getMin() > 0) {
if (cardinality.getMin() > value) {
- throw new InvalidSubstatementException(ctx.getStatementSourceReference(),
+ final StmtContext<?, ?, ?> root = ctx.getRoot();
+ throw new InvalidSubstatementException(ctx.sourceReference(),
"Minimal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
- cardinality.getMin(), value, ctx.getRoot().rawStatementArgument(),
- ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()));
+ cardinality.getMin(), value, root.rawArgument(),
+ ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
}
// Encountered a mandatory statement, hence we are not missing it
missingMandatory.remove(key);
}
if (cardinality.getMax() < value) {
- throw new InvalidSubstatementException(ctx.getStatementSourceReference(),
+ final StmtContext<?, ?, ?> root = ctx.getRoot();
+ throw new InvalidSubstatementException(ctx.sourceReference(),
"Maximal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
- cardinality.getMax(), value, ctx.getRoot().rawStatementArgument(),
- ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()));
+ cardinality.getMax(), value, root.rawArgument(),
+ ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
}
}
final Entry<StatementDefinition, Cardinality> e = missingMandatory.entrySet().iterator().next();
final StmtContext<?, ?, ?> root = ctx.getRoot();
- throw new MissingSubstatementException(ctx.getStatementSourceReference(),
+ throw new MissingSubstatementException(ctx.sourceReference(),
"%s is missing %s. Minimal count is %s. Error in module %s (%s)", currentStatement, e.getKey(),
- e.getValue().getMin(), root.rawStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class,
- root));
+ e.getValue().getMin(), root.rawArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
}
}