From 27af6e9fc4d7b3f557ba0a24561afbdbed5a9894 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 12 Jan 2024 00:35:38 +0100 Subject: [PATCH] Make AugmentationCodecPrototype generic Augmentations should capture their target type, which eliminates the need for quite a few casts. JIRA: MDSAL-815 Change-Id: I3d9c8326ac2bb24135c66ecfe240ed95cea98318 Signed-off-by: Robert Varga --- .../codec/impl/AugmentationCodecContext.java | 6 +++--- .../impl/AugmentationCodecPrototype.java | 10 +++++----- .../codec/impl/DataObjectCodecContext.java | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecContext.java index d7842638aa..c4250f65a3 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecContext.java @@ -33,7 +33,7 @@ final class AugmentationCodecContext> private final MethodHandle proxyConstructor; - private AugmentationCodecContext(final AugmentationCodecPrototype prototype, + private AugmentationCodecContext(final AugmentationCodecPrototype prototype, final DataContainerAnalysis analysis) { super(prototype, analysis); @@ -50,7 +50,7 @@ final class AugmentationCodecContext> proxyConstructor = ctor.asType(DATAOBJECT_TYPE); } - AugmentationCodecContext(final AugmentationCodecPrototype prototype) { + AugmentationCodecContext(final AugmentationCodecPrototype prototype) { this(prototype, new DataContainerAnalysis<>(prototype, CodecItemFactory.of())); } @@ -73,7 +73,7 @@ final class AugmentationCodecContext> @SuppressWarnings("checkstyle:illegalCatch") @Override public D filterFrom(final DataContainerNode parentData) { - for (var childArg : ((AugmentationCodecPrototype) prototype()).getChildArgs()) { + for (var childArg : ((AugmentationCodecPrototype) prototype()).getChildArgs()) { if (parentData.childByArg(childArg) != null) { try { return (D) proxyConstructor.invokeExact(this, parentData); diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecPrototype.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecPrototype.java index 5f10f1abc5..1b5ae222f6 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecPrototype.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/AugmentationCodecPrototype.java @@ -12,17 +12,17 @@ import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableSet; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType; -import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.binding.NodeStep; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -final class AugmentationCodecPrototype extends CommonDataObjectCodecPrototype { +final class AugmentationCodecPrototype> + extends CommonDataObjectCodecPrototype { private final @NonNull ImmutableSet childArgs; - @SuppressWarnings("unchecked") - AugmentationCodecPrototype(final @NonNull Class cls, final AugmentRuntimeType type, + AugmentationCodecPrototype(final @NonNull Class cls, final AugmentRuntimeType type, final CodecContextFactory factory, final ImmutableSet childArgs) { - super(new NodeStep<>((Class) cls), type, factory); + super(new NodeStep<>(cls), type, factory); this.childArgs = requireNonNull(childArgs); } diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java index 6ab6c0157b..91fe183ec4 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java @@ -134,7 +134,7 @@ public abstract sealed class DataObjectCodecContext>(); - final var augClassToProto = new HashMap, AugmentationCodecPrototype>(); + final var augClassToProto = new HashMap, AugmentationCodecPrototype>(); for (var augment : possibleAugmentations) { final var augProto = loadAugmentPrototype(augment); if (augProto != null) { @@ -187,13 +187,13 @@ public abstract sealed class DataObjectCodecContext, AugmentationCodecPrototype>) MISMATCHED_AUGMENTED.getAcquire(this); + final var local = (ImmutableMap, AugmentationCodecPrototype>) MISMATCHED_AUGMENTED.getAcquire(this); final var mismatched = local.get(childClass); return mismatched != null ? mismatched : loadMismatchedAugmentation(local, childClass); } - private @Nullable AugmentationCodecPrototype loadMismatchedAugmentation( - final ImmutableMap, AugmentationCodecPrototype> oldMismatched, + private @Nullable AugmentationCodecPrototype loadMismatchedAugmentation( + final ImmutableMap, AugmentationCodecPrototype> oldMismatched, final @NonNull Class childClass) { @SuppressWarnings("rawtypes") final Class augTarget = findAugmentationTarget((Class) childClass); @@ -211,9 +211,9 @@ public abstract sealed class DataObjectCodecContext, AugmentationCodecPrototype> oldMismatched, - final @NonNull Class childClass, final @NonNull AugmentationCodecPrototype prototype) { + private @NonNull AugmentationCodecPrototype cacheMismatched( + final @NonNull ImmutableMap, AugmentationCodecPrototype> oldMismatched, + final @NonNull Class childClass, final @NonNull AugmentationCodecPrototype prototype) { var expected = oldMismatched; while (true) { final var newMismatched = @@ -222,7 +222,7 @@ public abstract sealed class DataObjectCodecContext, AugmentationCodecPrototype>) + final var witness = (ImmutableMap, AugmentationCodecPrototype>) MISMATCHED_AUGMENTED.compareAndExchangeRelease(this, expected, newMismatched); if (witness == expected) { LOG.trace("Cached mismatched augmentation {} -> {} in {}", childClass, prototype, this); @@ -250,7 +250,7 @@ public abstract sealed class DataObjectCodecContext loadAugmentPrototype(final AugmentRuntimeType augment) { // FIXME: in face of deviations this code should be looking at declared view, i.e. all possibilities at augment // declaration site final var childPaths = augment.statement() @@ -271,7 +271,7 @@ public abstract sealed class DataObjectCodecContext(augClass, augment, factory, childPaths); } @Override -- 2.36.6