Support error*() methods
This commit is contained in:
+27
-5
@@ -79,14 +79,23 @@ public class InterceptionInstrumenter {
|
||||
|
||||
List<MethodData> enterData = new ArrayList<MethodData>();
|
||||
List<MethodData> exitData = new ArrayList<MethodData>();
|
||||
List<MethodData> errorData = new ArrayList<MethodData>();
|
||||
List<Method> dumpMethods = new ArrayList<Method>();
|
||||
for (Method method : interceptorClass.getMethods()) {
|
||||
String name = method.getName();
|
||||
MethodData methodData = getMethodData(fieldData, method);
|
||||
if (name.startsWith("enter")) {
|
||||
enterData.add(getMethodData(fieldData, method));
|
||||
enterData.add(methodData);
|
||||
}
|
||||
else if (name.startsWith("exit")) {
|
||||
exitData.add(getMethodData(fieldData, method));
|
||||
exitData.add(methodData);
|
||||
}
|
||||
else if (name.startsWith("error")) {
|
||||
errorData.add(methodData);
|
||||
}
|
||||
else if (name.startsWith("anyExit")) {
|
||||
exitData.add(methodData);
|
||||
errorData.add(methodData);
|
||||
}
|
||||
else if (name.startsWith("dump")) {
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
@@ -109,6 +118,7 @@ public class InterceptionInstrumenter {
|
||||
annotation.allowMultipleMatches(),
|
||||
enterData,
|
||||
exitData,
|
||||
errorData,
|
||||
annotation.logInterceptions());
|
||||
|
||||
for (Method dumpMethod : dumpMethods) {
|
||||
@@ -278,6 +288,7 @@ public class InterceptionInstrumenter {
|
||||
|
||||
final List<MethodData> exitData = new ArrayList<MethodData>();
|
||||
final List<MethodData> enterData = new ArrayList<MethodData>();
|
||||
final List<MethodData> errorData = new ArrayList<MethodData>();
|
||||
|
||||
org.jetbrains.asm4.commons.Method methodBeingInstrumented = new org.jetbrains.asm4.commons.Method(name, desc);
|
||||
|
||||
@@ -298,6 +309,14 @@ public class InterceptionInstrumenter {
|
||||
}
|
||||
exitData.add(methodData);
|
||||
}
|
||||
|
||||
for (MethodData methodData : instrumenter.getErrorData()) {
|
||||
int depth = stackDepth(methodData, methodBeingInstrumented);
|
||||
if (maxStackDepth < depth) {
|
||||
maxStackDepth = depth;
|
||||
}
|
||||
errorData.add(methodData);
|
||||
}
|
||||
}
|
||||
|
||||
if (enterData.isEmpty() && exitData.isEmpty()) return mv;
|
||||
@@ -352,11 +371,14 @@ public class InterceptionInstrumenter {
|
||||
case FRETURN:
|
||||
case DRETURN:
|
||||
case ARETURN:
|
||||
case ATHROW:
|
||||
for (MethodData methodData : exitData) {
|
||||
invokeMethod(access, name, desc, getInstructionAdapter(), methodData, false);
|
||||
}
|
||||
break;
|
||||
case ATHROW:
|
||||
for (MethodData methodData : errorData) {
|
||||
// A constructor may throw before calling super(), 'this' is not available in this case
|
||||
boolean beforeThrowInConstructor = opcode == ATHROW && isConstructor;
|
||||
invokeMethod(access, name, desc, getInstructionAdapter(), methodData, beforeThrowInConstructor);
|
||||
invokeMethod(access, name, desc, getInstructionAdapter(), methodData, isConstructor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+2
@@ -23,6 +23,8 @@ interface MethodInstrumenter {
|
||||
|
||||
List<MethodData> getExitData();
|
||||
|
||||
List<MethodData> getErrorData();
|
||||
|
||||
List<MethodData> getEnterData();
|
||||
|
||||
boolean allowsMultipleMatches();
|
||||
|
||||
+8
-1
@@ -27,6 +27,7 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
private final boolean allowMultipleMatches;
|
||||
private final List<MethodData> enterData;
|
||||
private final List<MethodData> exitData;
|
||||
private final List<MethodData> errorData;
|
||||
private final boolean logApplications;
|
||||
|
||||
public MethodInstrumenterImpl(
|
||||
@@ -36,7 +37,7 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
boolean allowMultipleMatches,
|
||||
List<MethodData> enterData,
|
||||
List<MethodData> exitData,
|
||||
boolean logApplications
|
||||
List<MethodData> errorData, boolean logApplications
|
||||
) {
|
||||
this.debugName = debugName;
|
||||
this.classPattern = classPattern;
|
||||
@@ -45,6 +46,7 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
this.allowMultipleMatches = allowMultipleMatches;
|
||||
this.enterData = enterData;
|
||||
this.exitData = exitData;
|
||||
this.errorData = errorData;
|
||||
this.logApplications = logApplications;
|
||||
}
|
||||
|
||||
@@ -75,6 +77,11 @@ class MethodInstrumenterImpl implements MethodInstrumenter {
|
||||
return exitData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MethodData> getErrorData() {
|
||||
return errorData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]";
|
||||
|
||||
Reference in New Issue
Block a user