Remove deprecated uint migration elements, take 2 48/95048/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 5 Feb 2021 16:31:21 +0000 (17:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 6 Feb 2021 14:07:34 +0000 (15:07 +0100)
It's been 18 months since we introduced this particular change in
mapping, giving ample time for users to migrate.

Remove code generated to support uint8/16/32/64 mapping transition,
so that users are forced to interface with proper types.

JIRA: MDSAL-490
Change-Id: I03c80a92dbb6bb429b5bd939cb2068a0289defc5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BaseTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/CodeHelpers.java

index 7a1d55a252abf18d45de684fb8f7c44a86a97bb0..c15e683e39ad77105d63fa0d31fac70cf40321b9 100644 (file)
@@ -12,9 +12,7 @@ import static extension org.opendaylight.mdsal.binding.model.util.BindingGenerat
 
 import com.google.common.base.CharMatcher
 import com.google.common.base.Splitter
-import com.google.common.collect.ImmutableMap
 import com.google.common.collect.Iterables
-import java.math.BigInteger
 import java.util.Collection
 import java.util.List
 import java.util.Locale
@@ -39,10 +37,6 @@ import org.opendaylight.mdsal.binding.model.util.TypeConstants
 import org.opendaylight.mdsal.binding.model.util.Types
 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
 import org.opendaylight.yangtools.yang.common.QName
-import org.opendaylight.yangtools.yang.common.Uint8
-import org.opendaylight.yangtools.yang.common.Uint16
-import org.opendaylight.yangtools.yang.common.Uint32
-import org.opendaylight.yangtools.yang.common.Uint64
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
@@ -70,13 +64,6 @@ abstract class BaseTemplate extends JavaFileTemplate {
         .addIgnoredStatement(YangStmtMapping.ORGANIZATION)
         .build();
 
-    protected static val UINT_TYPES = ImmutableMap.of(
-        Types.typeForClass(Uint8), Types.typeForClass(Short),
-        Types.typeForClass(Uint16), Types.typeForClass(Integer),
-        Types.typeForClass(Uint32), Types.typeForClass(Long),
-        Types.typeForClass(Uint64), Types.typeForClass(BigInteger)
-    );
-
     new(GeneratedType type) {
         super(type)
     }
index 0b361e000a6f09c82ec80bca8b5d631b7be94ef6..90fb8f6b3107c1693fdf18eebc56308c75092eca 100644 (file)
@@ -388,21 +388,6 @@ class BuilderTemplate extends AbstractBuilderTemplate {
             this.«field.fieldName» = value;
             return this;
         }
-        «val uintType = UINT_TYPES.get(field.returnType)»
-        «IF uintType !== null»
-
-            /**
-             * Utility migration setter.
-             *
-             * @param value field value in legacy type
-             * @return this builder
-             * @deprecated Use {@link #«setterName»(«field.returnType.importedJavadocName»)} instead.
-             */
-            @Deprecated(forRemoval = true)
-            public «type.getName» «setterName»(final «uintType.importedName» value) {
-                return «setterName»(«CODEHELPERS.importedName».compatUint(value));
-            }
-        «ENDIF»
     '''
 
     /**
index faadb1aefe04a1be1f6b65a69b8cdad6ad0575a9..a5e0b94019cd0bb120f06447f2c8cd882a7115b7 100644 (file)
@@ -256,10 +256,8 @@ class ClassTemplate extends BaseTemplate {
             «genUnionConstructor»
         «ELSEIF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name.equals(TypeConstants.VALUE_PROP)»
             «typedefConstructor»
-            «legacyConstructor»
         «ELSE»
             «allValuesConstructor»
-            «legacyConstructor»
         «ENDIF»
 
         «IF !allProperties.empty»
@@ -314,29 +312,6 @@ class ClassTemplate extends BaseTemplate {
     }
     '''
 
-    def private legacyConstructor() {
-        if (!hasUintProperties) {
-            return ""
-        }
-
-        val compatUint = CODEHELPERS.importedName + ".compatUint("
-        return '''
-
-            /**
-             * Utility migration constructor.
-             *
-             «FOR prop : allProperties»
-             * @param «prop.fieldName» «prop.name»«IF prop.isUintType» in legacy Java type«ENDIF»
-             «ENDFOR»
-             * @deprecated Use {@link #«type.name»(«FOR prop : allProperties SEPARATOR ", "»«prop.returnType.importedJavadocName»«ENDFOR»)} instead.
-             */
-            @Deprecated(forRemoval = true)
-            public «type.getName»(«FOR prop : allProperties SEPARATOR ", "»«prop.legacyType.importedName» «prop.fieldName»«ENDFOR») {
-                this(«FOR prop : allProperties SEPARATOR ", "»«IF prop.isUintType»«compatUint»«prop.fieldName»)«ELSE»«prop.fieldName»«ENDIF»«ENDFOR»);
-            }
-        '''
-    }
-
     def protected genUnionConstructor() '''
     «FOR p : allProperties»
         «val List<GeneratedProperty> other = new ArrayList(properties)»
@@ -641,26 +616,4 @@ class ClassTemplate extends BaseTemplate {
         }
         return null
     }
-
-    def private hasUintProperties() {
-        for (GeneratedProperty prop : allProperties) {
-            if (prop.isUintType) {
-                return true
-            }
-        }
-        return false
-    }
-
-    def private static isUintType(GeneratedProperty prop) {
-        UINT_TYPES.containsKey(prop.returnType)
-    }
-
-    def private static legacyType(GeneratedProperty prop) {
-        val type = prop.returnType
-        val uint = UINT_TYPES.get(type)
-        if (uint !== null) {
-            return uint
-        }
-        return type
-    }
 }
index 55334e12be68965dce78dc0edbc7a0acc0586301..bf3afc2945fa9f34743bbdc24d98801ecc51ca45 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.VerifyException;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -23,10 +22,6 @@ import java.util.Objects;
 import java.util.regex.Pattern;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.Uint16;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Helper methods for generated binding code. This class concentrates useful primitives generated code may call
@@ -316,66 +311,6 @@ public final class CodeHelpers {
         return wrapHashCode(Arrays.hashCode(obj));
     }
 
-    /**
-     * Compatibility utility for converting a legacy {@link Short} {@code uint8} value to its {@link Uint8}
-     * counterpart.
-     *
-     * @param value Legacy value
-     * @return Converted value
-     * @throws IllegalArgumentException if the value does not fit an Uint8
-     * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
-     *             compatibility methods.
-     */
-    @Deprecated
-    public static @Nullable Uint8 compatUint(final @Nullable Short value) {
-        return value == null ? null : Uint8.valueOf(value.shortValue());
-    }
-
-    /**
-     * Compatibility utility for converting a legacy {@link Integer} {@code uint16} value to its {@link Uint16}
-     * counterpart.
-     *
-     * @param value Legacy value
-     * @return Converted value
-     * @throws IllegalArgumentException if the value does not fit an Uint16
-     * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
-     *             compatibility methods.
-     */
-    @Deprecated
-    public static @Nullable Uint16 compatUint(final @Nullable Integer value) {
-        return value == null ? null : Uint16.valueOf(value.intValue());
-    }
-
-    /**
-     * Compatibility utility for converting a legacy {@link Long} {@code uint32} value to its {@link Uint32}
-     * counterpart.
-     *
-     * @param value Legacy value
-     * @return Converted value
-     * @throws IllegalArgumentException if the value does not fit an Uint32
-     * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
-     *             compatibility methods.
-     */
-    @Deprecated
-    public static @Nullable Uint32 compatUint(final @Nullable Long value) {
-        return value == null ? null : Uint32.valueOf(value.longValue());
-    }
-
-    /**
-     * Compatibility utility for converting a legacy {@link BigInteger} {@code uint64} value to its {@link Uint64}
-     * counterpart.
-     *
-     * @param value Legacy value
-     * @return Converted value
-     * @throws IllegalArgumentException if the value does not fit an Uint64
-     * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
-     *             compatibility methods.
-     */
-    @Deprecated
-    public static @Nullable Uint64 compatUint(final @Nullable BigInteger value) {
-        return value == null ? null : Uint64.valueOf(value);
-    }
-
     /**
      * Utility method for checking whether a target object is a compatible DataObject.
      *
@@ -435,10 +370,12 @@ public final class CodeHelpers {
     /**
      * The constant '31' is the result of folding this code:
      * <pre>
+     *   <code>
      *     final int prime = 31;
      *     int result = 1;
      *     result = result * prime + Objects.hashCode(obj);
      *     return result;
+     *   </code>
      * </pre>
      * when hashCode is returned as 0, such as due to obj being null or its hashCode being 0.
      *