if (!(producerMember instanceof MetaMethod)) {
throw new InjectionFailure("cannot specialize a field-based producer: " + producerMember);
}
final MetaMethod producerMethod = (MetaMethod) producerMember;
if (producerMethod.isStatic()) {
throw new InjectionFailure("cannot specialize a static producer method: " + producerMethod);
}
if (type.getSuperClass().getFullyQualifiedName().equals(Object.class.getName())) {
throw new InjectionFailure("the specialized producer " + producerMember + " must override "
+ "another producer");
}
context.addInjectorRegistrationListener(getInjectedType(),
new InjectorRegistrationListener() {
@Override
public void onRegister(final MetaClass type, final Injector injector) {
MetaClass cls = producerMember.getDeclaringClass();
while ((cls = cls.getSuperClass()) != null && !cls.getFullyQualifiedName().equals(Object.class.getName())) {
if (!context.hasInjectorForType(cls)) {
context.addType(cls);
}
final MetaMethod declaredMethod
= cls.getDeclaredMethod(producerMethod.getName(), GenUtil.fromParameters(producerMethod.getParameters()));
context.declareOverridden(declaredMethod);
updateQualifiersAndName(producerMethod, context);