Bump upstreams
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / DataObjectCodecContext.java
index cbc3c15eb9b2bd759b42473798bd992ac596992b..b63befcbe96f7ef77125fe1664cbf69ff309e555 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableCollection;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.VarHandle;
 import java.lang.reflect.Method;
@@ -27,7 +28,6 @@ import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
 import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
-import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.BindingObject;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -47,8 +47,9 @@ import org.slf4j.LoggerFactory;
  * This class is an implementation detail. It is public only due to technical reasons and may change at any time.
  */
 @Beta
-public abstract class DataObjectCodecContext<D extends DataObject, T extends CompositeRuntimeType>
-        extends AbstractDataObjectCodecContext<D, T> implements BindingDataObjectCodecTreeNode<D> {
+public abstract sealed class DataObjectCodecContext<D extends DataObject, T extends CompositeRuntimeType>
+        extends AbstractDataObjectCodecContext<D, T> implements BindingDataObjectCodecTreeNode<D>
+        permits CaseCodecContext, ContainerLikeCodecContext, ListCodecContext, NotificationCodecContext {
     private static final Logger LOG = LoggerFactory.getLogger(DataObjectCodecContext.class);
 
     private static final VarHandle MISMATCHED_AUGMENTED;
@@ -69,21 +70,22 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
     // Note this the content of this field depends only of invariants expressed as this class's fields or
     // BindingRuntimeContext. It is only accessed via MISMATCHED_AUGMENTED above.
     @SuppressWarnings("unused")
-    private volatile ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> mismatchedAugmented = ImmutableMap.of();
+    @SuppressFBWarnings(value = "URF_UNREAD_FIELD", justification = "https://github.com/spotbugs/spotbugs/issues/2749")
+    private volatile ImmutableMap<Class<?>, CommonDataObjectCodecPrototype<?>> mismatchedAugmented = ImmutableMap.of();
 
-    DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype) {
+    DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype) {
         this(prototype, CodecItemFactory.of());
     }
 
-    DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype, final CodecItemFactory itemFactory) {
+    DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype, final CodecItemFactory itemFactory) {
         this(prototype, new CodecDataObjectAnalysis<>(prototype, itemFactory, null));
     }
 
-    DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype, final Method keyMethod) {
+    DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype, final Method keyMethod) {
         this(prototype, new CodecDataObjectAnalysis<>(prototype, CodecItemFactory.of(), keyMethod));
     }
 
-    private DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype,
+    private DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype,
             final CodecDataObjectAnalysis<T> analysis) {
         super(prototype, analysis);
 
@@ -108,13 +110,13 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
     }
 
     @Override
-    final DataContainerCodecPrototype<?> pathChildPrototype(final Class<? extends DataObject> argType) {
+    final CommonDataObjectCodecPrototype<?> pathChildPrototype(final Class<? extends DataObject> argType) {
         final var child = super.pathChildPrototype(argType);
         return child != null ? child : augmentToPrototype.get(argType);
     }
 
     @Override
-    final DataContainerCodecPrototype<?> streamChildPrototype(final Class<?> childClass) {
+    final CommonDataObjectCodecPrototype<?> streamChildPrototype(final Class<?> childClass) {
         final var child = super.streamChildPrototype(childClass);
         if (child == null && Augmentation.class.isAssignableFrom(childClass)) {
             return getAugmentationProtoByClass(childClass);
@@ -123,7 +125,7 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
     }
 
     @Override
-    final NodeContextSupplier yangChildSupplier(final NodeIdentifier arg) {
+    final CodecContextSupplier yangChildSupplier(final NodeIdentifier arg) {
         final var child = super.yangChildSupplier(arg);
         if (child == null) {
             final var augClass = yangToAugmentClass.get(arg);
@@ -154,7 +156,7 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
             final ImmutableMap<Class<?>, AugmentationCodecPrototype> oldMismatched,
             final @NonNull Class<?> childClass) {
         @SuppressWarnings("rawtypes")
-        final Class<?> augTarget = BindingReflections.findAugmentationTarget((Class) childClass);
+        final Class<?> augTarget = findAugmentationTarget((Class) childClass);
         // Do not bother with proposals which are not augmentations of our class, or do not match what the runtime
         // context would load.
         if (getBindingClass().equals(augTarget) && belongsToRuntimeContext(childClass)) {
@@ -175,7 +177,7 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
         var expected = oldMismatched;
         while (true) {
             final var newMismatched =
-                ImmutableMap.<Class<?>, DataContainerCodecPrototype<?>>builderWithExpectedSize(expected.size() + 1)
+                ImmutableMap.<Class<?>, CommonDataObjectCodecPrototype<?>>builderWithExpectedSize(expected.size() + 1)
                     .putAll(expected)
                     .put(childClass, prototype)
                     .build();
@@ -216,11 +218,9 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
             .map(stmt -> new NodeIdentifier((QName) stmt.argument()))
             .collect(ImmutableSet.toImmutableSet());
 
-        final var it = childPaths.iterator();
-        if (!it.hasNext()) {
+        if (childPaths.isEmpty()) {
             return null;
         }
-        final var namespace = it.next().getNodeType().getModule();
 
         final var factory = factory();
         final GeneratedType javaType = augment.javaType();
@@ -231,7 +231,7 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
             throw new IllegalStateException(
                 "RuntimeContext references type " + javaType + " but failed to load its class", e);
         }
-        return new AugmentationCodecPrototype(augClass, namespace, augment, factory, childPaths);
+        return new AugmentationCodecPrototype(augClass, augment, factory, childPaths);
     }
 
     @Override
@@ -257,7 +257,10 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Com
             final var bindingClass = entry.getKey();
             final var codecProto = augmentToPrototype.get(bindingClass);
             if (codecProto != null) {
-                map.put(bindingClass, codecProto.get().deserializeObject(entry.getValue().build()));
+                final var bindingObj = codecProto.get().deserializeObject(entry.getValue().build());
+                if (bindingObj != null) {
+                    map.put(bindingClass, bindingObj);
+                }
             }
         }
         return map;