private static SourceIdentifier getSourceIdentifier(final StmtContext<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> belongsToCtx) { return RevisionSourceIdentifier.create(belongsToCtx.coerceStatementArgument()); }
private static boolean isListKey(final StmtContext<?, ?, ?> leafStmtCtx, final StmtContext<Collection<SchemaNodeIdentifier>, ?, ?> keyStmtCtx) { for (final SchemaNodeIdentifier keyIdentifier : keyStmtCtx.coerceStatementArgument()) { if (leafStmtCtx.getStatementArgument().equals(keyIdentifier.getLastComponent())) { return true; } } return false; }
RefineEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) { super(ctx); qname = verifyNotNull(ctx.coerceStatementArgument().getLastComponent()); path = ctx.getSchemaPath().get(); refineTargetNode = (SchemaNode) ctx.getEffectOfStatement().iterator().next().buildEffective(); // initSubstatementCollectionsAndFields this.unknownNodes = ImmutableList.copyOf(effectiveSubstatements().stream() .filter(UnknownSchemaNode.class::isInstance) .map(UnknownSchemaNode.class::cast) .collect(Collectors.toList())); }
GroupingEffectiveStatementImpl( final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) { super(ctx); qname = ctx.coerceStatementArgument(); path = ctx.getSchemaPath().get(); addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES); final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder(); final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder(); final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder(); for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof ActionDefinition) { actionsBuilder.add((ActionDefinition) effectiveStatement); } if (effectiveStatement instanceof NotificationDefinition) { notificationsBuilder.add((NotificationDefinition) effectiveStatement); } if (effectiveStatement instanceof UnknownSchemaNode) { b.add((UnknownSchemaNode) effectiveStatement); } } this.actions = actionsBuilder.build(); this.notifications = notificationsBuilder.build(); unknownNodes = b.build(); }
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); } }
IdentityEffectiveStatementImpl( final StmtContext<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> ctx) { super(ctx); this.baseIdentities = new HashSet<>(); ((StmtContext.Mutable<?, ?, ?>) ctx).addMutableStmtToSeal(this); // initDerivedIdentities final Set<IdentitySchemaNode> derivedIdentitiesInit = new HashSet<>(); final List<StmtContext<?, ?, ?>> derivedIdentitiesCtxList = ctx.getFromNamespace( DerivedIdentitiesNamespace.class, ctx.coerceStatementArgument()); if (derivedIdentitiesCtxList == null) { this.derivedIdentities = ImmutableSet.of(); return; } for (final StmtContext<?, ?, ?> derivedIdentityCtx : derivedIdentitiesCtxList) { final IdentityEffectiveStatementImpl derivedIdentity = (IdentityEffectiveStatementImpl) derivedIdentityCtx .buildEffective(); derivedIdentity.addBaseIdentity(this); derivedIdentitiesInit.add(derivedIdentity); } this.derivedIdentities = ImmutableSet.copyOf(derivedIdentitiesInit); }
AugmentEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) { super(ctx); this.targetPath = ctx.coerceStatementArgument().asSchemaPath(); final QNameModule rootModuleQName = StmtContextUtils.getRootModuleQName(ctx); this.namespace = rootModuleQName.getNamespace(); this.revision = rootModuleQName.getRevision().orElse(null); this.copyOf = (AugmentationSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null); whenCondition = findFirstEffectiveSubstatementArgument(WhenEffectiveStatement.class).orElse(null); // initSubstatementCollections final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder(); final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder(); final ImmutableList.Builder<UnknownSchemaNode> listBuilder = new ImmutableList.Builder<>(); for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof ActionDefinition) { actionsBuilder.add((ActionDefinition) effectiveStatement); } else if (effectiveStatement instanceof NotificationDefinition) { notificationsBuilder.add((NotificationDefinition) effectiveStatement); } else if (effectiveStatement instanceof UnknownSchemaNode) { listBuilder.add((UnknownSchemaNode) effectiveStatement); } } this.actions = actionsBuilder.build(); this.notifications = notificationsBuilder.build(); this.unknownNodes = listBuilder.build(); }
private ExtensionEffectiveStatementImpl( final StmtContext<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> ctx) { super(ctx); this.qname = ctx.coerceStatementArgument(); this.schemaPath = ctx.getSchemaPath().get(); final List<UnknownSchemaNode> unknownNodesInit = new ArrayList<>(); for (EffectiveStatement<?, ?> unknownNode : effectiveSubstatements()) { if (unknownNode instanceof UnknownSchemaNode) { unknownNodesInit.add((UnknownSchemaNode) unknownNode); } } this.unknownNodes = ImmutableList.copyOf(unknownNodesInit); // initFields final Optional<ArgumentEffectiveStatement> optArgumentSubstatement = findFirstEffectiveSubstatement( ArgumentEffectiveStatement.class); if (optArgumentSubstatement.isPresent()) { final ArgumentEffectiveStatement argumentStatement = optArgumentSubstatement.get(); this.argument = argumentStatement.argument().getLocalName(); this.yin = argumentStatement.findFirstEffectiveSubstatement(YinElementEffectiveStatement.class) .map(YinElementEffectiveStatement::argument).orElse(Boolean.FALSE).booleanValue(); } else { this.argument = null; this.yin = false; } }
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); } }
public static boolean checkFeatureSupport(final StmtContext<?, ?, ?> stmtContext, final Set<QName> supportedFeatures) { boolean isSupported = false; boolean containsIfFeature = false; for (final StmtContext<?, ?, ?> stmt : stmtContext.declaredSubstatements()) { if (YangStmtMapping.IF_FEATURE.equals(stmt.getPublicDefinition())) { containsIfFeature = true; @SuppressWarnings("unchecked") final Predicate<Set<QName>> argument = (Predicate<Set<QName>>) stmt.coerceStatementArgument(); if (argument.test(supportedFeatures)) { isSupported = true; } else { isSupported = false; break; } } } return !containsIfFeature || isSupported; }
NotificationEffectiveStatementImpl( final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) { super(ctx); this.qname = ctx.coerceStatementArgument(); this.path = ctx.getSchemaPath().get();
ctx.getFromNamespace(GroupingNamespace.class, ctx.coerceStatementArgument()); this.groupingPath = grpCtx.getSchemaPath().get();
@Override public void apply(final InferenceContext ctx) { StmtContext<?, ?, ?> belongsToModuleCtx = belongsToPrereq.resolve(ctx); belongsToCtx.addToNs(BelongsToModuleContext.class, belongsToSourceIdentifier, belongsToModuleCtx); belongsToCtx.addToNs(BelongsToPrefixToModuleCtx.class, findFirstDeclaredSubstatement(belongsToCtx, PrefixStatement.class).coerceStatementArgument(), belongsToModuleCtx); }
ImportEffectiveStatementImpl(final StmtContext<String, ImportStatement, ?> ctx) { super(ctx); moduleName = ctx.coerceStatementArgument(); final Optional<String> prefixStmt = findFirstEffectiveSubstatementArgument(PrefixEffectiveStatement.class); MissingSubstatementException.throwIf(!prefixStmt.isPresent(), ctx.getStatementSourceReference(), "Prefix is mandatory substatement of import statement"); this.prefix = prefixStmt.get(); if (!ctx.isEnabledSemanticVersioning()) { final Optional<Revision> optRev = findFirstEffectiveSubstatementArgument( RevisionDateEffectiveStatement.class); this.revision = optRev.isPresent() ? optRev.get() : getImportedRevision(ctx); this.semVer = null; } else { final SemVerSourceIdentifier importedModuleIdentifier = ctx.getFromNamespace( ImportPrefixToSemVerSourceIdentifier.class, prefix); revision = importedModuleIdentifier.getRevision().orElse(null); semVer = importedModuleIdentifier.getSemanticVersion().orElse(null); } description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null); reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null); }
@Override public Collection<SchemaNodeIdentifier> adaptArgumentValue( final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx, final QNameModule targetModule) { final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder(); boolean replaced = false; for (final SchemaNodeIdentifier arg : ctx.coerceStatementArgument()) { final QName qname = arg.getLastComponent(); if (!targetModule.equals(qname.getModule())) { final QName newQname = ctx.getFromNamespace(QNameCacheNamespace.class, qname.withModule(targetModule)); builder.add(SchemaNodeIdentifier.SAME.createChild(newQname)); replaced = true; } else { builder.add(arg); } } // This makes sure we reuse the collection when a grouping is // instantiated in the same module return replaced ? builder.build() : ctx.getStatementArgument(); }
@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 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; }
switch (ctx.coerceStatementArgument()) { case BINARY: typeStmt = BuiltinEffectiveStatement.BINARY;