Support logging interceptions
This commit is contained in:
+3
-2
@@ -98,8 +98,8 @@ public class InterceptionInstrumenter implements Instrumenter {
|
||||
compilePattern(annotation.erasedSignature()),
|
||||
annotation.allowMultipleMatches(),
|
||||
enterData,
|
||||
exitData
|
||||
);
|
||||
exitData,
|
||||
annotation.logInterceptions());
|
||||
instrumenters.add(instrumenter);
|
||||
neverMatchedInstrumenters.add(instrumenter);
|
||||
}
|
||||
@@ -205,6 +205,7 @@ public class InterceptionInstrumenter implements Instrumenter {
|
||||
for (MethodInstrumenter instrumenter : instrumenters) {
|
||||
if (instrumenter.isApplicable(name, desc)) {
|
||||
applicableInstrumenters.add(instrumenter);
|
||||
instrumenter.reportApplication(cr.getClassName(), name, desc);
|
||||
|
||||
checkMultipleMatches(instrumenter, name, desc);
|
||||
neverMatchedInstrumenters.remove(instrumenter);
|
||||
|
||||
+2
@@ -26,4 +26,6 @@ interface MethodInstrumenter {
|
||||
List<MethodData> getEnterData();
|
||||
|
||||
boolean allowsMultipleMatches();
|
||||
|
||||
void reportApplication(String className, String methodName, String methodDesc);
|
||||
}
|
||||
|
||||
+12
-2
@@ -25,19 +25,22 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
private final boolean allowMultipleMatches;
|
||||
private final List<MethodData> enterData;
|
||||
private final List<MethodData> exitData;
|
||||
private final boolean logApplications;
|
||||
|
||||
public MethodInstrumenterImpl(
|
||||
Pattern namePattern,
|
||||
Pattern descPattern,
|
||||
boolean allowMultipleMatches,
|
||||
List<MethodData> enterData,
|
||||
List<MethodData> exitData
|
||||
List<MethodData> exitData,
|
||||
boolean logApplications
|
||||
) {
|
||||
this.namePattern = namePattern;
|
||||
this.descPattern = descPattern;
|
||||
this.allowMultipleMatches = allowMultipleMatches;
|
||||
this.enterData = enterData;
|
||||
this.exitData = exitData;
|
||||
this.logApplications = logApplications;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +48,13 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
return allowMultipleMatches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportApplication(String className, String methodName, String methodDesc) {
|
||||
if (logApplications) {
|
||||
System.out.println(toString() + " applied to " + className + ":" + methodName + methodDesc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(String name, String desc) {
|
||||
return namePattern.matcher(name).matches() && descPattern.matcher(desc).matches();
|
||||
@@ -62,6 +72,6 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return namePattern + " " + descPattern + (allowMultipleMatches ? "[multiple]" : "");
|
||||
return namePattern + " " + descPattern + (allowMultipleMatches ? " [multiple]" : "");
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -35,4 +35,7 @@ public @interface MethodInterceptor {
|
||||
|
||||
// if this is false, an exception is thrown when more than one method in the same class matches
|
||||
boolean allowMultipleMatches() default false;
|
||||
|
||||
// if true, every method instrumented with this interceptor will be logged to stdout
|
||||
boolean logInterceptions() default false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user