X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-reactor%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FStatementContextBase.java;fp=yang%2Fyang-parser-reactor%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FStatementContextBase.java;h=cd07b95b1cb51e30d3054050f5d6434d6234f96a;hb=3174ac0dc4fb109977fc21f95c82c07e4392172c;hp=899345574ab9f99a4d4ccbd137ba599788e9861b;hpb=34e1427fe005d38e0ba7422bdfa1a8bd3e311d87;p=yangtools.git diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index 899345574a..cd07b95b1c 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -597,23 +597,15 @@ public abstract class StatementContextBase, E checkEffectiveModelCompleted(this); final StatementSupport support = definition.support(); - final CopyPolicy policy = support.applyCopyPolicy(this, parent, type, targetModule); + final CopyPolicy policy = support.copyPolicy(); switch (policy) { case CONTEXT_INDEPENDENT: - if (hasEmptySubstatements()) { - // This statement is context-independent and has no substatements -- hence it can be freely shared. + if (substatementsContextIndependent()) { return Optional.of(replicaAsChildOf(parent)); } - // ascertaining substatements could be quite costly, let's just fall through to declared copy and deal - // shortcut it when we build the statements. + // fall through case DECLARED_COPY: - // FIXME: YANGTOOLS-694: this is still to eager, we really want to copy as a lazily-instantiated - // context, so that we can support building an effective statement without copying - // anything -- we will typically end up not being inferred against. In that case, - // this slim context should end up dealing with differences at buildContext() - // time. This is a YANGTOOLS-1067 prerequisite (which will deal with what can and - // cannot be shared across instances). return Optional.of(parent.childCopyOf(this, type, targetModule)); case IGNORE: return Optional.empty(); @@ -624,6 +616,37 @@ public abstract class StatementContextBase, E } } + private boolean substatementsContextIndependent() { + // FIXME: YANGTOOLS-1195: we really want to compute (and cache) the summary for substatements. + // + // For now we just check if there are any substatements, but we really want to ask: + // + // Are all substatements (recursively) CONTEXT_INDEPENDENT as well? + // + // Which is something we want to compute once and store. This needs to be implemented. + return hasEmptySubstatements(); + } + + // FIXME: YANGTOOLS-1195: this method is unused, but should be called from InferredStatementContext at the very + // least. It should return @NonNull -- either 'E' or EffectiveStmtCtx.Current'. Perhaps its arguments need + // to be adjusted, too. + final void asEffectiveChildOf(final Mutable parent, final CopyType type, final QNameModule targetModule) { + checkEffectiveModelCompleted(this); + + final StatementSupport support = definition.support(); + final StmtContext effective = support.effectiveCopyOf(this, parent, type, targetModule); + if (effective == this) { + LOG.debug("Should reuse {}", this); + return; + } + + // FIXME: YANGTOOLS-1195: here is probably where we want to do some statement reuse: even if the parent is + // affected, some substatements may not -- in which case we want to reuse them. This + // probably needs to be a callout of some kind. + // FIXME: YANGTOOLS-1067: an incremental improvement to that is that if no substatements changed, we want to + // be reusing the entire List and pass that as substatements. + } + @Override public final Mutable childCopyOf(final StmtContext stmt, final CopyType type, final QNameModule targetModule) {