}
}
if (!constructorInjectionPoints.isEmpty()) {
if (constructorInjectionPoints.size() > 1) {
throw new InjectionFailure("more than one constructor in "
+ type.getFullyQualifiedName() + " is marked as the injection point!");
}
final MetaConstructor constructor = constructorInjectionPoints.get(0);
return new ConstructionStrategy() {
@Override
public void generateConstructor(final ConstructionStatusCallback callback) {
final Statement[] parameterStatements
= resolveInjectionDependencies(constructor.getParameters(), ctx, constructor);
if (injector.isSingleton() && injector.isCreated()) return;
final IOCProcessingContext processingContext = ctx.getProcessingContext();
final Statement objectInstantiate = Stmt.newObject(type, parameterStatements);
processingContext.append(
Stmt.declareFinalVariable(injector.getInstanceVarName(), type, objectInstantiate)
);
callback.beanConstructed(ConstructionType.CONSTRUCTOR);
handleInjectionTasks(ctx, injectionTasks);
doPostConstruct(ctx, injector, postConstructTasks);
doPreDestroy(ctx, injector, preDestroyTasks);
}
};
}
else {
// field injection
if (!hasDefaultConstructor(type))
throw new InjectionFailure("there is no public default constructor or suitable injection constructor for type: "
+ type.getFullyQualifiedName());
return new ConstructionStrategy() {
@Override
public void generateConstructor(final ConstructionStatusCallback callback) {