this.type = type;
}
@SuppressWarnings({"unchecked"})
public boolean doTask(InjectionContext ctx) {
IOCProcessingContext processingContext = ctx.getProcessingContext();
InjectableInstance injectableInstance = getInjectableInstance(ctx);
Injector inj;
QualifyingMetadata qualifyingMetadata = processingContext.getQualifyingMetadataFactory()
.createFrom(injectableInstance.getQualifiers());
switch (taskType) {
case Type:
ctx.getQualifiedInjector(type, qualifyingMetadata);
break;
case PrivateField: {
if (!ctx.isInjectableQualified(field.getType(), qualifyingMetadata)) {
return false;
}
try {
inj = ctx.getQualifiedInjector(field.getType(), qualifyingMetadata);
}
catch (InjectionFailure e) {
e.setTarget(toString());
throw e;
}
processingContext.append(
Stmt.invokeStatic(processingContext.getBootstrapClass(), getPrivateFieldInjectorName(field),
Refs.get(injector.getVarName()), inj.getType(ctx, injectableInstance))
);
ctx.addExposedField(field);
break;
}
case Field:
if (!ctx.isInjectableQualified(field.getType(), qualifyingMetadata)) {
return false;
}
try {
inj = ctx.getQualifiedInjector(field.getType(), qualifyingMetadata);
}
catch (InjectionFailure e) {
e.setTarget(toString());
throw e;
}
processingContext.append(
Stmt.loadVariable(injector.getVarName()).loadField(field.getName()).assignValue(inj.getType(ctx,
injectableInstance))
);
break;
case PrivateMethod: {
for (MetaParameter parm : method.getParameters()) {
ctx.getProcessingContext().handleDiscoveryOfType(
new InjectableInstance(null, TaskType.Parameter, null, method, null, parm.getType(), parm, injector, ctx));
if (!ctx.isInjectableQualified(parm.getType(), qualifyingMetadata)) {
return false;
}
}
Statement[] smts = resolveInjectionDependencies(method.getParameters(), ctx, method);
Statement[] parms = new Statement[smts.length];
parms[0] = Refs.get(injector.getVarName());
System.arraycopy(smts, 0, parms, 1, smts.length);
processingContext.append(
Stmt.invokeStatic(processingContext.getBootstrapClass(), getPrivateMethodName(method),
parms)
);
break;
}
case Method:
for (MetaParameter parm : method.getParameters()) {
ctx.getProcessingContext().handleDiscoveryOfType(
new InjectableInstance(null, TaskType.Parameter, null, method, null, parm.getType(), parm, injector, ctx));
if (!ctx.isInjectableQualified(parm.getType(), qualifyingMetadata)) {
return false;
}
}
processingContext.append(
Stmt.loadVariable(injector.getVarName()).invoke(method,
resolveInjectionDependencies(method.getParameters(), ctx, method))
);
break;