private final @NonNull StatementContextBase<A, D, E> prototype;
private final @NonNull StatementContextBase<?, ?, ?> parent;
+ private final @NonNull StmtContext<A, D, E> originalCtx;
private final @NonNull CopyType childCopyType;
private final QNameModule targetModule;
private final A argument;
this.childCopyType = original.childCopyType;
this.targetModule = original.targetModule;
this.prototype = original.prototype;
+ this.originalCtx = original.originalCtx;
this.argument = original.argument;
}
: prototype.definition().adaptArgumentValue(prototype, targetModule);
this.childCopyType = requireNonNull(childCopyType);
this.targetModule = targetModule;
+ this.originalCtx = prototype.getOriginalCtx().orElse(prototype);
// FIXME: YANGTOOLS-784: instantiate these lazily
addEffectiveSubstatements(createEffective());
@Override
public StatementSourceReference getStatementSourceReference() {
- return prototype.getStatementSourceReference();
+ return originalCtx.getStatementSourceReference();
}
@Override
public String rawStatementArgument() {
- return prototype.rawStatementArgument();
+ return originalCtx.rawStatementArgument();
}
@Override
- public Optional<StmtContext<?, ?, ?>> getOriginalCtx() {
- final Optional<StmtContext<?, ?, ?>> orig = prototype.getOriginalCtx();
- return orig.isPresent() ? orig : Optional.of(prototype);
+ public Optional<StmtContext<A, D, E>> getOriginalCtx() {
+ return Optional.of(originalCtx);
}
@Override
- public Optional<? extends StmtContext<?, ?, ?>> getPreviousCopyCtx() {
+ public Optional<StmtContext<A, D, E>> getPreviousCopyCtx() {
return Optional.of(prototype);
}
+ @Override
+ public D buildDeclared() {
+ /*
+ * Share original instance of declared statement between all effective statements which have been copied or
+ * derived from this original declared statement.
+ */
+ return originalCtx.buildDeclared();
+ }
+
@Override
InferredStatementContext<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
return new InferredStatementContext<>(this, newParent);
// FIXME: This is messy and is probably wrong in some corner case. Even if it is correct, the way how it is correct
// relies on hard-coded maps. At the end of the day, the logic needs to be controlled by statement's
// StatementSupport.
- // FIXME: YANGTOOLS-652: these maps look very much like those in UsesStatementImpl
+ // FIXME: YANGTOOLS-652: this map looks very much like UsesStatementSupport.TOP_REUSED_DEF_SET
private static final ImmutableSet<YangStmtMapping> REUSED_DEF_SET = ImmutableSet.of(
YangStmtMapping.TYPE,
YangStmtMapping.TYPEDEF,
YangStmtMapping.USES);
- private static final ImmutableSet<YangStmtMapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(
- YangStmtMapping.DESCRIPTION,
- YangStmtMapping.REFERENCE,
- YangStmtMapping.STATUS);
private void copySubstatement(final Mutable<?, ?, ?> substatement, final Collection<Mutable<?, ?, ?>> buffer) {
final StatementDefinition def = substatement.getPublicDefinition();
buffer.add(substatement);
return;
}
- // FIXME: YANGTOOLS-652: formerly known as "needToCopyByUses" (note inverted check, though)
- if (NOCOPY_FROM_GROUPING_SET.contains(def)) {
- // This is to say: if parent of source context is a grouping, ignore this statement.
- if (YangStmtMapping.GROUPING.equals(substatement.coerceParentContext().getPublicDefinition())) {
- LOG.debug("Skipping grouping statement {}", substatement);
- return;
- }
- }
- // FIXME: YANGTOOLS-694: we are forcing a copy here, hence even statements not affected by parent, copyType
- // or targetModule (and don't forget its substatements!). This really should be a callout
- // to StatementSupport. Note if that callout is allowed to return an Optional, it can
- // take care at least of the 'grouping from uses' case above.
- final Mutable<?, ?, ?> copy = childCopyOf(substatement, childCopyType, targetModule);
- LOG.debug("Copying substatement {} for {} as {}", substatement, this, copy);
- buffer.add(copy);
+ substatement.copyAsChildOf(this, childCopyType, targetModule).ifPresent(buffer::add);
}
// Statement copy mess ends here