X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=parser%2Fyang-parser-reactor%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FInferredStatementContext.java;h=9349e3ff6ca2b5c6f31d462e85b96cc19c810075;hb=0f34ef9c1d749b903a476b84c3c54e5e98225669;hp=c1e4386f21201b34afafaf575ddb5e035e9bffd7;hpb=fc17f39c478a20907bec485d1b9b38fdb9eba0c8;p=yangtools.git diff --git a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java index c1e4386f21..9349e3ff6c 100644 --- a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java +++ b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java @@ -87,7 +87,7 @@ final class InferredStatementContext, E extend private final @NonNull StatementContextBase prototype; private final @NonNull StatementContextBase parent; - private final @NonNull StmtContext originalCtx; + private final @NonNull ReactorStmtCtx originalCtx; private final QNameModule targetModule; private final A argument; @@ -122,7 +122,10 @@ final class InferredStatementContext, E extend this.argument = targetModule == null ? prototype.argument() : prototype.definition().adaptArgumentValue(prototype, targetModule); this.targetModule = targetModule; - this.originalCtx = prototype.getOriginalCtx().orElse(prototype); + + final var origCtx = prototype.getOriginalCtx().orElse(prototype); + verify(origCtx instanceof ReactorStmtCtx, "Unexpected original %s", origCtx); + this.originalCtx = (ReactorStmtCtx) origCtx; // Mark prototype as blocking statement cleanup prototype.incRef(); @@ -139,13 +142,13 @@ final class InferredStatementContext, E extend } @Override - public Iterable> allSubstatements() { + public Iterable> allSubstatements() { // No need to concat with declared return effectiveSubstatements(); } @Override - public Stream> allSubstatementsStream() { + public Stream> allSubstatementsStream() { // No need to concat with declared return effectiveSubstatements().stream(); } @@ -194,6 +197,7 @@ final class InferredStatementContext, E extend @Override public void addEffectiveSubstatement(final Mutable substatement) { substatements = addEffectiveSubstatement(ensureEffectiveSubstatements(), substatement); + afterAddEffectiveSubstatement(substatement); } @Override @@ -211,10 +215,21 @@ final class InferredStatementContext, E extend // If we have not materialized we do not have a difference in effective substatements, hence we can forward // towards the source of the statement. accessSubstatements(); - return substatements == null ? tryToReusePrototype(factory) : super.createEffective(factory); + return substatements == null ? tryToReusePrototype(factory) : createInferredEffective(factory); + } + + private @NonNull E createInferredEffective(final @NonNull StatementFactory factory) { + return createInferredEffective(factory, this, streamDeclared(), streamEffective()); + } + + @Override + E createInferredEffective(final StatementFactory factory, final InferredStatementContext ctx, + final Stream> declared, + final Stream> effective) { + return originalCtx.createInferredEffective(factory, ctx, declared, effective); } - private @NonNull E tryToReusePrototype(final StatementFactory factory) { + private @NonNull E tryToReusePrototype(final @NonNull StatementFactory factory) { final E origEffective = prototype.buildEffective(); final Collection> origSubstatements = origEffective.effectiveSubstatements(); @@ -273,10 +288,12 @@ final class InferredStatementContext, E extend prototype.decRef(); // Values are the effective copies, hence this efficiently deals with recursion. - return internAlongCopyAxis(factory, factory.createEffective(this, declared.stream(), effective.stream())); + return internAlongCopyAxis(factory, + originalCtx.createInferredEffective(factory, this, declared.stream(), effective.stream())); } - private @NonNull E tryToReuseSubstatements(final StatementFactory factory, final @NonNull E original) { + private @NonNull E tryToReuseSubstatements(final @NonNull StatementFactory factory, + final @NonNull E original) { if (allSubstatementsContextIndependent()) { LOG.debug("Reusing substatements of: {}", prototype); substatements = noRefs() ? REUSED_SUBSTATEMENTS : reusePrototypeReplicas(); @@ -286,7 +303,7 @@ final class InferredStatementContext, E extend // Fall back to full instantiation, which populates our substatements. Then check if we should be reusing // the substatement list, as this operation turned out to not affect them. - final E effective = super.createEffective(factory); + final E effective = createInferredEffective(factory); // Since we have forced instantiation to deal with this case, we also need to reset the 'modified' flag setUnmodified();