/** * Adapts the argument value to match a new module. * * @param ctx * Context, which may be used to access source-specific * namespaces required for parsing. * @param targetModule * Target module, may not be null. * @return Adapted argument value. The default implementation returns original value stored in context. */ default A adaptArgumentValue(final StmtContext<A, D, E> ctx, final QNameModule targetModule) { return ctx.getStatementArgument(); }
@SuppressWarnings("unchecked") public static <A, D extends DeclaredStatement<A>> A firstAttributeOf(final StmtContext<?, ?, ?> ctx, final Class<D> declaredType) { return producesDeclared(ctx, declaredType) ? (A) ctx.getStatementArgument() : null; }
static SourceIdentifier getImportedSourceIdentifier(final StmtContext<String, ImportStatement, ?> stmt) { final StmtContext<Revision, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class); return revision == null ? RevisionSourceIdentifier.create(stmt.getStatementArgument()) : RevisionSourceIdentifier.create(stmt.getStatementArgument(), revision.getStatementArgument()); } }
@SuppressWarnings("unchecked") public static <A, D extends DeclaredStatement<A>> A firstAttributeOf( final Iterable<? extends StmtContext<?, ?, ?>> contexts, final Class<D> declaredType) { for (final StmtContext<?, ?, ?> ctx : contexts) { if (producesDeclared(ctx, declaredType)) { return (A) ctx.getStatementArgument(); } } return null; }
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; }
@Override public QName adaptArgumentValue(final StmtContext<QName, D, E> ctx, final QNameModule targetModule) { return ctx.getFromNamespace(QNameCacheNamespace.class, ctx.getStatementArgument().withModule(targetModule)); } }
MustEffectiveStatementImpl(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) { super(ctx); xpath = ctx.getStatementArgument(); description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null); errorAppTag = findFirstEffectiveSubstatementArgument(ErrorAppTagEffectiveStatement.class).orElse(null); errorMessage = findFirstEffectiveSubstatementArgument(ErrorMessageEffectiveStatement.class).orElse(null); reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null); }
/** * Return the statement argument in literal format. * * @return raw statement argument string * @throws VerifyException if this statement does not have an argument */ default @NonNull A coerceStatementArgument() { return verifyNotNull(getStatementArgument(), "Statement context %s does not have an argument", this); }
DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) { super(ctx); this.targetPath = ctx.getStatementArgument().asSchemaPath(); this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class)); description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null); reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null); List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>(); for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof UnknownSchemaNode) { unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement); } } unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit); }
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)); }
public static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) { final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root); if (qNameModule != null) { // creates SourceIdentifier for a module return RevisionSourceIdentifier.create((String) root.getStatementArgument(), qNameModule.getRevision()); } // creates SourceIdentifier for a submodule final Optional<Revision> revision = getLatestRevision(root.declaredSubstatements()); return RevisionSourceIdentifier.create((String) root.getStatementArgument(), revision); }
@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()); } }
@Override public EffectiveStatement<QName, NotificationStatement> createEffective( final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) { SourceException.throwIf(StmtContextUtils.hasAncestorOfType(ctx, ILLEGAL_PARENTS), ctx.getStatementSourceReference(), "Notification %s is defined within an rpc, action, or another notification", ctx.getStatementArgument()); SourceException.throwIf(!StmtContextUtils.hasAncestorOfTypeWithChildOfType(ctx, YangStmtMapping.LIST, YangStmtMapping.KEY), ctx.getStatementSourceReference(), "Notification %s is defined within a list that has no key statement", ctx.getStatementArgument()); SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.CASE), ctx.getStatementSourceReference(), "Notification %s is defined within a case statement", ctx.getStatementArgument()); return new NotificationEffectiveStatementImpl(ctx); }
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); }
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()); }); }
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()); }
@Override public final void onPreLinkageDeclared( final Mutable<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> stmt) { final StmtContext<Revision, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class); stmt.addRequiredSource(revision == null ? RevisionSourceIdentifier.create(stmt.getStatementArgument()) : RevisionSourceIdentifier.create(stmt.getStatementArgument(), revision.getStatementArgument())); }
@Override public void apply(final InferenceContext ctx) { final StmtContext<?, ?, ?> includedSubModuleContext = requiresCtxPrerequisite.resolve(ctx); stmt.addToNs(IncludedModuleContext.class, revision != null ? RevisionSourceIdentifier.create(submoduleName, revision.getStatementArgument()) : RevisionSourceIdentifier.create(submoduleName), includedSubModuleContext); stmt.addToNs(IncludedSubmoduleNameToModuleCtx.class, stmt.getStatementArgument(), includedSubModuleContext); }
@Override public void apply(final InferenceContext ctx) { final StmtContext<?, ?, ?> importedModuleContext = imported.resolve(ctx); Verify.verify(moduleName.equals(importedModuleContext.getStatementArgument())); final URI importedModuleNamespace = importedModuleContext.getFromNamespace(ModuleNameToNamespace.class, moduleName); Verify.verifyNotNull(importedModuleNamespace); final String impPrefix = SourceException.throwIfNull( firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt.getStatementSourceReference(), "Missing prefix statement"); stmt.addToNs(ImpPrefixToNamespace.class, impPrefix, importedModuleNamespace); }
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()); }