Support logging interceptions
This commit is contained in:
+3
-2
@@ -98,8 +98,8 @@ public class InterceptionInstrumenter implements Instrumenter {
|
|||||||
compilePattern(annotation.erasedSignature()),
|
compilePattern(annotation.erasedSignature()),
|
||||||
annotation.allowMultipleMatches(),
|
annotation.allowMultipleMatches(),
|
||||||
enterData,
|
enterData,
|
||||||
exitData
|
exitData,
|
||||||
);
|
annotation.logInterceptions());
|
||||||
instrumenters.add(instrumenter);
|
instrumenters.add(instrumenter);
|
||||||
neverMatchedInstrumenters.add(instrumenter);
|
neverMatchedInstrumenters.add(instrumenter);
|
||||||
}
|
}
|
||||||
@@ -205,6 +205,7 @@ public class InterceptionInstrumenter implements Instrumenter {
|
|||||||
for (MethodInstrumenter instrumenter : instrumenters) {
|
for (MethodInstrumenter instrumenter : instrumenters) {
|
||||||
if (instrumenter.isApplicable(name, desc)) {
|
if (instrumenter.isApplicable(name, desc)) {
|
||||||
applicableInstrumenters.add(instrumenter);
|
applicableInstrumenters.add(instrumenter);
|
||||||
|
instrumenter.reportApplication(cr.getClassName(), name, desc);
|
||||||
|
|
||||||
checkMultipleMatches(instrumenter, name, desc);
|
checkMultipleMatches(instrumenter, name, desc);
|
||||||
neverMatchedInstrumenters.remove(instrumenter);
|
neverMatchedInstrumenters.remove(instrumenter);
|
||||||
|
|||||||
+2
@@ -26,4 +26,6 @@ interface MethodInstrumenter {
|
|||||||
List<MethodData> getEnterData();
|
List<MethodData> getEnterData();
|
||||||
|
|
||||||
boolean allowsMultipleMatches();
|
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 boolean allowMultipleMatches;
|
||||||
private final List<MethodData> enterData;
|
private final List<MethodData> enterData;
|
||||||
private final List<MethodData> exitData;
|
private final List<MethodData> exitData;
|
||||||
|
private final boolean logApplications;
|
||||||
|
|
||||||
public MethodInstrumenterImpl(
|
public MethodInstrumenterImpl(
|
||||||
Pattern namePattern,
|
Pattern namePattern,
|
||||||
Pattern descPattern,
|
Pattern descPattern,
|
||||||
boolean allowMultipleMatches,
|
boolean allowMultipleMatches,
|
||||||
List<MethodData> enterData,
|
List<MethodData> enterData,
|
||||||
List<MethodData> exitData
|
List<MethodData> exitData,
|
||||||
|
boolean logApplications
|
||||||
) {
|
) {
|
||||||
this.namePattern = namePattern;
|
this.namePattern = namePattern;
|
||||||
this.descPattern = descPattern;
|
this.descPattern = descPattern;
|
||||||
this.allowMultipleMatches = allowMultipleMatches;
|
this.allowMultipleMatches = allowMultipleMatches;
|
||||||
this.enterData = enterData;
|
this.enterData = enterData;
|
||||||
this.exitData = exitData;
|
this.exitData = exitData;
|
||||||
|
this.logApplications = logApplications;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,6 +48,13 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
|||||||
return allowMultipleMatches;
|
return allowMultipleMatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reportApplication(String className, String methodName, String methodDesc) {
|
||||||
|
if (logApplications) {
|
||||||
|
System.out.println(toString() + " applied to " + className + ":" + methodName + methodDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(String name, String desc) {
|
public boolean isApplicable(String name, String desc) {
|
||||||
return namePattern.matcher(name).matches() && descPattern.matcher(desc).matches();
|
return namePattern.matcher(name).matches() && descPattern.matcher(desc).matches();
|
||||||
@@ -62,6 +72,6 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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
|
// if this is false, an exception is thrown when more than one method in the same class matches
|
||||||
boolean allowMultipleMatches() default false;
|
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