@Override
final E createEffective(final StatementFactory<A, D, E> factory) {
- return createEffective(factory, this);
+ return createEffective(factory, this, streamDeclared(), streamEffective());
}
// Creates EffectiveStatement through full materialization and assumes declared statement presence
private @NonNull E createEffective(final StatementFactory<A, D, E> factory,
- final StatementContextBase<A, D, E> ctx) {
+ final StatementContextBase<A, D, E> ctx, final Stream<? extends StmtContext<?, ?, ?>> declared,
+ final Stream<? extends StmtContext<?, ?, ?>> effective) {
// Statement reference count infrastructure makes an assumption that effective statement is only built after
// the declared statement is already done. Statements tracked by this class always have a declared view, and
// we need to ensure that is built before we touch effective substatements.
//
// Once the effective substatement stream has been exhausted, reference counting will triggers a sweep, hence
// the substatements may be gone by the time the factory attempts to acquire the declared statement.
- declared();
+ ctx.declared();
- return factory.createEffective(ctx, ctx.streamDeclared(), ctx.streamEffective());
+ return factory.createEffective(ctx, declared, effective);
}
@Override
final E createInferredEffective(final StatementFactory<A, D, E> factory,
- final InferredStatementContext<A, D, E> ctx) {
- return createEffective(factory, ctx);
+ final InferredStatementContext<A, D, E> ctx, final Stream<? extends StmtContext<?, ?, ?>> declared,
+ final Stream<? extends StmtContext<?, ?, ?>> effective) {
+ return createEffective(factory, ctx, declared, effective);
}
/**
private final @NonNull StatementContextBase<A, D, E> prototype;
private final @NonNull StatementContextBase<?, ?, ?> parent;
- private final @NonNull StmtContext<A, D, E> originalCtx;
+ private final @NonNull ReactorStmtCtx<A, D, E> originalCtx;
private final QNameModule targetModule;
private final A argument;
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<A, D, E>) origCtx;
// Mark prototype as blocking statement cleanup
prototype.incRef();
// 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) : createInferredEffective(factory, this);
+ return substatements == null ? tryToReusePrototype(factory) : createInferredEffective(factory);
+ }
+
+ private @NonNull E createInferredEffective(final @NonNull StatementFactory<A, D, E> factory) {
+ return createInferredEffective(factory, this, streamDeclared(), streamEffective());
}
@Override
- E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx) {
- return prototype.createInferredEffective(factory, ctx);
+ E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx,
+ final Stream<? extends StmtContext<?, ?, ?>> declared,
+ final Stream<? extends StmtContext<?, ?, ?>> effective) {
+ return originalCtx.createInferredEffective(factory, ctx, declared, effective);
}
private @NonNull E tryToReusePrototype(final @NonNull StatementFactory<A, D, E> factory) {
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 @NonNull StatementFactory<A, D, E> factory,
// 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 = createInferredEffective(factory, this);
+ final E effective = createInferredEffective(factory);
// Since we have forced instantiation to deal with this case, we also need to reset the 'modified' flag
setUnmodified();
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.ExecutionOrder;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementFactory;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
abstract @NonNull E createEffective();
+ /**
+ * Routing of the request to build an effective statement from {@link InferredStatementContext} towards the original
+ * definition site. This is needed to pick the correct instantiation method: for declared statements we will
+ * eventually land in {@link AbstractResumedStatement}, for underclared statements that will be
+ * {@link UndeclaredStmtCtx}.
+ *
+ * @param factory Statement factory
+ * @param ctx Inferred statement context, i.e. where the effective statement is instantiated
+ * @return Built effective stateue
+ */
+ abstract @NonNull E createInferredEffective(@NonNull StatementFactory<A, D, E> factory,
+ @NonNull InferredStatementContext<A, D, E> ctx, Stream<? extends StmtContext<?, ?, ?>> declared,
+ Stream<? extends StmtContext<?, ?, ?>> effective);
+
/**
* Attach an effective copy of this statement. This essentially acts as a map, where we make a few assumptions:
* <ul>
import java.util.Collection;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementFactory;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
return source.buildEffective();
}
+ @Override
+ E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx,
+ final Stream<? extends StmtContext<?, ?, ?>> declared,
+ final Stream<? extends StmtContext<?, ?, ?>> effective) {
+ return source.createInferredEffective(factory, ctx, declared, effective);
+ }
+
@Override
ReactorStmtCtx<A, D, E> unmodifiedEffectiveSource() {
return source.unmodifiedEffectiveSource();
abstract @NonNull E createEffective(@NonNull StatementFactory<A, D, E> factory);
- /**
- * Routing of the request to build an effective statement from {@link InferredStatementContext} towards the original
- * definition site. This is needed to pick the correct instantiation method: for declared statements we will
- * eventually land in {@link AbstractResumedStatement}, for underclared statements that will be
- * {@link UndeclaredStmtCtx}.
- *
- * @param factory Statement factory
- * @param ctx Inferred statement context, i.e. where the effective statement is instantiated
- * @return Built effective stateue
- */
- abstract @NonNull E createInferredEffective(@NonNull StatementFactory<A, D, E> factory,
- @NonNull InferredStatementContext<A, D, E> ctx);
-
/**
* Return a stream of declared statements which can be built into an {@link EffectiveStatement}, as per
* {@link StmtContext#buildEffective()} contract.
}
@Override
- E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx) {
- return createEffective(factory, new ForwardingUndeclaredCurrent<>(ctx), ctx.streamEffective());
+ E createInferredEffective(final StatementFactory<A, D, E> factory, final InferredStatementContext<A, D, E> ctx,
+ final Stream<? extends StmtContext<?, ?, ?>> declared,
+ final Stream<? extends StmtContext<?, ?, ?>> effective) {
+ final long declaredCount = declared.count();
+ verify(declaredCount == 0, "Unexpected non-empty declared statements in %s", ctx);
+ return createEffective(factory, new ForwardingUndeclaredCurrent<>(ctx), effective);
}
/*
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import org.junit.Test;
+
+public class YT1407Test extends AbstractYangTest {
+ @Test
+ public void testUsedUndeclaredCase() {
+ assertEffectiveModelDir("/bugs/YT1407");
+ }
+}
--- /dev/null
+module ietf-lisp-address-types {
+ namespace "urn:ietf:params:xml:ns:yang:ietf-lisp-address-types";
+ prefix laddr;
+
+ grouping lisp-address {
+ choice address {
+ container null-address {
+ leaf address {
+ type empty;
+ }
+ }
+ }
+ }
+}
--- /dev/null
+module odl-inet-binary-types {
+ namespace "urn:opendaylight:lfm:inet-binary-types";
+ prefix "inet-binary";
+
+ typedef ipv4-address-binary {
+ type binary {
+ length "4";
+ }
+ }
+}
--- /dev/null
+module odl-lisp-address-types {
+ namespace "urn:opendaylight:lfm:lisp-binary-address-types";
+ prefix "lisp-binary";
+
+ import ietf-lisp-address-types { prefix laddr; }
+ import odl-inet-binary-types { prefix bin; }
+
+ grouping augmented-lisp-address {
+ uses laddr:lisp-address {
+ augment "address" {
+ case ipv4-binary {
+ leaf ipv4-binary {
+ type bin:ipv4-address-binary;
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+module odl-lisp-proto {
+ namespace "urn:opendaylight:lfm:lisp-proto";
+ prefix "lisp-proto";
+
+ import odl-lisp-address-types { prefix odl-lisp-address; }
+
+ grouping eid-container {
+ container eid {
+ uses odl-lisp-address:augmented-lisp-address;
+ }
+ }
+
+ grouping eid-list {
+ list eid-item {
+ key "eid-item-id";
+ leaf eid-item-id {
+ type string;
+ }
+ uses eid-container;
+ }
+ }
+}