Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 898   Methods: 78
NCLOC: 437   Classes: 17
 
 Source file Conditionals Statements Methods TOTAL
ReflectUtil.java 90.4% 79.5% 82.1% 81.7%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK*
 2   
 3    PLT Utilities BSD License
 4   
 5    Copyright (c) 2007-2010 JavaPLT group at Rice University
 6    All rights reserved.
 7   
 8    Developed by: Java Programming Languages Team
 9    Rice University
 10    http://www.cs.rice.edu/~javaplt/
 11   
 12    Redistribution and use in source and binary forms, with or without modification, are permitted
 13    provided that the following conditions are met:
 14   
 15    - Redistributions of source code must retain the above copyright notice, this list of conditions
 16    and the following disclaimer.
 17    - Redistributions in binary form must reproduce the above copyright notice, this list of
 18    conditions and the following disclaimer in the documentation and/or other materials provided
 19    with the distribution.
 20    - Neither the name of the JavaPLT group, Rice University, nor the names of the library's
 21    contributors may be used to endorse or promote products derived from this software without
 22    specific prior written permission.
 23   
 24    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 25    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 26    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND
 27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 29    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 30    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 31    OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32   
 33    *END_COPYRIGHT_BLOCK*/
 34   
 35    package edu.rice.cs.plt.reflect;
 36   
 37    import java.lang.reflect.Field;
 38    import java.lang.reflect.Method;
 39    import java.lang.reflect.Constructor;
 40    import java.lang.reflect.InvocationTargetException;
 41    import java.io.File;
 42    import java.io.Serializable;
 43    import edu.rice.cs.plt.lambda.*;
 44    import edu.rice.cs.plt.iter.IterUtil;
 45    import edu.rice.cs.plt.io.IOUtil;
 46   
 47    import static edu.rice.cs.plt.reflect.ReflectException.*;
 48    import static edu.rice.cs.plt.debug.DebugUtil.debug;
 49   
 50    public final class ReflectUtil {
 51   
 52    /** Prevents instance creation */
 53  0 private ReflectUtil() {}
 54   
 55    /**
 56    * A ClassLoader for the bootstrap classes -- those provided by the bootstrap class path in Sun
 57    * JVMs. Note that this is not the actual loader used for bootstrap classes, but rather an immediate
 58    * child; for any available class {@code c} ({@code "java.lang.Number"} or {@code "javax.swing.JFrame"},
 59    * for example), {@code BOOT_CLASS_LOADER.loadClass(c).getClassLoader()} has value
 60    * {@code null}. When constructing a class loader, there is no need to use this object as a parent --
 61    * simply use {@code null} as the parent parameter.
 62    */
 63    public static final ClassLoader BOOT_CLASS_LOADER = new ClassLoader(null) {};
 64   
 65    /**
 66    * The value of system property "java.class.path", parsed as a list of files. Consistent with most
 67    * other uses of JVM properties in Java libraries, does not reflect subsequent changes to the property.
 68    */
 69    public static final Iterable<File> SYSTEM_CLASS_PATH = IOUtil.parsePath(System.getProperty("java.class.path", ""));
 70   
 71    /**
 72    * Produce the simple name of the given class, as specified by {@link Class#getSimpleName},
 73    * with an improved scheme for anonymous classes. The simple name of a class is generally
 74    * the unqualified name used to declare it. Arrays evaluate to the simple name of their
 75    * element type, followed by a pair of brackets. Anonymous classes, rather than evaluating to an
 76    * empty string, produce something like "anonymous Foo" (where Foo is the supertype). Assumes
 77    * non-anonymous classes follow a naming convention in which the simple name is the suffix
 78    * of the full class name following all '.' and '$' characters, and immediately following a
 79    * (possibly empty) sequence of digits.
 80    */
 81  55 public static String simpleName(Class<?> c) {
 82  7 if (c.isArray()) { return simpleName(c.getComponentType()) + "[]"; }
 83  48 else if (isAnonymousClass(c)) {
 84  1 if (c.getInterfaces().length > 0) { return "anonymous " + simpleName(c.getInterfaces()[0]); }
 85  1 else { return "anonymous " + simpleName(c.getSuperclass()); }
 86    }
 87    else {
 88  46 String fullName = c.getName();
 89  46 int dot = fullName.lastIndexOf('.');
 90  46 int dollar = fullName.lastIndexOf('$');
 91  46 int nameStart = (dot > dollar) ? dot+1 : dollar+1;
 92  46 int length = fullName.length();
 93  1 while (nameStart < length && Character.isDigit(fullName.charAt(nameStart))) { nameStart++; }
 94  46 return fullName.substring(nameStart);
 95    }
 96    }
 97   
 98    /** An implementation of {@link Class#isAnonymousClass}, which is unavailable prior to Java 5.0 */
 99  54 public static boolean isAnonymousClass(Class<?> c) {
 100  54 String name = c.getName();
 101  54 String nameEnd = name.substring(name.lastIndexOf('$') + 1); // index is -1 if there is none
 102  54 for (int i = 0; i < nameEnd.length(); i++) {
 103  50 if (Character.isJavaIdentifierStart(nameEnd.charAt(i))) { return false; }
 104    }
 105  4 return true;
 106    }
 107   
 108    /**
 109    * Gets the base component type of an array of arbitrary dimensions. For example, for each of {@code String},
 110    * {@code String[]}, and {@code String[][]}, this is {@code String}.
 111    */
 112  0 public static Class<?> arrayBaseClass(Class<?> c) {
 113  0 Class<?> result = c;
 114  0 while (result.isArray()) { result = result.getComponentType(); }
 115  0 return result;
 116    }
 117   
 118    /**
 119    * Return the number of array dimensions represented by the given class. For {@code String[][]}, this is 2.
 120    * For {@code String}, this is 0.
 121    */
 122  0 public static int arrayDimensions(Class<?> c) {
 123  0 Class<?> rest = c;
 124  0 int result = 0;
 125  0 while (rest.isArray()) { rest = rest.getComponentType(); result++; }
 126  0 return result;
 127    }
 128   
 129    /**
 130    * <p>An implementation of {@link Class#cast}, which is unavailable prior to Java 5.0. Unlike the
 131    * Java API method, this version allows a boxed value to be cast to its unboxed equivalent &mdash; for
 132    * example, {@code ReflectUtil.cast(int.class, 23)} will succeed (see SDN bug 6456930).</p>
 133    *
 134    * <p>The method is only capable of checking that {@code o} is an instance of the class {@code c} &mdash; not
 135    * that {@code o} is an instance of type {@code T} (for example, casting with a {@code Class<List<Integer>>} would
 136    * only check that {@code o} is a {@code List<?>}, but the return type would by {@code List<Integer>}).
 137    * Such discrepancies are rare in practice, because class literals ({@code Foo.class}) will only produce classes
 138    * for which {@code T} is unparameterized or raw.</p>
 139    *
 140    * <p>Following {@code Class.cast()}, a boxed type cannot be cast to its unboxed equivalent, despite the fact
 141    * that such a cast would be safe. (From a practical point of view, we would prefer to avoid incurring the
 142    * overhead of {@link #box} on every cast.)</li>
 143    * </ul>
 144    * @throws ClassCastException If the object cannot be cast to the given type.
 145    */
 146  43 public static <T> T cast(Class<? extends T> c, Object o) throws ClassCastException {
 147  43 if (box(c).isInstance(o)) {
 148  36 @SuppressWarnings("unchecked") T result = (T) o;
 149  36 return result;
 150    }
 151  7 else { throw new ClassCastException("Casting to " + c.getName() + " from " + o.getClass().getName()); }
 152    }
 153   
 154    /**
 155    * Produce a correctly-typed class corresponding to {@code obj}. {@code obj.getClass()}, in contrast,
 156    * returns a {@code Class<?>}.
 157    */
 158  4 @SuppressWarnings("unchecked") public static <T> Class<? extends T> getClass(T obj) {
 159  4 return (Class<? extends T>) obj.getClass();
 160    }
 161   
 162    /** If {@code c} is a primitive type, return its boxed counterpart; otherwise, return {@code c}. */
 163  54 @SuppressWarnings("unchecked") public static <T> Class<T> box(Class<T> c) {
 164  54 if (c.isPrimitive()) {
 165  1 if (c == Boolean.TYPE) { return (Class<T>) Boolean.class; }
 166  1 if (c == Character.TYPE) { return (Class<T>) Character.class; }
 167  1 if (c == Byte.TYPE) { return (Class<T>) Byte.class; }
 168  1 if (c == Short.TYPE) { return (Class<T>) Short.class; }
 169  4 if (c == Integer.TYPE) { return (Class<T>) Integer.class; }
 170  1 if (c == Long.TYPE) { return (Class<T>) Long.class; }
 171  1 if (c == Float.TYPE) { return (Class<T>) Float.class; }
 172  1 if (c == Double.TYPE) { return (Class<T>) Double.class; }
 173  1 if (c == Void.TYPE) { return (Class<T>) Void.class; }
 174    }
 175  42 return c;
 176    }
 177   
 178   
 179    private static final ClassLoader CURRENT_LOADER = ReflectUtil.class.getClassLoader();
 180   
 181    /** Apply getClass() to an array of objects */
 182  21 private static Class<?>[] getClasses(Object[] args) {
 183  21 if (args.length > 0) {
 184  6 Class<?>[] sig = new Class<?>[args.length];
 185  8 for (int i = 0; i < args.length; i++) { sig[i] = args[i].getClass(); }
 186  6 return sig;
 187    }
 188  15 else { return null; }
 189    }
 190   
 191    /**
 192    * <p>Create an instance of the given class. This is a convenience method that uses the class loader of
 193    * {@code ReflectUtil} to load {@code className}, and that infers the constructor signature from the
 194    * given arguments.</p>
 195    *
 196    * <p>Note that the inference process for the constructor signature is potentially error-prone, because it
 197    * uses the concrete runtime types of the objects, which may be more specific than what is needed. It is
 198    * impossible, for example, to use this method to invoke a constructor whose parameters include
 199    * interface, abstract class, or primitive types. In such cases,
 200    * {@link #loadObject(String, Class[], Object[])} should be used instead.</p>
 201    *
 202    * <p>A typical use of this method is to instantiate an object that belongs to or directly refers to
 203    * a library that is not guaranteed to be statically available at runtime. Since no direct reference
 204    * can by made to that object's class or any of the library's classes in the main body of code
 205    * (otherwise, a {@link NoClassDefFoundError} may occur), reflection must be used to load
 206    * the object.</p>
 207    *
 208    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 209    *
 210    * @see #loadObject(String, Class[], Object[])
 211    * @see #loadObject(ClassLoader, String, Class[], Object[])
 212    */
 213  7 public static Object loadObject(String className, Object... constructorArgs) throws ReflectException {
 214  7 return loadObject(CURRENT_LOADER, className, getClasses(constructorArgs), constructorArgs);
 215    }
 216   
 217    /**
 218    * <p>Create an instance of the given class. This is a convenience method that uses the class loader of
 219    * {@code ReflectUtil} to load {@code className}.</p>
 220    *
 221    * <p>A typical use of this method is to instantiate an object that belongs to or directly refers to
 222    * a library that is not guaranteed to be statically available at runtime. Since no direct reference
 223    * can by made to that object's class or any of the library's classes in the main body of code
 224    * (otherwise, a {@link NoClassDefFoundError} may occur), reflection must be used to load
 225    * the object.</p>
 226    *
 227    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 228    *
 229    * @see #loadObject(String, Object[])
 230    * @see #loadObject(ClassLoader, String, Class[], Object[])
 231    */
 232  3 public static Object loadObject(String className, Class<?>[] constructorSig, Object... constructorArgs)
 233    throws ReflectException {
 234  3 return loadObject(CURRENT_LOADER, className, constructorSig, constructorArgs);
 235    }
 236   
 237    /**
 238    * <p>Create an instance of the given class. This is a convenience method that infers the constructor
 239    * signature from the given arguments.</p>
 240    *
 241    * <p>Note that the inference process for the constructor signature is potentially error-prone, because it
 242    * uses the concrete runtime types of the objects, which may be more specific than what is needed. It is
 243    * impossible, for example, to use this method to invoke a constructor whose parameters include
 244    * interface, abstract class, or primitive types. In such cases,
 245    * {@link #loadObject(ClassLoader, String, Class[], Object[])} should be used instead.</p>
 246    *
 247    * <p>A typical use of this method is to instantiate an object that belongs to or directly refers to
 248    * a library that is not guaranteed to be statically available at runtime. Since no direct reference
 249    * can by made to that object's class or any of the library's classes in the main body of code
 250    * (otherwise, a {@link NoClassDefFoundError} may occur), reflection must be used to load
 251    * the object.</p>
 252    *
 253    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 254    *
 255    * @see #loadObject(String, Object[])
 256    * @see #loadObject(ClassLoader, String, Class[], Object[])
 257    */
 258  1 public static Object loadObject(ClassLoader loader, String className, Object... constructorArgs)
 259    throws ReflectException {
 260  1 return loadObject(loader, className, getClasses(constructorArgs), constructorArgs);
 261    }
 262   
 263    /**
 264    * <p>Create an instance of the given class. This method invokes
 265    * {@link Class#forName(String, boolean, ClassLoader)} (with {@code initialize} set to {@code true}),
 266    * {@link Class#getConstructor(Class[])}, and {@link Constructor#newInstance}.</p>
 267    *
 268    * <p>A typical use of this method is to instantiate an object that belongs to or directly refers to
 269    * a library that is not guaranteed to be statically available at runtime. Since no direct reference
 270    * can by made to that object's class or any of the library's classes in the main body of code
 271    * (otherwise, a {@link NoClassDefFoundError} may occur), reflection must be used to load
 272    * the object.</p>
 273    *
 274    * @param loader A class loader used to load the specified class
 275    * @param className The name of the class to be instantiated
 276    * @param constructorSig The types of the desired constructor's parameters; these must exactly match the
 277    * the constructor's declared signature (may not be {@code null})
 278    * @param constructorArgs The arguments to pass to the constructor ({@code null} is also acceptable where
 279    * there are no parameters)
 280    *
 281    * @throws ReflectException This operation may trigger any of the following, which is wrapped as a
 282    * {@code ReflectException}:<ul>
 283    * <li>A {@link ClassNotFoundException} if {@code className} cannot be found</li>
 284    * <li>A {@link NoSuchMethodException} if no constructor with the given signature
 285    * exists</li>
 286    * <li>An {@link IllegalArgumentException} if the cardinality and types of
 287    * {@code constructorArgs} are inconsistent with {@code constructorSig}</li>
 288    * <li>An {@link InvocationTargetException} in any throwable is thrown by the
 289    * constructor</li>
 290    * <li>An {@link InstantiationException} if the class is abstract</li>
 291    * <li>An {@link IllegalAccessException} if the constructor is inaccessible</li>
 292    * <li>A {@link SecurityException} if the security manager denies access to the
 293    * constructor</li>
 294    *
 295    * @see #loadObject(String, Object[])
 296    * @see #loadObject(String, Class[], Object[])
 297    */
 298  13 public static Object loadObject(ClassLoader loader, String className, Class<?>[] constructorSig,
 299    Object... constructorArgs) throws ReflectException {
 300  13 try {
 301  13 Class<?> c = Class.forName(className, true, loader);
 302  12 Constructor<?> k = c.getConstructor(constructorSig);
 303  8 return k.newInstance(constructorArgs);
 304    }
 305  1 catch (ClassNotFoundException e) { throw new ClassNotFoundReflectException(e); }
 306  4 catch (NoSuchMethodException e) { throw new NoSuchMethodReflectException(e); }
 307  2 catch (IllegalArgumentException e) { throw new IllegalArgumentReflectException(e); }
 308  1 catch (InvocationTargetException e) { throw new InvocationTargetReflectException(e); }
 309  0 catch (InstantiationException e) { throw new InstantiationReflectException(e); }
 310  0 catch (IllegalAccessException e) { throw new IllegalAccessReflectException(e); }
 311  0 catch (SecurityException e) { throw new SecurityReflectException(e); }
 312    }
 313   
 314  5 public static Object getStaticField(String className, String fieldName) throws ReflectException {
 315  5 return getStaticField(CURRENT_LOADER, className, fieldName);
 316    }
 317   
 318  9 public static Object getStaticField(ClassLoader loader, String className, String fieldName) throws ReflectException {
 319  9 try {
 320  9 Class<?> c = Class.forName(className, true, loader);
 321  7 Field f = c.getField(fieldName);
 322  6 try { return f.get(null); }
 323    // catch null pointer here to prevent silly null pointers (e.g. fieldName is null) from being caught
 324  1 catch (NullPointerException e) { throw new NullPointerReflectException(e); }
 325    }
 326  2 catch (ClassNotFoundException e) { throw new ClassNotFoundReflectException(e); }
 327  1 catch (NoSuchFieldException e) { throw new NoSuchFieldReflectException(e); }
 328  0 catch (IllegalArgumentException e) { throw new IllegalArgumentReflectException(e); }
 329  0 catch (IllegalAccessException e) { throw new IllegalAccessReflectException(e); }
 330  0 catch (SecurityException e) { throw new SecurityReflectException(e); }
 331    }
 332   
 333  8 public static Object invokeStaticMethod(String className, String methodName, Object... args)
 334    throws ReflectException {
 335  8 return invokeStaticMethod(CURRENT_LOADER, className, methodName, getClasses(args), args);
 336    }
 337   
 338  4 public static Object invokeStaticMethod(ClassLoader loader, String className, String methodName, Object... args)
 339    throws ReflectException {
 340  4 return invokeStaticMethod(loader, className, methodName, getClasses(args), args);
 341    }
 342   
 343  3 public static Object invokeStaticMethod(String className, String methodName, Class<?>[] signature, Object... args)
 344    throws ReflectException {
 345  3 return invokeStaticMethod(CURRENT_LOADER, className, methodName, signature, args);
 346    }
 347   
 348  15 public static Object invokeStaticMethod(ClassLoader loader, String className, String methodName, Class<?>[] signature,
 349    Object... args) throws ReflectException {
 350  15 try {
 351  15 Class<?> c = Class.forName(className, true, loader);
 352  13 Method m = c.getMethod(methodName, signature);
 353  10 try { return m.invoke(null, args); }
 354    // catch null pointer here to prevent silly null pointers (e.g. methodName is null) from being caught
 355  1 catch (NullPointerException e) { throw new NullPointerReflectException(e); }
 356    }
 357  2 catch (ClassNotFoundException e) { throw new ClassNotFoundReflectException(e); }
 358  3 catch (NoSuchMethodException e) { throw new NoSuchMethodReflectException(e); }
 359  1 catch (IllegalArgumentException e) { throw new IllegalArgumentReflectException(e); }
 360  0 catch (InvocationTargetException e) { throw new InvocationTargetReflectException(e); }
 361  0 catch (IllegalAccessException e) { throw new IllegalAccessReflectException(e); }
 362  0 catch (SecurityException e) { throw new SecurityReflectException(e); }
 363    }
 364   
 365   
 366    /**
 367    * <p>Create an adapter object which provides an interface to a library that is not available statically on the
 368    * class path (or, more generally, to the {@code baseLoader}). This assumes the relevant code may be organized
 369    * into three groups: the base classes, which are available to the {@code baseLoader} and make
 370    * no direct references to the library or adapter classes; the library classes, which are located in the path
 371    * represented by {@code libraryPath}, and make no direct references to the adapter class; and the adapter
 372    * class (including its inner classes), which is available to the {@code baseLoader}, and which can
 373    * directly refer to both the library and base classes.</p>
 374    *
 375    * <p>This is a convenience method that uses the class loader of {@code ReflectUtil} as {@code baseLoader}, and
 376    * that infers the constructor signature from the given arguments. Note that the inference process for the
 377    * constructor signature is potentially error-prone, because it uses the concrete runtime types of the objects,
 378    * which may be more specific than what is needed. It is impossible, for example, to use this method to invoke a
 379    * constructor whose parameters include interface, abstract class, or primitive types. In such cases,
 380    * {@link #loadLibraryAdapter(Iterable, String, Class[], Object[])} should be used instead.</p>
 381    *
 382    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 383    *
 384    */
 385  0 public static Object loadLibraryAdapter(Iterable<? extends File> libraryPath, String adapterName,
 386    Object... constructorArgs) throws ReflectException {
 387  0 return loadLibraryAdapter(CURRENT_LOADER, libraryPath, adapterName, getClasses(constructorArgs), constructorArgs);
 388    }
 389   
 390    /**
 391    * <p>Create an adapter object which provides an interface to a library that is not available statically on the
 392    * class path (or, more generally, to the {@code baseLoader}). This assumes the relevant code may be organized
 393    * into three groups: the base classes, which are available to the {@code baseLoader} and make
 394    * no direct references to the library or adapter classes; the library classes, which are located in the path
 395    * represented by {@code libraryPath}, and make no direct references to the adapter class; and the adapter
 396    * class (including its inner classes), which is available to the {@code baseLoader}, and which can
 397    * directly refer to both the library and base classes.</p>
 398    *
 399    * <p>This is a convenience method that uses the class loader of {@code ReflectUtil} to load {@code className}.</p>
 400    *
 401    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 402    *
 403    */
 404  0 public static Object loadLibraryAdapter(Iterable<? extends File> libraryPath, String adapterName,
 405    Class<?>[] constructorSig,Object... constructorArgs) throws ReflectException {
 406  0 return loadLibraryAdapter(CURRENT_LOADER, libraryPath, adapterName, constructorSig, constructorArgs);
 407    }
 408   
 409    /**
 410    * <p>Create an adapter object which provides an interface to a library that is not available statically on the
 411    * class path (or, more generally, to the {@code baseLoader}). This assumes the relevant code may be organized
 412    * into three groups: the base classes, which are available to the {@code baseLoader} and make
 413    * no direct references to the library or adapter classes; the library classes, which are located in the path
 414    * represented by {@code libraryPath}, and make no direct references to the adapter class; and the adapter
 415    * class (including its inner classes), which is available to the {@code baseLoader}, and which can
 416    * directly refer to both the library and base classes.</p>
 417    *
 418    * <p>This is a convenience method that infers the constructor signature from the given arguments. Note that the
 419    * inference process for the constructor signature is potentially error-prone, because it uses the concrete runtime
 420    * types of the objects, which may be more specific than what is needed. It is impossible, for example, to use this
 421    * method to invoke a constructor whose parameters include interface, abstract class, or primitive types. In such
 422    * cases, {@link #loadLibraryAdapter(ClassLoader, Iterable, String, Class[], Object[])} should be used instead.</p>
 423    *
 424    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 425    *
 426    */
 427  1 public static Object loadLibraryAdapter(ClassLoader baseLoader, Iterable<? extends File> libraryPath,
 428    String adapterName, Object... constructorArgs) throws ReflectException {
 429  1 return loadLibraryAdapter(baseLoader, libraryPath, adapterName, getClasses(constructorArgs), constructorArgs);
 430    }
 431   
 432    /**
 433    * <p>Create an adapter object which provides an interface to a library that is not available statically on the
 434    * class path (or, more generally, to the {@code baseLoader}). This assumes the relevant code may be organized
 435    * into three groups: the base classes, which are available to the {@code baseLoader} and make
 436    * no direct references to the library or adapter classes; the library classes, which are located in the path
 437    * represented by {@code libraryPath}, and make no direct references to the adapter class; and the adapter
 438    * class (including its inner classes), which is available to the {@code baseLoader}, and which can
 439    * directly refer to both the library and base classes.</p>
 440    *
 441    * <p>This method constructs an appropriate class loader and then invokes
 442    * {@link #loadObject(ClassLoader, String, Class[], Object[])}.</p>
 443    *
 444    * @throws ReflectException As specified by {@link #loadObject(ClassLoader, String, Class[], Object[])}
 445    *
 446    */
 447  1 public static Object loadLibraryAdapter(ClassLoader baseLoader, Iterable<? extends File> libraryPath,
 448    String adapterName, Class<?>[] constructorSig, Object... constructorArgs)
 449    throws ReflectException {
 450  1 ClassLoader libraryLoader = new PathClassLoader(baseLoader, libraryPath);
 451  1 ClassLoader adapterLoader = new PreemptingClassLoader(libraryLoader, adapterName);
 452  1 return loadObject(adapterLoader, adapterName, constructorSig, constructorArgs);
 453    }
 454   
 455    /**
 456    * Combine two class loaders by first matching classes in {@code first}, then delegating to {@code second}.
 457    */
 458  0 public static ComposedClassLoader mergeLoaders(ClassLoader first, ClassLoader second) {
 459  0 return new ComposedClassLoader(first, second);
 460    }
 461   
 462    /**
 463    * Combine two class loaders by matching specific classes (or class prefixes) from {@code first}, and delegating
 464    * all other searches to {@code second}. Bootstrap classes will not be filtered from {@code first}.
 465    */
 466  0 public static ComposedClassLoader mergeLoaders(ClassLoader first, ClassLoader second, String... firstIncludes) {
 467  0 return mergeLoaders(first, second, false, firstIncludes);
 468    }
 469   
 470    /**
 471    * Combine two class loaders by matching a subset of those in {@code first}, followed by a search in {@code second}.
 472    * The nature of the subset is defined by parameters {@code blackList} and {@code firstPrefixes}. Bootstrap classes
 473    * will not be filtered from {@code first}.
 474    * @param blackList Whether classes matching {@code firstPrefixes} should be shadowed in {@code first}; otherwise,
 475    * all classes <em>except</em> those that match will be shadowed.
 476    * @param firstPrefixes Class or package prefix to match in determining which classes or {@code first} are shadowed
 477    */
 478  0 public static ComposedClassLoader mergeLoaders(ClassLoader first, ClassLoader second, boolean blackList,
 479    String... firstPrefixes) {
 480  0 ClassLoader filteredFirst = new ShadowingClassLoader(first, blackList, IterUtil.asIterable(firstPrefixes), false);
 481  0 return new ComposedClassLoader(filteredFirst, second);
 482    }
 483   
 484    /**
 485    * Wrap a static field in a box. The field will be accessed via reflection, and any resulting errors will be
 486    * thrown as {@link ReflectException}s nested in {@link WrappedException}s by the box's {@code value()} and
 487    * {@code set()} methods. If the field is known statically, and performance is important, consider defining a
 488    * custom box instead.
 489    */
 490  6 public static <T> Box<T> staticFieldAsBox(Class<?> c, String fieldName, Class<T> fieldType) {
 491  6 return new FieldBox<T>(c, fieldName, fieldType, null);
 492    }
 493   
 494    /**
 495    * Wrap a field of the given object in a box. The field will be accessed via reflection, and any resulting errors
 496    * will be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the box's {@code value()} and
 497    * {@code set()} methods. If the field is known statically, and performance is important, consider defining a
 498    * custom box instead.
 499    */
 500  4 public static <T> Box<T> fieldAsBox(Object object, String fieldName, Class<T> fieldType) {
 501  4 return new FieldBox<T>(object.getClass(), fieldName, fieldType, object);
 502    }
 503   
 504    private static final class FieldBox<T> implements Box<T>, Serializable {
 505    private final Class<?> _objClass;
 506    private final String _name;
 507    private final Class<T> _type;
 508    private final Object _obj;
 509    private transient Field _field; // optimization; transient because Field isn't serializable
 510   
 511  10 public FieldBox(Class<?> objClass, String name, Class<T> type, Object obj) {
 512  10 _objClass = objClass;
 513  10 _name = name;
 514  10 _type = type;
 515  10 _obj = obj;
 516  10 _field = null;
 517    }
 518   
 519  12 public T value() {
 520  12 try {
 521  8 if (_field == null) { _field = _objClass.getField(_name); }
 522  10 try { return cast(_type, _field.get(_obj)); }
 523    // catch null pointer here to prevent silly null pointers (e.g. _name is null) from being caught
 524  1 catch (NullPointerException e) { throw new WrappedException(new NullPointerReflectException(e)); }
 525    }
 526  2 catch (NoSuchFieldException e) { throw new WrappedException(new NoSuchFieldReflectException(e)); }
 527  0 catch (IllegalArgumentException e) { throw new WrappedException(new IllegalArgumentReflectException(e)); }
 528  0 catch (IllegalAccessException e) { throw new WrappedException(new IllegalAccessReflectException(e)); }
 529  2 catch (ClassCastException e) { throw new WrappedException(new ClassCastReflectException(e)); }
 530  0 catch (SecurityException e) { throw new WrappedException(new SecurityReflectException(e)); }
 531    }
 532   
 533  6 public void set(T value) {
 534  6 try {
 535  2 if (_field == null) { _field = _objClass.getField(_name); }
 536  6 _field.set(_obj, value);
 537    }
 538  0 catch (NoSuchFieldException e) { throw new WrappedException(new NoSuchFieldReflectException(e)); }
 539  0 catch (IllegalArgumentException e) { throw new WrappedException(new IllegalArgumentReflectException(e)); }
 540  2 catch (IllegalAccessException e) { throw new WrappedException(new IllegalAccessReflectException(e)); }
 541  0 catch (SecurityException e) { throw new WrappedException(new SecurityReflectException(e)); }
 542    }
 543    }
 544   
 545   
 546    /**
 547    * Wrap a static method in a thunk. The method will be invoked via reflection, and any resulting errors will be
 548    * thrown as {@link ReflectException}s nested in {@link WrappedException}s by the thunk's {@code value()} method.
 549    * If the method is known statically, and performance is important, consider defining a custom thunk instead.
 550    */
 551  2 public static <O, R> Thunk<R> staticMethodAsThunk(Class<? super O> c, String methodName, Class<? extends R> retT) {
 552  2 return LambdaUtil.bindFirst(new MethodLambda<O, R>(c, methodName, retT), null);
 553    }
 554   
 555    /**
 556    * Wrap a method of the given object in a thunk. The method will be invoked via reflection, and any resulting
 557    * errors will be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the thunk's
 558    * {@code value()} method. If the method is known statically, and performance is important, consider defining
 559    * a custom thunk instead.
 560    */
 561  1 public static <R> Thunk<R> methodAsThunk(Object object, String methodName, Class<? extends R> retT) {
 562  1 return new ObjectMethodThunk<R>(object, methodName, retT);
 563    }
 564   
 565    /**
 566    * Wrap a method in a lambda, with the receiver object as the first argument. The method will be invoked via
 567    * reflection, and any resulting errors will be thrown as {@link ReflectException}s nested in
 568    * {@link WrappedException}s by the lambda's {@code value()} method. If the method is known statically, and
 569    * performance is important, consider defining a custom lambda instead.
 570    */
 571  2 public static <O, R> Lambda<O, R> methodAsLambda(Class<? super O> c, String methodName, Class<? extends R> retT) {
 572  2 return new MethodLambda<O, R>(c, methodName, retT);
 573    }
 574   
 575    /**
 576    * Wrap a static method in a lambda. The method will be invoked via reflection, and any resulting errors will be
 577    * thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()} method.
 578    * If the method is known statically, and performance is important, consider defining a custom lambda instead.
 579    */
 580  2 public static <O, T, R> Lambda<T, R> staticMethodAsLambda(Class<? super O> c, String methodName,
 581    Class<? super T> argT, Class<? extends R> retT) {
 582  2 return LambdaUtil.bindFirst(new MethodLambda2<O, T, R>(c, methodName, argT, retT), null);
 583    }
 584   
 585    /**
 586    * Wrap a method of the given object in a lambda. The method will be invoked via reflection, and any resulting
 587    * errors will be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's
 588    * {@code value()} method. If the method is known statically, and performance is important, consider defining
 589    * a custom lambda instead.
 590    */
 591  3 public static <T, R> Lambda<T, R> methodAsLambda(Object object, String methodName, Class<? super T> argT,
 592    Class<? extends R> retT) {
 593  3 return new ObjectMethodLambda<T, R>(object, methodName, argT, retT);
 594    }
 595   
 596    /**
 597    * Wrap a method in a lambda, with the receiver object as the first argument. The method will be invoked via
 598    * reflection, and any resulting errors will be thrown as {@link ReflectException}s nested in
 599    * {@link WrappedException}s by the lambda's {@code value()} method. If the method is known statically, and
 600    * performance is important, consider defining a custom lambda instead.
 601    */
 602  1 public static <O, T, R> Lambda2<O, T, R> methodAsLambda2(Class<? super O> c, String methodName,
 603    Class<? super T> argT, Class<? extends R> retT) {
 604  1 return new MethodLambda2<O, T, R>(c, methodName, argT, retT);
 605    }
 606   
 607    /**
 608    * Wrap a static method in a lambda. The method will be invoked via reflection, and any resulting errors will be
 609    * thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()} method.
 610    * If the method is known statically, and performance is important, consider defining a custom lambda instead.
 611    */
 612  1 public static <O, T1, T2, R>
 613    Lambda2<T1, T2, R> staticMethodAsLambda2(Class<? super O> c, String methodName, Class<? super T1> arg1T,
 614    Class<? super T2> arg2T, Class<? extends R> retT) {
 615  1 return LambdaUtil.bindFirst(new MethodLambda3<O, T1, T2, R>(c, methodName, arg1T, arg2T, retT), null);
 616    }
 617   
 618    /**
 619    * Wrap a method of the given object in a lambda. The method will be invoked via reflection, and any resulting
 620    * errors will be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's
 621    * {@code value()} method. If the method is known statically, and performance is important, consider defining
 622    * a custom lambda instead.
 623    */
 624  1 public static <T1, T2, R>
 625    Lambda2<T1, T2, R> methodAsLambda2(Object object, String methodName, Class<? super T1> arg1T,
 626    Class<? super T2> arg2T, Class<? extends R> retT) {
 627  1 return new ObjectMethodLambda2<T1, T2, R>(object, methodName, arg1T, arg2T, retT);
 628    }
 629   
 630    /**
 631    * Wrap a method in a lambda, with the receiver object as the first argument. The method will be invoked via
 632    * reflection, and any resulting errors will be thrown as {@link ReflectException}s nested in
 633    * {@link WrappedException}s by the lambda's {@code value()} method. If the method is known statically, and
 634    * performance is important, consider defining a custom lambda instead.
 635    */
 636  1 public static <O, T1, T2, R>
 637    Lambda3<O, T1, T2, R> methodAsLambda3(Class<? super O> c, String methodName, Class<? super T1> arg1T,
 638    Class<? super T2> arg2T, Class<? extends R> retT) {
 639  1 return new MethodLambda3<O, T1, T2, R>(c, methodName, arg1T, arg2T, retT);
 640    }
 641   
 642    /**
 643    * Wrap a static method in a lambda. The method will be invoked via reflection, and any resulting errors will be
 644    * thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()} method.
 645    * If the method is known statically, and performance is important, consider defining a custom lambda instead.
 646    */
 647  1 public static <O, T1, T2, T3, R>
 648    Lambda3<T1, T2, T3, R> staticMethodAsLambda3(Class<? super O> c, String methodName, Class<? super T1> arg1T,
 649    Class<? super T2> arg2T, Class<? super T3> arg3T,
 650    Class<? extends R> retT) {
 651  1 return LambdaUtil.bindFirst(new MethodLambda4<O, T1, T2, T3, R>(c, methodName, arg1T, arg2T, arg3T, retT), null);
 652    }
 653   
 654    /**
 655    * Wrap a method of the given object in a lambda. The method will be invoked via reflection, and any resulting
 656    * errors will be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's
 657    * {@code value()} method. If the method is known statically, and performance is important, consider defining
 658    * a custom lambda instead.
 659    */
 660  1 public static <T1, T2, T3, R>
 661    Lambda3<T1, T2, T3, R> methodAsLambda3(Object object, String methodName, Class<? super T1> arg1T,
 662    Class<? super T2> arg2T, Class<? super T3> arg3T, Class<? extends R> retT) {
 663  1 return new ObjectMethodLambda3<T1, T2, T3, R>(object, methodName, arg1T, arg2T, arg3T, retT);
 664    }
 665   
 666    /**
 667    * Wrap a method in a lambda, with the receiver object as the first argument. The method will be invoked via
 668    * reflection, and any resulting errors will be thrown as {@link ReflectException}s nested in
 669    * {@link WrappedException}s by the lambda's {@code value()} method. If the method is known statically, and
 670    * performance is important, consider defining a custom lambda instead.
 671    */
 672  1 public static <O, T1, T2, T3, R>
 673    Lambda4<O, T1, T2, T3, R> methodAsLambda4(Class<? super O> c, String methodName, Class<? super T1> arg1T,
 674    Class<? super T2> arg2T, Class<? super T3> arg3T,
 675    Class<? extends R> retT) {
 676  1 return new MethodLambda4<O, T1, T2, T3, R>(c, methodName, arg1T, arg2T, arg3T, retT);
 677    }
 678   
 679   
 680    /** Common code for method-wrapping lambdas. */
 681    private static abstract class MethodWrapper<R> implements Serializable {
 682    private final Class<?> _objClass;
 683    private final String _name;
 684    private final Class<? extends R> _returnType;
 685    private final Class<?>[] _signature;
 686    private transient Method _method; // optimization; transient because Method isn't serializable
 687   
 688  17 protected MethodWrapper(Class<?> objClass, String name, Class<? extends R> returnType, Class<?>... signature) {
 689  17 _objClass = objClass;
 690  17 _name = name;
 691  17 _returnType = returnType;
 692  17 _signature = signature;
 693  17 _method = null;
 694    }
 695   
 696    /** Invoke the method with the given arguments. Throws a wrapped ReflectException. */
 697  26 protected R invoke(Object obj, Object... args) {
 698  26 try {
 699  18 if (_method == null) { _method = _objClass.getMethod(_name, _signature); }
 700  23 try { return cast(_returnType, _method.invoke(obj, args)); }
 701    // catch null pointer here to prevent silly null pointers (e.g. _name is null) from being caught
 702  1 catch (NullPointerException e) { throw new WrappedException(new NullPointerReflectException(e)); }
 703    }
 704  3 catch (NoSuchMethodException e) { throw new WrappedException(new NoSuchMethodReflectException(e)); }
 705  0 catch (IllegalArgumentException e) { throw new WrappedException(new IllegalArgumentReflectException(e)); }
 706  0 catch (InvocationTargetException e) { throw new WrappedException(new InvocationTargetReflectException(e)); }
 707  0 catch (IllegalAccessException e) { throw new WrappedException(new IllegalAccessReflectException(e)); }
 708  2 catch (ClassCastException e) { throw new WrappedException(new ClassCastReflectException(e)); }
 709  0 catch (SecurityException e) { throw new WrappedException(new SecurityReflectException(e)); }
 710    }
 711    }
 712   
 713    private static final class ObjectMethodThunk<R> extends MethodWrapper<R> implements Thunk<R> {
 714    private final Object _obj;
 715  1 public ObjectMethodThunk(Object obj, String name, Class<? extends R> returnT) {
 716  1 super(obj.getClass(), name, returnT); _obj = obj;
 717    }
 718  1 public R value() { return invoke(_obj); }
 719    }
 720   
 721    private static final class MethodLambda<O, R> extends MethodWrapper<R> implements Lambda<O, R> {
 722  4 public MethodLambda(Class<? super O> objT, String name, Class<? extends R> returnT) {
 723  4 super(objT, name, returnT);
 724    }
 725  7 public R value(O obj) { return invoke(obj); }
 726    }
 727   
 728    private static final class ObjectMethodLambda<T, R> extends MethodWrapper<R> implements Lambda<T, R> {
 729    private final Object _obj;
 730  3 public ObjectMethodLambda(Object obj, String name, Class<? super T> argT, Class<? extends R> returnT) {
 731  3 super(obj.getClass(), name, returnT, argT); _obj = obj;
 732    }
 733  3 public R value(T arg) { return invoke(_obj, arg); }
 734    }
 735   
 736    private static final class MethodLambda2<O, T, R> extends MethodWrapper<R> implements Lambda2<O, T, R> {
 737  3 public MethodLambda2(Class<? super O> objT, String name, Class<? super T> argT, Class<? extends R> returnT) {
 738  3 super(objT, name, returnT, argT);
 739    }
 740  4 public R value(O obj, T arg) { return invoke(obj, arg); }
 741    }
 742   
 743    private static final class ObjectMethodLambda2<T1, T2, R> extends MethodWrapper<R> implements Lambda2<T1, T2, R> {
 744    private final Object _obj;
 745  1 public ObjectMethodLambda2(Object obj, String name, Class<? super T1> arg1T, Class<? super T2> arg2T,
 746    Class<? extends R> returnT) {
 747  1 super(obj.getClass(), name, returnT, arg1T, arg2T); _obj = obj;
 748    }
 749  1 public R value(T1 arg1, T2 arg2) { return invoke(_obj, arg1, arg2); }
 750    }
 751   
 752    private static final class MethodLambda3<O, T1, T2, R> extends MethodWrapper<R> implements Lambda3<O, T1, T2, R> {
 753  2 public MethodLambda3(Class<? super O> objT, String name, Class<? super T1> arg1T, Class<? super T2> arg2T,
 754    Class<? extends R> returnT) {
 755  2 super(objT, name, returnT, arg1T, arg2T);
 756    }
 757  5 public R value(O obj, T1 arg1, T2 arg2) { return invoke(obj, arg1, arg2); }
 758    }
 759   
 760    private static final class ObjectMethodLambda3<T1, T2, T3, R> extends MethodWrapper<R>
 761    implements Lambda3<T1, T2, T3, R> {
 762    private final Object _obj;
 763  1 public ObjectMethodLambda3(Object obj, String name, Class<? super T1> arg1T, Class<? super T2> arg2T,
 764    Class<? super T3> arg3T, Class<? extends R> returnT) {
 765  1 super(obj.getClass(), name, returnT, arg1T, arg2T, arg3T); _obj = obj;
 766    }
 767  1 public R value(T1 arg1, T2 arg2, T3 arg3) { return invoke(_obj, arg1, arg2, arg3); }
 768    }
 769   
 770    private static final class MethodLambda4<O, T1, T2, T3, R> extends MethodWrapper<R>
 771    implements Lambda4<O, T1, T2, T3, R> {
 772  2 public MethodLambda4(Class<? super O> objT, String name, Class<? super T1> arg1T, Class<? super T2> arg2T,
 773    Class<? super T3> arg3T, Class<? extends R> returnT) {
 774  2 super(objT, name, returnT, arg1T, arg2T, arg3T);
 775    }
 776  4 public R value(O obj, T1 arg1, T2 arg2, T3 arg3) { return invoke(obj, arg1, arg2, arg3); }
 777    }
 778   
 779   
 780    /**
 781    * Wrap a constructor in a thunk. The constructor will be invoked via reflection, and any resulting errors will
 782    * be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the thunk's {@code value()}
 783    * method. If the constructor is known statically, and performance is important, consider defining a custom
 784    * thunk instead.
 785    */
 786  4 public static <R> Thunk<R> constructorAsThunk(Class<? extends R> c) {
 787  4 return new ConstructorThunk<R>(c);
 788    }
 789   
 790    /**
 791    * Wrap a constructor in a lambda. The constructor will be invoked via reflection, and any resulting errors will
 792    * be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()}
 793    * method. If the constructor is known statically, and performance is important, consider defining a custom
 794    * lambda instead.
 795    */
 796  3 public static <T, R> Lambda<T, R> constructorAsLambda(Class<? extends R> c, Class<? super T> argT) {
 797  3 return new ConstructorLambda<T, R>(c, argT);
 798    }
 799   
 800    /**
 801    * Wrap a constructor in a lambda. The constructor will be invoked via reflection, and any resulting errors will
 802    * be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()}
 803    * method. If the constructor is known statically, and performance is important, consider defining a custom
 804    * lambda instead.
 805    */
 806  0 public static <T1, T2, R> Lambda2<T1, T2, R> constructorAsLambda2(Class<? extends R> c, Class<? super T1> arg1T,
 807    Class<? super T2> arg2T) {
 808  0 return new ConstructorLambda2<T1, T2, R>(c, arg1T, arg2T);
 809    }
 810   
 811    /**
 812    * Wrap a constructor in a lambda. The constructor will be invoked via reflection, and any resulting errors will
 813    * be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()}
 814    * method. If the constructor is known statically, and performance is important, consider defining a custom
 815    * lambda instead.
 816    */
 817  1 public static <T1, T2, T3, R> Lambda3<T1, T2, T3, R>
 818    constructorAsLambda3(Class<? extends R> c, Class<? super T1> arg1T, Class<? super T2> arg2T,
 819    Class<? super T3> arg3T) {
 820  1 return new ConstructorLambda3<T1, T2, T3, R>(c, arg1T, arg2T, arg3T);
 821    }
 822   
 823    /**
 824    * Wrap a constructor in a lambda. The constructor will be invoked via reflection, and any resulting errors will
 825    * be thrown as {@link ReflectException}s nested in {@link WrappedException}s by the lambda's {@code value()}
 826    * method. If the constructor is known statically, and performance is important, consider defining a custom
 827    * lambda instead.
 828    */
 829  0 public static <T1, T2, T3, T4, R> Lambda4<T1, T2, T3, T4, R>
 830    constructorAsLambda4(Class<? extends R> c, Class<? super T1> arg1T, Class<? super T2> arg2T,
 831    Class<? super T3> arg3T, Class<? super T4> arg4T) {
 832  0 return new ConstructorLambda4<T1, T2, T3, T4, R>(c, arg1T, arg2T, arg3T, arg4T);
 833    }
 834   
 835   
 836    /** Common code for constructor-wrapping lambdas. */
 837    private static abstract class ConstructorWrapper<R> implements Serializable {
 838    private final Class<? extends R> _c;
 839    private final Class<?>[] _signature;
 840    private transient Constructor<? extends R> _k; // optimization; transient because Constructor isn't serializable
 841   
 842  8 protected ConstructorWrapper(Class<? extends R> c, Class<?>... signature) {
 843  8 _c = c;
 844  8 _signature = signature;
 845  8 _k = null;
 846    }
 847   
 848    /** Invoke the constructor with the given arguments. Throws a wrapped ReflectException. */
 849  9 protected R invoke(Object... args) {
 850  9 try {
 851  8 if (_k == null) { _k = _c.getConstructor(_signature); }
 852  8 return _k.newInstance(args);
 853    }
 854  1 catch (NoSuchMethodException e) { throw new WrappedException(new NoSuchMethodReflectException(e)); }
 855  0 catch (IllegalArgumentException e) { throw new WrappedException(new IllegalArgumentReflectException(e)); }
 856  1 catch (InvocationTargetException e) { throw new WrappedException(new InvocationTargetReflectException(e)); }
 857  0 catch (IllegalAccessException e) { throw new WrappedException(new IllegalAccessReflectException(e)); }
 858  1 catch (InstantiationException e) { throw new WrappedException(new InstantiationReflectException(e)); }
 859  0 catch (SecurityException e) { throw new WrappedException(new SecurityReflectException(e)); }
 860    }
 861    }
 862   
 863    private static final class ConstructorThunk<R> extends ConstructorWrapper<R> implements Thunk<R> {
 864  4 public ConstructorThunk(Class<? extends R> c) { super(c); }
 865  4 public R value() { return invoke(); }
 866    }
 867   
 868    private static final class ConstructorLambda<T, R> extends ConstructorWrapper<R> implements Lambda<T, R> {
 869  3 public ConstructorLambda(Class<? extends R> c, Class<? super T> argT) { super(c, argT); }
 870  4 public R value(T arg) { return invoke(arg); }
 871    }
 872   
 873    private static final class ConstructorLambda2<T1, T2, R> extends ConstructorWrapper<R>
 874    implements Lambda2<T1, T2, R> {
 875  0 public ConstructorLambda2(Class<? extends R> c, Class<? super T1> arg1T, Class<? super T2> arg2T) {
 876  0 super(c, arg1T, arg2T);
 877    }
 878  0 public R value(T1 arg1, T2 arg2) { return invoke(arg1, arg2); }
 879    }
 880   
 881    private static final class ConstructorLambda3<T1, T2, T3, R> extends ConstructorWrapper<R>
 882    implements Lambda3<T1, T2, T3, R> {
 883  1 public ConstructorLambda3(Class<? extends R> c, Class<? super T1> arg1T, Class<? super T2> arg2T,
 884    Class<? super T3> arg3T) {
 885  1 super(c, arg1T, arg2T, arg3T);
 886    }
 887  1 public R value(T1 arg1, T2 arg2, T3 arg3) { return invoke(arg1, arg2, arg3); }
 888    }
 889   
 890    private static final class ConstructorLambda4<T1, T2, T3, T4, R> extends ConstructorWrapper<R>
 891    implements Lambda4<T1, T2, T3, T4, R> {
 892  0 public ConstructorLambda4(Class<? extends R> c, Class<? super T1> arg1T, Class<? super T2> arg2T,
 893    Class<? super T3> arg3T, Class<? super T4> arg4T) {
 894  0 super(c, arg1T, arg2T, arg3T, arg4T);
 895    }
 896  0 public R value(T1 arg1, T2 arg2, T3 arg3, T4 arg4) { return invoke(arg1, arg2, arg3, arg4); }
 897    }
 898    }