private List<Constructor<T>> getSortedMatchingConstructors() { List<Constructor<T>> matchingConstructors = new ArrayList<Constructor<T>>(); Constructor<T>[] allConstructors = getConstructors(); // filter out all constructors that will definitely not match final Parameter[] paramsToUse = (parameters != null && parameters.length > 0) ? parameters[0].getParams() : null; for (Constructor<T> constructor : allConstructors) { if ((paramsToUse == null || constructor.getParameterTypes().length == paramsToUse.length) && hasApplicableConstructorModifiers(constructor.getModifiers())) { matchingConstructors.add(constructor); } } // optimize list of constructors moving the longest at the beginning if (paramsToUse == null) { Collections.sort(matchingConstructors, new Comparator<Constructor>() { public int compare(final Constructor arg0, final Constructor arg1) { return arg1.getParameterTypes().length - arg0.getParameterTypes().length; } }); } return matchingConstructors; }
private List<Constructor<T>> getSortedMatchingConstructors() { List<Constructor<T>> matchingConstructors = new ArrayList<Constructor<T>>(); Constructor<T>[] allConstructors = getConstructors(); // filter out all constructors that will definitely not match final Parameter[] paramsToUse = (parameters != null && parameters.length > 0) ? parameters[0].getParams() : null; for (Constructor<T> constructor : allConstructors) { if ((paramsToUse == null || constructor.getParameterTypes().length == paramsToUse.length) && hasApplicableConstructorModifiers(constructor.getModifiers())) { matchingConstructors.add(constructor); } } // optimize list of constructors moving the longest at the beginning if (paramsToUse == null) { Collections.sort(matchingConstructors, new Comparator<Constructor>() { public int compare(final Constructor arg0, final Constructor arg1) { return arg1.getParameterTypes().length - arg0.getParameterTypes().length; } }); } return matchingConstructors; }
nonMatching.addAll(Arrays.asList(getConstructors())); throw new PicoCompositionException("Either the specified parameters do not match any of the following constructors: " + nonMatching.toString() + "; OR the constructors were not accessible for '" + getComponentImplementation().getName() + "'");
nonMatching.addAll(Arrays.asList(getConstructors())); throw new PicoCompositionException("Either the specified parameters do not match any of the following constructors: " + nonMatching.toString() + "; OR the constructors were not accessible for '" + getComponentImplementation().getName() + "'");