}
if (bestMatchingCtor == null) {
if (possibleCtor == null) {
usedDeps = 0;
throw new ObjectAccessException("Cannot construct "
+ type.getName()
+ ", none of the dependencies match any constructor's parameters");
} else {
bestMatchingCtor = possibleCtor;
matchingDependencies.clear();
matchingDependencies.addAll(possibleMatchingDependencies);
usedDeps = possibleUsedDeps;
}
}
}
try {
final T instance;
if (bestMatchingCtor == null) {
instance = type.newInstance();
} else {
@SuppressWarnings("unchecked")
final T obj = (T)bestMatchingCtor.newInstance(matchingDependencies.toArray());
instance = obj;
}
if (usedDependencies != null) {
usedDependencies.clear();
int i = 0;
for(long l = 1; l < usedDeps; l <<= 1, ++i) {
if ((usedDeps & l) > 0) {
usedDependencies.set(i);
}
}
}
return instance;
} catch (final InstantiationException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
} catch (final IllegalAccessException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
} catch (final InvocationTargetException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
} catch (final SecurityException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
} catch (final ExceptionInInitializerError e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
}
}