Effective(final StmtContext<Void, DefaultDenyWriteStatement, ?> ctx) { super(ctx); path = ctx.coerceParentContext().getSchemaPath().get().createChild( ctx.getPublicDefinition().getStatementName()); }
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())); }
@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 StmtContext<?, ?, ?> getSearchRoot(final StmtContext<?, ?, ?> augmentContext) { // Augment is in uses - we need to augment instantiated nodes in parent. final StmtContext<?, ?, ?> parent = augmentContext.coerceParentContext(); if (YangStmtMapping.USES == parent.getPublicDefinition()) { return parent.getParentContext(); } return parent; }
public static QNameModule getModuleQNameByPrefix(final StmtContext<?, ?, ?> ctx, final String prefix) { final StmtContext<?, ?, ?> importedModule = ctx.getRoot().getFromNamespace(ImportPrefixToModuleCtx.class, prefix); final QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, importedModule); if (qnameModule != null) { return qnameModule; } if (producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) { final String moduleName = ctx.getRoot().getFromNamespace(BelongsToPrefixToModuleName.class, prefix); return ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName); } return null; }
protected AbstractDeclaredStatement(final StmtContext<A, ?, ?> context) { rawArgument = context.rawStatementArgument(); argument = context.getStatementArgument(); source = context.getStatementSource(); definition = context.getPublicDefinition(); /* * Perform an explicit copy, because Collections2.transform() is lazily transformed and retains pointer to * original collection, which may contains references to mutable context. */ substatements = ImmutableList.copyOf(Collections2.transform(context.declaredSubstatements(), StmtContext::buildDeclared)); }
AnyxmlSchemaLocationEffectiveStatementImpl( final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx) { super(ctx); path = ctx.coerceParentContext().getSchemaPath().get().createChild(getNodeType()); }
Effective(final StmtContext<String, AnnotationStatement, ?> ctx) { super(ctx); path = ctx.coerceParentContext().getSchemaPath().get().createChild( StmtContextUtils.parseIdentifier(ctx, argument())); final TypeEffectiveStatement<?> typeStmt = SourceException.throwIfNull( firstSubstatementOfType(TypeEffectiveStatement.class), ctx.getStatementSourceReference(), "AnnotationStatementSupport %s is missing a 'type' statement", argument()); final ConcreteTypeBuilder<?> builder = ConcreteTypes.concreteTypeBuilder(typeStmt.getTypeDefinition(), path); final StmtContext<String, ?, ?> unitsStmt = StmtContextUtils.findFirstEffectiveSubstatement(ctx, UnitsStatement.class); if (unitsStmt != null) { builder.setUnits(unitsStmt.getStatementArgument()); } type = builder.build(); }
for (StmtContext<?, ?, ?> stmtCtx : ctx.allSubstatements()) { stmtCounts.computeIfAbsent(stmtCtx.getPublicDefinition(), key -> new Counter()).increment(); 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().getStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot())); throw new InvalidSubstatementException(ctx.getStatementSourceReference(), "Minimal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement, cardinality.getMin(), value, ctx.getRoot().getStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot())); throw new InvalidSubstatementException(ctx.getStatementSourceReference(), "Maximal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement, cardinality.getMax(), value, ctx.getRoot().getStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot())); final StmtContext<?, ?, ?> root = ctx.getRoot(); throw new MissingSubstatementException(ctx.getStatementSourceReference(), "%s is missing %s. Minimal count is %s. Error in module %s (%s)", currentStatement, e.getKey(), e.getValue().getMin(), root.getStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
UnrecognizedEffectiveStatementImpl(final StmtContext<String, UnrecognizedStatement, ?> ctx) { super(ctx); // FIXME: Remove following section after fixing 4380 final UnknownSchemaNode original = (UnknownSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective) .orElse(null); if (original != null) { this.maybeQNameArgument = original.getQName(); } else { QName maybeQNameArgumentInit = null; try { maybeQNameArgumentInit = StmtContextUtils.qnameFromArgument(ctx, argument()); } catch (IllegalArgumentException e) { maybeQNameArgumentInit = getNodeType(); } this.maybeQNameArgument = maybeQNameArgumentInit; } path = ctx.coerceParentContext().getSchemaPath().get().createChild(maybeQNameArgument); }
public static boolean needToCopyByUses(final StmtContext<?, ?, ?> stmtContext) { final StatementDefinition def = stmtContext.getPublicDefinition(); if (REUSED_DEF_SET.contains(def)) { LOG.trace("Will reuse {} statement {}", def, stmtContext); return false; } if (NOCOPY_FROM_GROUPING_SET.contains(def)) { return !YangStmtMapping.GROUPING.equals(stmtContext.coerceParentContext().getPublicDefinition()); } LOG.trace("Will copy {} statement {}", def, stmtContext); return true; }
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()); }
switch (ctx.coerceStatementArgument()) { case BINARY: typeStmt = BuiltinEffectiveStatement.BINARY; break; default: final QName qname = StmtContextUtils.parseNodeIdentifier(ctx, ctx.getStatementArgument()); final StmtContext<?, TypedefStatement, TypedefEffectiveStatement> typedef = SourceException.throwIfNull(ctx.getFromNamespace(TypeNamespace.class, qname), ctx.getStatementSourceReference(), "Type '%s' not found", qname); typeStmt = typedef.buildEffective().asTypeEffectiveStatement(); if (ctx.declaredSubstatements().isEmpty() && ctx.effectiveSubstatements().isEmpty()) { return typeStmt;
private static QNameModule getNewQNameModule(final StmtContext<?, ?, ?> targetCtx, final StmtContext<?, ?, ?> stmtContext) { if (targetCtx.getParentContext() == null) { return targetCtx.getFromNamespace(ModuleCtxToModuleQName.class, targetCtx); } if (targetCtx.getPublicDefinition() == YangStmtMapping.AUGMENT) { return StmtContextUtils.getRootModuleQName(targetCtx); } final Object targetStmtArgument = targetCtx.getStatementArgument(); final Object sourceStmtArgument = stmtContext.getStatementArgument(); if (targetStmtArgument instanceof QName && sourceStmtArgument instanceof QName) { return ((QName) targetStmtArgument).getModule(); } return null; } }
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(); }
protected UndeclaredEffectiveStatementBase(final StmtContext<A, D, ?> ctx) { super(ctx); this.statementDefinition = ctx.getPublicDefinition(); this.argument = ctx.getStatementArgument(); this.statementSource = ctx.getStatementSource(); final D declareInstance = ctx.buildDeclared(); Verify.verify(declareInstance == null, "Statement %s resulted in declared statement %s", declareInstance); }
ctx.getFromNamespace(GroupingNamespace.class, ctx.coerceStatementArgument()); this.groupingPath = grpCtx.getSchemaPath().get(); addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
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()); }); }
private static boolean isSupportedRefineTarget(final StmtContext<?, ?, ?> refineSubstatementCtx, final StmtContext<?, ?, ?> refineTargetNodeCtx) { final Collection<?> supportedRefineTargets = YangValidationBundles.SUPPORTED_REFINE_TARGETS .get(refineSubstatementCtx.getPublicDefinition()); return supportedRefineTargets == null || supportedRefineTargets.isEmpty() || supportedRefineTargets.contains(refineTargetNodeCtx.getPublicDefinition()); }
public static boolean isInExtensionBody(final StmtContext<?, ?, ?> stmtCtx) { StmtContext<?, ?, ?> current = stmtCtx; while (current.coerceParentContext().getParentContext() != null) { current = current.getParentContext(); if (isUnknownStatement(current)) { return true; } } return false; }