private static <T> Constructor<T> getPotentialConstructorWrapped(Class<T> classThatContainsTheConstructorToTest, Class<?>[] argumentTypes) { return new CandidateConstructorSearcher<T>(classThatContainsTheConstructorToTest, argumentTypes) .findConstructor(); }
public Constructor<T> findConstructor() { final Constructor<T>[] constructors = getConstructors(); if (constructors.length == 0) { return null; } if (constructors.length == 1) { return constructors[0]; } else { return findBestCandidate(constructors); } }
@SuppressWarnings("unchecked") private Constructor<T>[] getConstructors() { try { Constructor<?>[] declaredConstructors = classThatContainsTheConstructorToTest.getDeclaredConstructors(); List<Constructor<?>> constructors = new ArrayList<Constructor<?>>(); for (Constructor<?> constructor : declaredConstructors) { if (argumentsApplied(constructor)) { constructors.add(constructor); } } return constructors.toArray(new Constructor[constructors.size()]); } catch (Exception e) { return new Constructor[0]; } }
private static <T> Constructor<T> getPotentialConstructorPrimitive(Class<T> classThatContainsTheConstructorToTest, Class<?>[] argumentTypes) { Constructor<T> potentialConstructorPrimitive = null; try { Class<?>[] primitiveType = PrimitiveWrapper.toPrimitiveType(argumentTypes); if (!argumentTypesEqualsPrimitiveTypes(argumentTypes, primitiveType)) { potentialConstructorPrimitive = new CandidateConstructorSearcher<T>(classThatContainsTheConstructorToTest, primitiveType) .findConstructor(); } } catch (Exception e) { // Do nothing } return potentialConstructorPrimitive; }