< prev index next >

test/lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java

Print this page

        

@@ -313,6 +313,35 @@
         if (dst == boolean.class || dst == Boolean.class) {
             return ((value % 29) & 1) == 0;
         }
         return null;
     }
+    
+    /**
+     * Routine used to obtain a randomly generated method type.
+     *
+     * @param arity Arity of returned method type.
+     * @return MethodType generated randomly.
+     */
+    public static MethodType randomMethodTypeGenerator(int arity) {
+        final Class<?>[] CLASSES = {
+            Object.class,
+            int.class,
+            boolean.class,
+            byte.class,
+            short.class,
+            char.class,
+            long.class,
+            float.class,
+            double.class
+        };
+        if (arity > MAX_ARITY) {
+            throw new IllegalArgumentException(
+                    String.format("Arity should not exceed %d!", MAX_ARITY));
+        }
+        List<Class<?>> list = randomClasses(CLASSES, arity);
+        list = getParams(list, false, arity);
+        int i = RNG.nextInt(CLASSES.length + 1);
+        Class<?> rtype = i == CLASSES.length ? void.class : CLASSES[i];
+        return MethodType.methodType(rtype, list);
+    }
 }
< prev index next >