Eliminate AugmentationHolder
[mdsal.git] / binding / mdsal-binding-test-utils / src / main / java / org / opendaylight / mdsal / binding / testutils / XtendYangBeanGenerator.java
index 6e87c5ab1527902188ec9fa7c17534a7232778e1..c9bd05972be27b4a6b3003594e0da50a7ddae031 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.testutils;
 
 import ch.vorburger.xtendbeans.XtendBeanGenerator;
 import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.collect.Iterables;
 import java.util.Comparator;
 import java.util.Optional;
@@ -38,8 +39,6 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 // package-local: no need to expose this, consider it an implementation detail; public API is the AssertDataObjects
 class XtendYangBeanGenerator extends XtendBeanGenerator {
 
-    private final AugmentableExtension augmentableExtension = new AugmentableExtension();
-
     @Override
     public String getExpression(final Object bean) {
         final String beanText = super.getExpression(bean);
@@ -85,10 +84,9 @@ class XtendYangBeanGenerator extends XtendBeanGenerator {
         return Iterables.filter(properties, property -> !property.getName().equals("key"));
     }
 
-    private Optional<ClassToInstanceMap<Augmentation<?>>> getAugmentations(final Object bean) {
+    private static Optional<ClassToInstanceMap<Augmentation<?>>> getAugmentations(final Object bean) {
         if (bean instanceof Augmentable<?>) {
-            Augmentable<?> augmentable = (Augmentable<?>) bean;
-            ClassToInstanceMap<Augmentation<?>> augmentables = augmentableExtension.getAugmentations(augmentable);
+            ClassToInstanceMap<Augmentation<?>> augmentables = augmentations((Augmentable<?>) bean);
             if (!augmentables.isEmpty()) {
                 return Optional.of(augmentables);
             }
@@ -96,6 +94,10 @@ class XtendYangBeanGenerator extends XtendBeanGenerator {
         return Optional.empty();
     }
 
+    private static ClassToInstanceMap<Augmentation<?>> augmentations(final Augmentable<?> augmentable) {
+        return ImmutableClassToInstanceMap.copyOf(augmentable.augmentations());
+    }
+
     @Override
     protected CharSequence getAdditionalInitializationExpression(final Object bean, final Class<?> builderClass) {
         Optional<ClassToInstanceMap<Augmentation<?>>> optional = getAugmentations(bean);