Extend AugmentableExtension to handle AugmentationHolder 00/81700/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 17 Apr 2019 14:04:28 +0000 (16:04 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 18 Apr 2019 13:03:53 +0000 (13:03 +0000)
This class seems to be a duplicate of BindingReflections'
functionality, completely missing out on AugmentationHolder, which
can be used as an alternative to expose augmentations.

Change-Id: Iadcc4e2f4587ceeb27d6a47c42b0319705fc1e58
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-test-utils/src/main/java/org/opendaylight/mdsal/binding/testutils/AugmentableExtension.java

index 205ef8623e6bbdfd8aa1b2e11f187ea63e9cfc50..ac46b832079895632dd0b3a7494c9c75c278dbd1 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.xtext.xbase.lib.util.ReflectExtensions;
 import org.opendaylight.mdsal.binding.dom.codec.util.AugmentationReader;
 import org.opendaylight.yangtools.yang.binding.Augmentable;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.AugmentationHolder;
 
 /**
  * Adds an {@link #getAugmentations(Augmentable)} method to {@link Augmentable}.
@@ -28,14 +29,18 @@ import org.opendaylight.yangtools.yang.binding.Augmentation;
  * @author Michael Vorburger
  */
 // package-local: no need to expose this, consider it an implementation detail; public API is the AssertDataObjects
+// FIXME: 5.0.0: this is a duplication of BindingReflections.getAugmentations() ... but why?
 class AugmentableExtension {
 
     private static final ReflectExtensions REFLECT_EXTENSIONS = new ReflectExtensions();
 
-    public ClassToInstanceMap<Augmentation<?>> getAugmentations(Augmentable<?> augmentable) {
+    public ClassToInstanceMap<Augmentation<?>> getAugmentations(final Augmentable<?> augmentable) {
         if (augmentable instanceof AugmentationReader) {
             AugmentationReader augmentationReader = (AugmentationReader) augmentable;
             return ImmutableClassToInstanceMap.copyOf(augmentationReader.getAugmentations(augmentable));
+        } else if (augmentable instanceof AugmentationHolder) {
+            AugmentationHolder<?> augmentationHolder = (AugmentationHolder<?>) augmentable;
+            return ImmutableClassToInstanceMap.copyOf(augmentationHolder.augmentations());
         } else if (Proxy.isProxyClass(augmentable.getClass())) {
             InvocationHandler invocationHandler = Proxy.getInvocationHandler(augmentable);
             // class LazyDataObject implements InvocationHandler, AugmentationReader