From faf7ce6d1e3acb2af2b846746e8495749301b484 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 10 Jan 2022 13:25:59 +0100 Subject: [PATCH] Deprecate ImmutableNodes.fromInstanceId() with deepestElement The two methods allowing an override of the deepest element have only a single user, which is broken by their semantics. Deprecate them for removal, so that we flush out anyone else still relying on them. JIRA: YANGTOOLS-1389 Change-Id: I52e8bdebc5488d095645a7bfb45a5c9cf400ecb0 Signed-off-by: Robert Varga --- .../yang/data/impl/schema/ImmutableNodes.java | 15 +++++++++++++-- .../data/impl/schema/InstanceIdToNodesTest.java | 9 +++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java index 24cf7aabc1..6f9519efb6 100644 --- a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java +++ b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java @@ -205,7 +205,7 @@ public final class ImmutableNodes { * @return serialized normalized node for provided instance Id */ public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id) { - return fromInstanceId(ctx, id, Optional.empty()); + return fromInstanceIdImpl(ctx, id, Optional.empty()); } /** @@ -216,10 +216,13 @@ public final class ImmutableNodes { * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided * instance identifier * @return serialized normalized node for provided instance Id with overridden last child. + * @deprecated This method is a historic hack, which has only a single downstream user. It is scheduled for removal + * without a replacement. */ + @Deprecated(since = "7.0.12", forRemoval = true) public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final NormalizedNode deepestElement) { - return fromInstanceId(ctx, id, Optional.of(deepestElement)); + return fromInstanceIdImpl(ctx, id, Optional.of(deepestElement)); } /** @@ -231,9 +234,17 @@ public final class ImmutableNodes { * instance identifier * @return serialized normalized node for provided instance Id with (optionally) overridden last child * and (optionally) marked with specific operation attribute. + * @deprecated This method is a historic hack, which has only a single downstream user. It is scheduled for removal + * without a replacement. */ + @Deprecated(since = "7.0.12", forRemoval = true) public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final Optional deepestElement) { + return fromInstanceIdImpl(ctx, id, deepestElement); + } + + private static @NonNull NormalizedNode fromInstanceIdImpl(final SchemaContext ctx, final YangInstanceIdentifier id, + final Optional deepestElement) { final PathArgument topLevelElement; final InstanceIdToNodes instanceIdToNodes; final Iterator it = id.getPathArguments().iterator(); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java index 4634c90c6f..4deb1900c1 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java @@ -31,6 +31,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -43,7 +44,7 @@ public class InstanceIdToNodesTest { private static final QName BAR = QName.create(ID, "bar"); private static final NodeIdentifier TWO_KEY_LIST = NodeIdentifier.create(QName.create(ID, "two-key-list")); - private static SchemaContext ctx; + private static EffectiveModelContext ctx; private final NodeIdentifier rootContainer = new NodeIdentifier(QName.create(NS, REVISION, "test")); private final NodeIdentifier outerContainer = new NodeIdentifier(QName.create(NS, REVISION, "outer-container")); @@ -71,6 +72,7 @@ public class InstanceIdToNodesTest { } @Test + @Deprecated(since = "7.0.12", forRemoval = true) public void testInAugment() { final LeafNode leaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("").build(); final ContainerNode expectedFilter = Builders @@ -91,6 +93,7 @@ public class InstanceIdToNodesTest { } @Test + @Deprecated(since = "7.0.12", forRemoval = true) public void testInAugmentLeafOverride() { final LeafNode lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf) .withValue("randomValue").build(); @@ -111,6 +114,7 @@ public class InstanceIdToNodesTest { } @Test + @Deprecated(since = "7.0.12", forRemoval = true) public void testListChoice() { final LeafNode leaf = Builders.leafBuilder().withNodeIdentifier(leafFromCase).withValue("").build(); final ContainerNode expectedFilter = Builders @@ -142,6 +146,7 @@ public class InstanceIdToNodesTest { } @Test + @Deprecated(since = "7.0.12", forRemoval = true) public void testTopContainerLastChildOverride() { final ContainerNode expectedStructure = Builders .containerBuilder() @@ -180,7 +185,7 @@ public class InstanceIdToNodesTest { .withChild( Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(ID)) .withValue(1).build()).build(); - final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(this.outerList).withChild(outerListEntry) + final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(outerList).withChild(outerListEntry) .build(); final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer) .withChild(lastChild).build(); -- 2.36.6