private static String addPrefixToYangXPathFunctions(final String path, final StmtContext<?, ?, ?> ctx) { if (ctx.getRootVersion() == YangVersion.VERSION_1_1) { // FIXME once Java 9 is available, change this to StringBuilder as Matcher.appendReplacement() and // Matcher.appendTail() will accept StringBuilder parameter in Java 9 final StringBuffer result = new StringBuffer(); final String prefix = YANG_XPATH_FUNCTIONS_PREFIX + ":"; final Matcher matcher = YANG_XPATH_FUNCTIONS_PATTERN.matcher(path); while (matcher.find()) { matcher.appendReplacement(result, prefix + matcher.group()); } matcher.appendTail(result); return result.toString(); } return path; }
private static boolean areFeaturesSupported(final StmtContext<?, ?, ?> subStmtCtx) { /* * In case of Yang 1.1, checks whether features are supported. */ return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || subStmtCtx.isSupportedByFeatures(); }
private static boolean isSupportedDeviationTarget(final StmtContext<?, ?, ?> deviateSubstatementCtx, final StmtContext<?, ?, ?> deviateTargetCtx, final YangVersion yangVersion) { Set<StatementDefinition> supportedDeviationTargets = YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(deviateTargetCtx.getRootVersion(), deviateSubstatementCtx.getPublicDefinition()); if (supportedDeviationTargets == null) { supportedDeviationTargets = YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(YangVersion.VERSION_1, deviateSubstatementCtx.getPublicDefinition()); } // if supportedDeviationTargets is null, it means that the deviate substatement is an unknown statement return supportedDeviationTargets == null || supportedDeviationTargets.contains( deviateTargetCtx.getPublicDefinition()); } }
@Override public Predicate<Set<QName>> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) { if (YangVersion.VERSION_1_1.equals(ctx.getRootVersion())) { return IfFeaturePredicateVisitor.parseIfFeatureExpression(ctx, value); } final QName qname = StmtContextUtils.parseNodeIdentifier(ctx, value); return setQNames -> setQNames.contains(qname); }
private static boolean isRelevantForIfFeatureAndWhenOnListKeysCheck(final StmtContext<?, ?, ?> ctx) { return YangVersion.VERSION_1_1.equals(ctx.getRootVersion()) && StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.LIST) && StmtContextUtils.findFirstDeclaredSubstatement(ctx.coerceParentContext(), KeyStatement.class) != null; }
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()); }
EffectiveStmtUtils.hasDefaultValueMarkedWithIfFeature(ctx.getRootVersion(), typeStmt, defaultValues), ctx.getStatementSourceReference(), "Leaf-list '%s' has one of its default values '%s' marked with an if-feature statement.",
EffectiveStmtUtils.hasDefaultValueMarkedWithIfFeature(ctx.getRootVersion(), typeStmt, dflt), ctx.getStatementSourceReference(), "Leaf '%s' has default value '%s' marked with an if-feature statement.", ctx.getStatementArgument(), dflt);
BitsTypeEffectiveStatementImpl( final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx, final BitsTypeDefinition baseType) { super(ctx); final BitsTypeBuilder builder = RestrictedTypes.newBitsBuilder(baseType, ctx.getSchemaPath().get()); final YangVersion yangVersion = ctx.getRootVersion(); for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) { if (stmt instanceof BitEffectiveStatementImpl) { SourceException.throwIf(yangVersion != YangVersion.VERSION_1_1, ctx.getStatementSourceReference(), "Restricted bits type is allowed only in YANG 1.1 version."); final BitEffectiveStatementImpl bitSubStmt = (BitEffectiveStatementImpl) stmt; final long effectivePos; if (bitSubStmt.getDeclaredPosition() == null) { effectivePos = getBaseTypeBitPosition(bitSubStmt.getName(), baseType, ctx); } else { effectivePos = bitSubStmt.getDeclaredPosition(); } builder.addBit(EffectiveTypeUtil.buildBit(bitSubStmt, effectivePos)); } else if (stmt instanceof UnknownSchemaNode) { builder.addUnknownSchemaNode((UnknownSchemaNode) stmt); } } typeDefinition = builder.build(); }
EnumTypeEffectiveStatementImpl( final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx, final EnumTypeDefinition baseType) { super(ctx); final EnumerationTypeBuilder builder = RestrictedTypes.newEnumerationBuilder(baseType, ctx.getSchemaPath().get()); final YangVersion yangVersion = ctx.getRootVersion(); for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) { if (stmt instanceof EnumEffectiveStatementImpl) { SourceException.throwIf(yangVersion != YangVersion.VERSION_1_1, ctx.getStatementSourceReference(), "Restricted enumeration type is allowed only in YANG 1.1 version."); final EnumEffectiveStatementImpl enumSubStmt = (EnumEffectiveStatementImpl) stmt; final int effectiveValue; if (enumSubStmt.getDeclaredValue() == null) { effectiveValue = getBaseTypeEnumValue(enumSubStmt.getName(), baseType, ctx); } else { effectiveValue = enumSubStmt.getDeclaredValue(); } builder.addEnum(EffectiveTypeUtil.buildEnumPair(enumSubStmt, effectiveValue)); } else if (stmt instanceof UnknownSchemaNode) { builder.addUnknownSchemaNode((UnknownSchemaNode) stmt); } } typeDefinition = builder.build(); }
EffectiveStmtUtils.hasDefaultValueMarkedWithIfFeature(ctx.getRootVersion(), typeEffectiveStmt, dflt), ctx.getStatementSourceReference(), "Typedef '%s' has default value '%s' marked with an if-feature statement.", ctx.getStatementArgument(),