import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.OnDemandSchemaTreeStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextDefaults;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
- public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
- ensureSubstatements();
- return super.mutableEffectiveSubstatements();
- }
-
- @Override
- public void addEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
- ensureSubstatements();
- super.addEffectiveSubstatement(substatement);
- }
-
- @Override
- public void addEffectiveSubstatements(final Collection<? extends Mutable<?, ?, ?>> statements) {
- ensureSubstatements();
- super.addEffectiveSubstatements(statements);
+ InferredStatementContext<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
+ return new InferredStatementContext<>(this, newParent);
}
@Override
- public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef,
- final String statementArg) {
- ensureSubstatements();
- super.removeStatementFromEffectiveSubstatements(statementDef, statementArg);
+ boolean hasEmptySubstatements() {
+ ensureEffectiveSubstatements();
+ return hasEmptyEffectiveSubstatements();
}
@Override
- public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef) {
- ensureSubstatements();
- super.removeStatementFromEffectiveSubstatements(statementDef);
- }
+ public <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
+ final @NonNull Class<Z> type) {
+ if (substatementsInitialized()) {
+ return StmtContextDefaults.findSubstatementArgument(this, type);
+ }
- @Override
- InferredStatementContext<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
- return new InferredStatementContext<>(this, newParent);
+ final Optional<X> templateArg = prototype.findSubstatementArgument(type);
+ if (templateArg.isEmpty()) {
+ return templateArg;
+ }
+ if (SchemaTreeEffectiveStatement.class.isAssignableFrom(type)) {
+ // X is known to be QName
+ return (Optional<X>) templateArg.map(template -> ((QName) template).bindTo(targetModule));
+ }
+ return templateArg;
}
@Override
- boolean hasEmptySubstatements() {
- ensureSubstatements();
- return hasEmptyEffectiveSubstatements();
+ public boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
+ return substatementsInitialized() ? StmtContextDefaults.hasSubstatement(prototype, type)
+ : prototype.hasSubstatement(type);
}
@Override
StmtContext<QName, D, E> requestSchemaTreeChild(final QName qname) {
LOG.debug("Materializing on lookup of {}", qname);
// FIXME: YANGTOOLS-1160: we do not want to force full materialization here
- ensureSubstatements();
+ ensureEffectiveSubstatements();
// Now we have to do a lookup as we do not have access to the namespace being populated (yet). Here we are
// bypassing additional checks and talk directly to superclass to get the statements.
// Instantiate this statement's effective substatements. Note this method has side-effects in namespaces and overall
// BuildGlobalContext, hence it must be called at most once.
- private void ensureSubstatements() {
+ @Override
+ void ensureEffectiveSubstatements() {
if (!substatementsInitialized()) {
initializeSubstatements();
}
}
+ @Override
+ Iterable<StatementContextBase<?, ?, ?>> effectiveChildrenToComplete() {
+ // When we have not initialized, there are no statements to catch up: we will catch up when we are copying
+ // from prototype (which is already at ModelProcessingPhase.EFFECTIVE_MODEL)
+ return substatementsInitialized() ? super.effectiveChildrenToComplete() : List.of();
+ }
+
private void initializeSubstatements() {
final Collection<? extends StatementContextBase<?, ?, ?>> declared = prototype.mutableDeclaredSubstatements();
final Collection<? extends Mutable<?, ?, ?>> effective = prototype.mutableEffectiveSubstatements();