Hide parameterized Types constants 14/73414/7
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 25 Jun 2018 16:24:32 +0000 (18:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jun 2018 13:18:54 +0000 (15:18 +0200)
These constants should be accessed via their specializing static
factory methods. Hide them and fix the single offending caller.

Change-Id: Ia0b63a4154b5e1dc86e73645b7935cb34d9c78cc
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/Types.java
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend

index 07b5f9ac2855f89b0d46a9e7fd7b3f9db67f7755..bb7a38d81c47932cb6d4dc9b204b30c86d7c814a 100644 (file)
@@ -28,7 +28,7 @@ import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifiabl
 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifier;
 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.FUTURE;
+import static org.opendaylight.mdsal.binding.model.util.Types.listenableFutureTypeFor;
 import static org.opendaylight.mdsal.binding.model.util.Types.typeForClass;
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findNodeInSchemaContext;
@@ -434,7 +434,7 @@ abstract class AbstractTypeGenerator {
                 addComment(method, rpc);
                 method.addParameter(
                     createRpcContainer(context, rpcName, rpc, verifyNotNull(rpc.getInput())), "input");
-                method.setReturnType(Types.parameterizedTypeFor(FUTURE,
+                method.setReturnType(listenableFutureTypeFor(
                     rpcResult(createRpcContainer(context, rpcName, rpc, verifyNotNull(rpc.getOutput())))));
             }
         }
index 03db4603a7403a7cfcae90523e4c42dcf997104c..226b3295a959254d2f53c9323f7ba749f27f3696 100644 (file)
@@ -50,21 +50,21 @@ public final class Types {
     private static final LoadingCache<Class<?>, ConcreteType> TYPE_CACHE =
             CacheBuilder.newBuilder().weakKeys().build(TYPE_LOADER);
 
-    public static final Type SET_TYPE = typeForClass(Set.class);
-    public static final Type LIST_TYPE = typeForClass(List.class);
-    public static final Type MAP_TYPE = typeForClass(Map.class);
 
     public static final ConcreteType BOOLEAN = typeForClass(Boolean.class);
-    public static final ConcreteType FUTURE = typeForClass(ListenableFuture.class);
     public static final ConcreteType STRING = typeForClass(String.class);
     public static final ConcreteType VOID = typeForClass(Void.class);
     public static final ConcreteType BYTE_ARRAY = typeForClass(byte[].class);
     public static final ConcreteType CHAR_ARRAY = typeForClass(char[].class);
 
     private static final ConcreteType CLASS = typeForClass(Class.class);
+    private static final ConcreteType LIST_TYPE = typeForClass(List.class);
+    private static final ConcreteType LISTENABLE_FUTURE = typeForClass(ListenableFuture.class);
+    private static final ConcreteType MAP_TYPE = typeForClass(Map.class);
     private static final ConcreteType OBJECT = typeForClass(Object.class);
     private static final ConcreteType PRIMITIVE_VOID = typeForClass(void.class);
     private static final ConcreteType SERIALIZABLE = typeForClass(Serializable.class);
+    private static final ConcreteType SET_TYPE = typeForClass(Set.class);
 
     /**
      * It is not desirable to create instance of this class
@@ -181,6 +181,22 @@ public final class Types {
         return parameterizedTypeFor(LIST_TYPE, valueType);
     }
 
+    public static boolean isListType(final Type type) {
+        return type instanceof ParameterizedType && LIST_TYPE.equals(((ParameterizedType) type).getRawType());
+    }
+
+    /**
+     * Returns an instance of {@link ParameterizedType} describing the typed
+     * {@link ListenableFuture}&lt;V&gt; with concrete type of value.
+     *
+     * @param valueType
+     *            Value Type
+     * @return Description of type instance of ListenableFuture
+     */
+    public static ParameterizedType listenableFutureTypeFor(final Type valueType) {
+        return parameterizedTypeFor(LISTENABLE_FUTURE, valueType);
+    }
+
     /**
      * Creates instance of type
      * {@link org.opendaylight.mdsal.binding.model.api.ParameterizedType
index 110765c8f2ea65f9773d9c8b98da2e30d6a2f31c..ca6f3e7c560731184dad4a9d8c319b42d47fe96d 100644 (file)
@@ -528,8 +528,7 @@ class BuilderTemplate extends BaseTemplate {
             }
         «ENDIF»
         «FOR property : properties»
-            «IF property.returnType instanceof ParameterizedType
-                    && (property.returnType as ParameterizedType).rawType.equals(Types.LIST_TYPE)»
+            «IF property.returnType instanceof ParameterizedType && Types.isListType(property.returnType)»
                 «generateListSetter(property, getActualType(property.returnType as ParameterizedType))»
             «ELSE»
                 «generateSetter(property, property.returnType)»