ReflectionUtil { @Pure public static boolean matchesParameters(Class<?>[] formalParameters, Object... parameterValues) { if (formalParameters == null) { return parameterValues == null; } if (parameterValues != null && formalParameters.length == parameterValues.length) { for (int i = 0; i < formalParameters.length; ++i) { if (!isInstance(formalParameters[i], parameterValues[i])) { return false; } } return true; } return false; } private  ReflectionUtil(); @Pure @SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:returncount"}) static boolean isInstance(Class<?> type, Object obj); @Pure static boolean isAssignableFrom(Class<?> assignementTarget, Class<?> assignementSource); @Pure @SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity"}) static Class<?> forName(String name); @Pure @Inline(value = "ReflectionUtil.forName(($1), true, ($2))", imported = {ReflectionUtil.class}) static Class<?> forName(String name, ClassLoader loader); @Pure @SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity"}) static Class<?> forName(String name, boolean typeInitialization, ClassLoader loader); @Pure @Inline(value = "ReflectionUtil.getPackageClasses(($1).getName())", imported = {ReflectionUtil.class}) static Collection<Class<?>> getPackageClasses(Package pkg); @Pure static Collection<Class<?>> getPackageClasses(String packageName); @Pure @Inline("getSubClasses($1, null)") static Collection<Class<? extends T>> getSubClasses(Class<T> className); @Pure static Collection<Class<? extends T>> getSubClasses(Class<T> className, DynamicURLClassLoader classLoader); static void getSubClasses(Class<T> className, boolean allowAbstract, boolean allowInterface,
			boolean allowEnum, Collection<Class<? extends T>> result); static void getSubClasses(Class<T> className, boolean allowAbstract, boolean allowInterface,
			boolean allowEnum, Collection<Class<? extends T>> result, DynamicURLClassLoader classLoader); @Pure @SuppressWarnings("unchecked") static Set<Class<? extends I>> getAllDirectInterfaces(Class<? extends T> lowestType,
			Class<T> highestType, Class<I> interfaceType); static Set<Class<?>> getAllDirectInterfaces(Class<? extends T> lowestType, Class<T> highestType); @Pure static Collection<Class<? super T>> getSuperClasses(Class<T> className); static Class<?> getCommonType(Class<?> type1, Class<?> type2); @Pure static Class<?> getCommonType(Object instance1, Object instance2); @Pure @SuppressWarnings({"checkstyle:returncount", "npathcomplexity"}) static Class<?> getOutboxingType(Class<?> type); @Pure @SuppressWarnings({"checkstyle:returncount", "npathcomplexity"}) static Class<?> getInboxingType(Class<?> type); @Pure static boolean matchesParameters(Class<?>[] formalParameters, Object... parameterValues); @Pure @Inline(value = "ReflectionUtil.matchesParameters(($1).getParameterTypes(), ($2))", imported = {ReflectionUtil.class}) static boolean matchesParameters(Method method, Object... parameters); static String toString(Object object); static void toJson(Object object, JsonBuffer output); static T newInstance(Class<T> type, Object... arguments);  }
@Test public void matchesParametersClassObjectArray() { assertTrue(ReflectionUtil.matchesParameters( new Class<?>[0], new Object[0])); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[0], new Object[] { 1 })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class }, new Object[0])); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class }, new Object[] { 'c' })); assertTrue(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class }, new Object[] { 3. })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class }, new Object[] { 4f })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class }, new Object[] { 1 })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[0])); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 'c' })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 3. })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 4. })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 1 })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 'c', "a" })); assertTrue(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 3., "a" })); assertTrue(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 4., "a" })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 1, "a" })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 'c', true })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 3., true })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 4., true })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class }, new Object[] { 1, true })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class, Array.class }, new Object[0])); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class, Array.class }, new Object[] { 1. })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class, Array.class }, new Object[] { 1., "a" })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class, Array.class }, new Object[] { 1., "a", null })); assertFalse(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class, Array.class }, new Object[] { 1., "a", new int[0] })); assertTrue(ReflectionUtil.matchesParameters( new Class<?>[] { Double.class, String.class, int[].class }, new Object[] { 1., "a", new int[0] })); assertTrue(ReflectionUtil.matchesParameters( new Class<?>[] { Number.class, String.class, int[].class }, new Object[] { 1., "a", new int[0] })); }