if (extendsBlock == null && (type.isAbstract() || type.isInterface() || type.isPrimitive()))
throw new InvalidTypeException("Cannot instantiate type:" + type, blame);
writer.reset();
final CallParameters callParameters = (parameters != null) ?
fromStatements(GenUtil.generateCallParameters(context, parameters)) : CallParameters.none();
if (!type.isInterface() && type.getBestMatchingConstructor(callParameters.getParameterTypes()) == null) {
if (context.isPermissiveMode()) {
// fall-through
}
else {
throw new UndefinedConstructorException(type, blame, callParameters.getParameterTypes());
}
}
final StringBuilder buf = new StringBuilder();
buf.append("new ").append(LoadClassReference.getClassReference(type, context, true));
if (callParameters != null) {
buf.append(callParameters.generate(Context.create(context)));
}
if (extendsBlock != null) {
for (final MetaField field : type.getDeclaredFields()) {
context.addVariable(Variable.create(field.getName(), field.getType()));
}