final ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction( ModelProcessingPhase.STATEMENT_DEFINITION); final Prerequisite<StmtContext<?, ?, ?>> requiresPrereq = baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName, ModelProcessingPhase.STATEMENT_DEFINITION); final Prerequisite<StmtContext.Mutable<?, ?, ?>> mutatesPrereq = baseIdentityAction.mutatesCtx( baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION); baseIdentityAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {
final QName groupingName = usesNode.getStatementArgument(); final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode, GroupingNamespace.class, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL); final Prerequisite<? extends StmtContext.Mutable<?, ?, ?>> targetNodePre = usesAction.mutatesEffectiveCtx( usesNode.getParentContext()); usesAction.apply(new InferenceAction() {
@Override public void onLinkageDeclared(final Mutable<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> belongsToCtx) { ModelActionBuilder belongsToAction = belongsToCtx.newInferenceAction(ModelProcessingPhase.SOURCE_LINKAGE); final SourceIdentifier belongsToSourceIdentifier = getSourceIdentifier(belongsToCtx); final Prerequisite<StmtContext<?, ?, ?>> belongsToPrereq = belongsToAction.requiresCtx(belongsToCtx, ModuleNamespaceForBelongsTo.class, belongsToCtx.coerceStatementArgument(), ModelProcessingPhase.SOURCE_LINKAGE); belongsToAction.apply(new InferenceAction() { @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); } @Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { if (failed.contains(belongsToPrereq)) { throw new InferenceException(belongsToCtx.getStatementSourceReference(), "Module '%s' from belongs-to was not found", belongsToCtx.getStatementArgument()); } } }); }
final Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL); final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtxPath(getSearchRoot(augmentNode), ChildSchemaNodeNamespace.class, augmentNode.coerceStatementArgument().getPathFromRoot()); augmentAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {
<K, E extends EffectiveStatement<?, ?>, N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> @NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
deviateAction.requiresCtx(deviateStmtCtx, ModelProcessingPhase.EFFECTIVE_MODEL); deviateAction.mutatesEffectiveCtxPath(deviateStmtCtx.getRoot(), ChildSchemaNodeNamespace.class, deviationTarget.getPathFromRoot()); deviateAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {
final Prerequisite<StmtContext<?, ?, ?>> requiresCtxPrerequisite; if (revision == null) { requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class, NamespaceKeyCriterion.latestRevisionModule(submoduleName), SOURCE_LINKAGE); } else { requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class, RevisionSourceIdentifier.create(submoduleName, Optional.of(revision.getStatementArgument())), SOURCE_LINKAGE); includeAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {
final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt, PreLinkageModuleNamespace.class, moduleName, SOURCE_PRE_LINKAGE); final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction .mutatesCtx(stmt.getRoot(), SOURCE_PRE_LINKAGE); importAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {
@Override public final void onFullDefinitionDeclared( final Mutable<String, TypeStatement, EffectiveStatement<String, TypeStatement>> stmt) { super.onFullDefinitionDeclared(stmt); // if it is yang built-in type, no prerequisite is needed, so simply return if (BUILT_IN_TYPES.containsKey(stmt.getStatementArgument())) { return; } final QName typeQName = StmtContextUtils.parseNodeIdentifier(stmt, stmt.getStatementArgument()); final ModelActionBuilder typeAction = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL); final Prerequisite<StmtContext<?, ?, ?>> typePrereq = typeAction.requiresCtx(stmt, TypeNamespace.class, typeQName, ModelProcessingPhase.EFFECTIVE_MODEL); typeAction.mutatesEffectiveCtx(stmt.getParentContext()); /* * If the type does not exist, throw new InferenceException. * Otherwise perform no operation. */ typeAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) { // Intentional NOOP } @Override public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) { InferenceException.throwIf(failed.contains(typePrereq), stmt.getStatementSourceReference(), "Type [%s] was not found.", typeQName); } }); }
final Revision revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class); if (revision == null) { imported = importAction.requiresCtx(stmt, ModuleNamespace.class, NamespaceKeyCriterion.latestRevisionModule(moduleName), SOURCE_LINKAGE); } else { imported = importAction.requiresCtx(stmt, ModuleNamespace.class, RevisionSourceIdentifier.create(moduleName, Optional.of(revision)), SOURCE_LINKAGE); final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE); importAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {
: new SemVerCompatibleCriterion(moduleName, semanticVersion); final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt, SemanticVersionModuleNamespace.class, criterion, SOURCE_LINKAGE); final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE); importAction.apply(new InferenceAction() { @Override public void apply(final InferenceContext ctx) {