Deprecate ImmutableNodes.fromInstanceId() with deepestElement 49/99249/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 10 Jan 2022 12:25:59 +0000 (13:25 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 10 Jan 2022 12:34:03 +0000 (13:34 +0100)
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 <robert.varga@pantheon.tech>
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java
data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java

index 24cf7aabc1bcccd484e144b0cf4c2af048ef8d35..6f9519efb64b80d92cab18d352a553ab66fe4d93 100644 (file)
@@ -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<NormalizedNode> deepestElement) {
+        return fromInstanceIdImpl(ctx, id, deepestElement);
+    }
+
+    private static @NonNull NormalizedNode fromInstanceIdImpl(final SchemaContext ctx, final YangInstanceIdentifier id,
+            final Optional<NormalizedNode> deepestElement) {
         final PathArgument topLevelElement;
         final InstanceIdToNodes<?> instanceIdToNodes;
         final Iterator<PathArgument> it = id.getPathArguments().iterator();
index 4634c90c6fd8f1fe4c0b962af39fccbf5e958c4d..4deb1900c1dbe79365dd296c230af74b80b832dd 100644 (file)
@@ -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<Object> 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();