@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); }
@Override public Integer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { try { return Integer.valueOf(value); } catch (NumberFormatException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "%s is not valid value statement integer argument in a range of -2147483648..2147483647", value); } }
@Override public Long parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new SourceException(String.format("Bit position value %s is not valid integer", value), ctx.getStatementSourceReference(), e); } }
@Override public Integer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { final Integer fractionDigits; try { fractionDigits = Integer.valueOf(value); } catch (NumberFormatException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "%s is not valid fraction-digits integer argument", value); } SourceException.throwIf(!FRAC_DIGITS_ALLOWED.contains(fractionDigits), ctx.getStatementSourceReference(), "fraction-digits argument should be integer within %s", FRAC_DIGITS_ALLOWED); return fractionDigits; }
@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(), "Augment argument \'%s\' is not valid, it can be only absolute path; or descendant if used in uses", value); return ArgumentUtils.nodeIdentifierFromPath(ctx, value); }
@Override public Set<Relative> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { final Set<Relative> 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); return uniqueConstraints; }
@Override public Revision parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { try { return Revision.of(value); } catch (DateTimeParseException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "Revision value %s is not in required format yyyy-MM-dd", value); } }
@Override public Revision parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { try { return Revision.of(value); } catch (DateTimeParseException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "Revision value %s is not in required format yyyy-MM-dd", value); } }
private Revision getImportedRevision(final StmtContext<String, ImportStatement, ?> ctx) { /* * When 'revision-date' of an import is not specified in yang source, we * need to find revision of imported module. */ final QNameModule importedModule = StmtContextUtils.getModuleQNameByPrefix(ctx, this.prefix); SourceException.throwIfNull(importedModule, ctx.getStatementSourceReference(), "Unable to find import of module %s with prefix %s.", this.moduleName, this.prefix); return importedModule.getRevision().orElse(null); }
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); } }
private static void checkConflict(final StmtContext<?, ?, ?> parent, final StmtContext<QName, ?, ?> stmt) { 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); } }
@SuppressWarnings("unchecked") @Override public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) { final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent( ChildSchemaNodeNamespace.class, key, value); if (prev != null) { throw new SourceException(value.getStatementSourceReference(), "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s", value.getRoot().getStatementArgument(), key, prev.getStatementArgument(), prev.getStatementSourceReference()); } }
private static int getBaseTypeEnumValue(final String enumName, final EnumTypeDefinition baseType, final StmtContext<?, ?, ?> ctx) { for (EnumPair baseTypeEnumPair : baseType.getValues()) { if (enumName.equals(baseTypeEnumPair.getName())) { return baseTypeEnumPair.getValue(); } } throw new SourceException(ctx.getStatementSourceReference(), "Enum '%s' is not a subset of its base enumeration type %s.", enumName, baseType.getQName()); }
private static long getBaseTypeBitPosition(final String bitName, final BitsTypeDefinition baseType, final StmtContext<?, ?, ?> ctx) { for (Bit baseTypeBit : baseType.getBits()) { if (bitName.equals(baseTypeBit.getName())) { return baseTypeBit.getPosition(); } } throw new SourceException(ctx.getStatementSourceReference(), "Bit '%s' is not a subset of its base bits type %s.", bitName, baseType.getQName()); }
static Predicate<Set<QName>> parseIfFeatureExpression(final StmtContext<?, ?, ?> ctx, final String value) { final IfFeatureExpressionLexer lexer = new IfFeatureExpressionLexer(CharStreams.fromString(value)); final IfFeatureExpressionParser parser = new IfFeatureExpressionParser(new CommonTokenStream(lexer)); return new IfFeaturePredicateVisitor(ctx).visit(SourceExceptionParser.parse(lexer, parser, parser::if_feature_expr, ctx.getStatementSourceReference())); }
public static @NonNull Boolean parseBoolean(final StmtContext<?, ?, ?> ctx, final String input) { if ("true".equals(input)) { return Boolean.TRUE; } else if ("false".equals(input)) { return Boolean.FALSE; } else { throw new SourceException(ctx.getStatementSourceReference(), "Invalid '%s' statement %s '%s', it can be either 'true' or 'false'", ctx.getPublicDefinition().getStatementName(), ctx.getPublicDefinition().getArgumentName(), input); } }
public static SourceException createNameCollisionSourceException(final StmtContext<?, ?, ?> ctx, final EffectiveStatement<?, ?> effectiveStatement) { return new SourceException(ctx.getStatementSourceReference(), "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared.", ctx.getRoot().getStatementArgument(), effectiveStatement.argument(), effectiveStatement.argument()); }
private static void disallowIfFeatureAndWhenOnListKeys(final StmtContext<?, ?, ?> leafStmtCtx) { leafStmtCtx.allSubstatements().forEach(leafSubstmtCtx -> { final StatementDefinition statementDef = leafSubstmtCtx.getPublicDefinition(); SourceException.throwIf(YangStmtMapping.IF_FEATURE.equals(statementDef) || YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx.getStatementSourceReference(), "%s statement is not allowed in %s leaf statement which is specified as a list key.", statementDef.getStatementName(), leafStmtCtx.getStatementArgument()); }); }
@Override public Predicate<Set<QName>> visitIf_feature_factor(final @Nullable If_feature_factorContext ctx) { if (ctx.if_feature_expr() != null) { return visitIf_feature_expr(ctx.if_feature_expr()); } else if (ctx.if_feature_factor() != null) { return visitIf_feature_factor(ctx.if_feature_factor()).negate(); } else if (ctx.identifier_ref_arg() != null) { return visitIdentifier_ref_arg(ctx.identifier_ref_arg()); } throw new SourceException("Unexpected grammar context during parsing of IfFeature expression. " + "Most probably IfFeature grammar has been changed.", stmtCtx.getStatementSourceReference()); }
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()); }