constructor = definition.getConstructor();
} else {
// no definition, heuristically determine constructor
Constructor[] constructors = clazz.getConstructors();
if (constructors.length == 0) {
throw new NoConstructorException("No public constructor for class");
} else if (constructors.length == 1) {
// Only one constructor, take it
constructor = constructors[0];
} else {
// multiple constructors scenario
Constructor<T> selected = null;
for (Constructor<T> ctor : constructors) {
if (ctor.getParameterTypes().length == 0) {
selected = ctor;
} else if (ctor.getParameterTypes().length == conArgs.size()) {
// we will find a constructor which has atleast one
// reference or property as its parameter types.
Class<?>[] parametersTypes = ctor.getParameterTypes();
for (Class<?> pType: parametersTypes) {
for (JavaElementImpl property : props.values()) {
if (pType.equals(property.getType()))
selected = ctor;
}
for (JavaElementImpl reference : refs.values()) {
if (pType.equals(reference.getType()))
selected = ctor;
}
}
}
}
if (selected == null) {
throw new NoConstructorException();
}
constructor = selected;
}
definition = type.getConstructors().get(constructor);
type.setConstructor(definition);