Include interceptor data into console output

This commit is contained in:
Andrey Breslav
2013-05-12 11:06:30 +02:00
parent 3440b85867
commit 8d22c038d5
@@ -71,8 +71,8 @@ public class InterceptionInstrumenter {
List<MethodData> enterData = new ArrayList<MethodData>(); List<MethodData> enterData = new ArrayList<MethodData>();
List<MethodData> exitData = new ArrayList<MethodData>(); List<MethodData> exitData = new ArrayList<MethodData>();
Method[] methods = interceptorClass.getMethods(); List<Method> dumpMethods = new ArrayList<Method>();
for (Method method : methods) { for (Method method : interceptorClass.getMethods()) {
String name = method.getName(); String name = method.getName();
if (name.startsWith("enter")) { if (name.startsWith("enter")) {
enterData.add(getMethodData(fieldData, method)); enterData.add(getMethodData(fieldData, method));
@@ -87,7 +87,7 @@ public class InterceptionInstrumenter {
if (parameterTypes.length == 1 && parameterTypes[0] != PrintStream.class) { if (parameterTypes.length == 1 && parameterTypes[0] != PrintStream.class) {
continue; continue;
} }
addDumpTask(interceptor, method); dumpMethods.add(method);
} }
} }
@@ -101,6 +101,11 @@ public class InterceptionInstrumenter {
enterData, enterData,
exitData, exitData,
annotation.logInterceptions()); annotation.logInterceptions());
for (Method dumpMethod : dumpMethods) {
addDumpTask(interceptor, dumpMethod, instrumenter);
}
instrumenters.add(instrumenter); instrumenters.add(instrumenter);
neverMatchedInstrumenters.add(instrumenter); neverMatchedInstrumenters.add(instrumenter);
} }
@@ -139,10 +144,11 @@ public class InterceptionInstrumenter {
); );
} }
private void addDumpTask(final Object interceptor, final Method method) { private void addDumpTask(final Object interceptor, final Method method, final MethodInstrumenter instrumenter) {
dumpTasks.add(new DumpAction() { dumpTasks.add(new DumpAction() {
@Override @Override
public void dump(PrintStream out) { public void dump(PrintStream out) {
out.println("<<< " + instrumenter + ": " + interceptor.getClass().getCanonicalName() + " says:");
try { try {
if (method.getParameterTypes().length == 0) { if (method.getParameterTypes().length == 0) {
method.invoke(interceptor); method.invoke(interceptor);
@@ -157,6 +163,7 @@ public class InterceptionInstrumenter {
catch (InvocationTargetException e) { catch (InvocationTargetException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
out.println(">>>");
} }
}); });
} }