-
1. Re: traceStackMatching
adinn Oct 25, 2010 9:29 AM (in response to mazz)Hi John,
Glad you like the feature.
It's rather nice that Java lets you see the call stack. I used the same capability to implement the callerEquals() and callerMatchers() built-ins. I don't know if you have seen these yet but they are really useful in rule condiitons when you want to be very specifci about which calls you are interested in e.g.
RULE fire when foo called from bar CLASS MyClass METHOD foo() AT ENTRY IF callerEquals("MyClass.bar", true) DO traceln("MyClass.foo() called from MyClass.bar()", traceStack() ENDRULE
This means that the rule only gets fired when you are in a call to MyClass.foo() which was made from MyClass.bar(). Calls from any other method will trigger the rule but the condition will be false so it won't fire. n.b. parameter true says include the class name when checking the caller method.
There is also a variant built-in callerMatches() which takes a regular expression rather than a direct method name.
As with the traceStack() and traceStackMatching() calls there are all sorts of optional parameters including a start frame and frame count which means you can be very specific about call paths
RULE fire when foo called from bar called from some other class
CLASS MyClass
METHOD foo()
AT ENTRY
IF callerEquals("MyClass.bar", true, 1, 1) &&
!callerMatches("MyClass\..*", true, 2, 1)
DO traceln("MyClass.foo() called from MyClass.bar() called from some other class",
traceStack()
ENDRULE
Enjoy!
regards,
Andrew Dinn