Extracting debug info printing to separate functions

This commit is contained in:
Mike Bierlee 2015-02-28 16:09:32 +01:00
parent 58073dd160
commit 3d6ab10b6d

View file

@ -64,6 +64,10 @@ struct Autowire(QualifierType = UseMemberType) {
QualifierType qualifier; QualifierType qualifier;
}; };
private void printDebugAutowiredInstance(TypeInfo instanceType, void* instanceAddress) {
writeln(format("DEBUG: Autowiring members of [%s@%s]", instanceType, instanceAddress));
}
/** /**
* Autowires members of a given instance using dependencies registered in the given container. * Autowires members of a given instance using dependencies registered in the given container.
* *
@ -78,9 +82,7 @@ struct Autowire(QualifierType = UseMemberType) {
*/ */
public void autowire(Type)(DependencyContainer container, Type instance) { public void autowire(Type)(DependencyContainer container, Type instance) {
debug(poodinisVerbose) { debug(poodinisVerbose) {
auto instanceType = typeid(Type); printDebugAutowiredInstance(typeid(Type), &instance);
auto instanceAddress = &instance;
writeln(format("DEBUG: Autowiring members of [%s@%s]", instanceType, instanceAddress));
} }
foreach (member ; __traits(allMembers, Type)) { foreach (member ; __traits(allMembers, Type)) {
@ -88,6 +90,10 @@ public void autowire(Type)(DependencyContainer container, Type instance) {
} }
} }
private void printDebugAutowiringCandidate(TypeInfo candidateInstanceType, void* candidateInstanceAddress, TypeInfo instanceType, void* instanceAddress, string member) {
writeln(format("DEBUG: Autowired instance [%s@%s] to [%s@%s].%s", candidateInstanceType, candidateInstanceAddress, instanceType, instanceAddress, member));
}
private void autowireMember(string member, Type)(DependencyContainer container, Type instance) { private void autowireMember(string member, Type)(DependencyContainer container, Type instance) {
// For the love of god, refactor this! <-- Doing it, bro! // For the love of god, refactor this! <-- Doing it, bro!
static if(__traits(compiles, __traits(getMember, Type, member)) && __traits(compiles, __traits(getAttributes, __traits(getMember, Type, member)))) { static if(__traits(compiles, __traits(getMember, Type, member)) && __traits(compiles, __traits(getAttributes, __traits(getMember, Type, member)))) {
@ -98,7 +104,7 @@ private void autowireMember(string member, Type)(DependencyContainer container,
alias MemberType = typeof(memberReference)[0]; alias MemberType = typeof(memberReference)[0];
debug(poodinisVerbose) { debug(poodinisVerbose) {
string qualifiedInstanceTypeString = typeid(MemberType).toString; TypeInfo qualifiedInstanceType = typeid(MemberType);
} }
MemberType qualifiedInstance; MemberType qualifiedInstance;
@ -106,7 +112,7 @@ private void autowireMember(string member, Type)(DependencyContainer container,
alias QualifierType = typeof(autowireAttribute.qualifier); alias QualifierType = typeof(autowireAttribute.qualifier);
qualifiedInstance = container.resolve!(typeof(memberReference), QualifierType); qualifiedInstance = container.resolve!(typeof(memberReference), QualifierType);
debug(poodinisVerbose) { debug(poodinisVerbose) {
qualifiedInstanceTypeString = typeid(QualifierType).toString; qualifiedInstanceType = typeid(QualifierType);
} }
} else { } else {
qualifiedInstance = container.resolve!(typeof(memberReference)); qualifiedInstance = container.resolve!(typeof(memberReference));
@ -115,10 +121,7 @@ private void autowireMember(string member, Type)(DependencyContainer container,
__traits(getMember, instance, member) = qualifiedInstance; __traits(getMember, instance, member) = qualifiedInstance;
debug(poodinisVerbose) { debug(poodinisVerbose) {
auto instanceType = typeid(Type); printDebugAutowiringCandidate(qualifiedInstanceType, &qualifiedInstance, typeid(Type), &instance, member);
auto instanceAddress = &instance;
auto qualifiedInstanceAddress = &qualifiedInstance;
writeln(format("DEBUG: Autowired instance [%s@%s] to [%s@%s].%s", qualifiedInstanceTypeString, qualifiedInstanceAddress, instanceType, instanceAddress, member));
} }
} }