Add BindingTypes.augmentation() 75/86475/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Dec 2019 10:23:33 +0000 (11:23 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Dec 2019 10:23:33 +0000 (11:23 +0100)
This migrates Types.augmentationTypeFor() into BindingTypes, so we
have proper separation.

Change-Id: I6ff923be4b598714761ed60ca6a36037295b9ac5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/BindingTypes.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/Types.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/BindingTypesTest.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/TypesTest.java

index 1b51e8b05fbd0a10cd20919b8184d549f7290e03..9d6e85387740b393d87189f8cf7aec0c72803004 100644 (file)
@@ -26,6 +26,7 @@ import static org.opendaylight.mdsal.binding.model.util.BindingTypes.RPC_OUTPUT;
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.RPC_SERVICE;
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.action;
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.augmentable;
+import static org.opendaylight.mdsal.binding.model.util.BindingTypes.augmentation;
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.childOf;
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.choiceIn;
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifiable;
@@ -37,7 +38,6 @@ import static org.opendaylight.mdsal.binding.model.util.BindingTypes.opaqueObjec
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.rpcResult;
 import static org.opendaylight.mdsal.binding.model.util.Types.BOOLEAN;
 import static org.opendaylight.mdsal.binding.model.util.Types.STRING;
-import static org.opendaylight.mdsal.binding.model.util.Types.augmentationTypeFor;
 import static org.opendaylight.mdsal.binding.model.util.Types.classType;
 import static org.opendaylight.mdsal.binding.model.util.Types.listTypeFor;
 import static org.opendaylight.mdsal.binding.model.util.Types.listenableFutureTypeFor;
@@ -981,7 +981,7 @@ abstract class AbstractTypeGenerator {
         augTypeBuilder.addImplementsType(DATA_OBJECT);
         defaultImplementedInterace(augTypeBuilder);
 
-        augTypeBuilder.addImplementsType(augmentationTypeFor(targetTypeRef));
+        augTypeBuilder.addImplementsType(augmentation(targetTypeRef));
         annotateDeprecatedIfNecessary(augSchema, augTypeBuilder);
         addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
 
index 250ca03e228b87583f2d9ed0dc7ae13bf07537d0..a61359edf630185b58e95f5789f1f90646377d57 100644 (file)
@@ -148,6 +148,17 @@ public final class BindingTypes {
         return parameterizedTypeFor(AUGMENTABLE, type);
     }
 
+    /**
+     * Specialize {@link Augmentation} for a particular type.
+     *
+     * @param type Type for which to specialize
+     * @return A parameterized type corresponding to {@code Augmentation<Type>}
+     * @throws NullPointerException if {@code type} is null
+     */
+    public static @NonNull ParameterizedType augmentation(final Type type) {
+        return parameterizedTypeFor(AUGMENTATION, type);
+    }
+
     /**
      * Specialize {@link ChildOf} for a particular type.
      *
index 99137a927204290eb05c72a028100da4a0892792..eefeaa26b035b2fa9456d68c0ab7ee7168db7924 100644 (file)
@@ -34,7 +34,6 @@ import org.opendaylight.mdsal.binding.model.api.Restrictions;
 import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.mdsal.binding.model.api.WildcardType;
 import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
@@ -64,8 +63,6 @@ public final class Types {
     private static final @NonNull ConcreteType SERIALIZABLE = typeForClass(Serializable.class);
     private static final @NonNull ConcreteType SET_TYPE = typeForClass(Set.class);
 
-    private static final @NonNull ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
-
     /**
      * It is not desirable to create instance of this class.
      */
@@ -260,12 +257,14 @@ public final class Types {
      * is <code>valueType</code>.
      *
      * @param valueType JAVA <code>Type</code> with actual parameter
-     * @return <code>ParametrizedType</code> reprezentation of raw type
+     * @return <code>ParametrizedType</code> representation of raw type
      *         <code>Augmentation</code> with actual parameter
      *         <code>valueType</code>
+     * @deprecated Use {@link BindingTypes#augmentation(Type)} instead.
      */
+    @Deprecated(forRemoval = true)
     public static @NonNull ParameterizedType augmentationTypeFor(final Type valueType) {
-        return parameterizedTypeFor(AUGMENTATION, valueType);
+        return BindingTypes.augmentation(valueType);
     }
 
     public static @Nullable String getOuterClassName(final Type valueType) {
index 79876b771b15ff4fddd0ee9c00311a8991809791..f271337f9f897e485c1c37a0059a6a15ff1ce2dd 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.opendaylight.mdsal.binding.model.util.Types.typeForClass;
 
 import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
 import org.opendaylight.yangtools.yang.binding.Augmentable;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
@@ -54,11 +55,23 @@ public class BindingTypesTest {
 
     @Test
     public void testAugmentable() {
-        assertNotNull(BindingTypes.augmentable(Types.objectType()));
+        ParameterizedType augmentableType = BindingTypes.augmentable(Types.objectType());
+        assertEquals("Augmentable", augmentableType.getName());
     }
 
     @Test
     public void testChildOf() {
         assertNotNull(BindingTypes.childOf(Types.objectType()));
     }
+
+    @Test(expected = NullPointerException.class)
+    public void testAugmentationNull() {
+        BindingTypes.augmentation(null);
+    }
+
+    @Test
+    public void testAugmentation() {
+        ParameterizedType augmentationType = BindingTypes.augmentation(Types.objectType());
+        assertEquals("Augmentation", augmentationType.getName());
+    }
 }
\ No newline at end of file
index e9546eca58d1d118366e5fe2f3c4a98daca8da27..0ff2d4077aed5ca8d10c2643ea26d62de7ce43f6 100644 (file)
@@ -72,22 +72,26 @@ public class TypesTest {
         assertEquals("WildcardTypeTest", wildcardType.getName());
     }
 
+    @Deprecated
     @Test(expected = NullPointerException.class)
     public void testAugmentableTypeForNull() {
         Types.augmentableTypeFor(null);
     }
 
+    @Deprecated
     @Test(expected = NullPointerException.class)
     public void augmentationTypeForNull() {
         Types.augmentationTypeFor(null);
     }
 
+    @Deprecated
     @Test
     public void testAugmentableTypeFor() {
         ParameterizedType augmentableType = Types.augmentableTypeFor(Types.objectType());
         assertEquals("Augmentable", augmentableType.getName());
     }
 
+    @Deprecated
     @Test
     public void augmentationTypeFor() {
         ParameterizedType augmentationType = Types.augmentationTypeFor(Types.objectType());