[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Newbie Questions: Biggest Issue
|
Greetings!
I'm just beginning with AspectJ today so I hope you can all forgive a
newbie with some questions. I'll ask them in sequential emails to keep
the size of each question manageable....
While the idea behind AspectJ seems worthwhile and I'm already starting
to get a sense of the potential, I'm getting bogged down in beginner issues.
The biggest problem I'm having is that I can't access values from one of
my methods.
I'm trying to imitate this example from the AspectJ Language Guide in my
own code:
after(FigureElement fe, int x, int y) returning:
call(void FigureElement.setXY(int, int))
&& target(fe)
&& args(x, y) {
System.out.println(fe + " moved to (" + x + ", " + y + ")");
}
This is my play program:
============================================
package test;
import ca.maximal.common.utilities.CountUtils;
public class Test01 {
final String CLASS_NAME = getClass().getName();
public static void main(String[] args) {
@SuppressWarnings("unused")
Test01 countStuff = new Test01();
}
public Test01() {
String needle = "a";
String haystack = "supercalifragilisticexpialadocious";
int occurrences = count(needle, haystack);
System.out.println("needle = " + needle + "; haystack = " +
haystack + "; count = " + occurrences);
}
private static int count(String needle, String haystack) {
int count = CountUtils.count(needle, haystack);
return count;
}
}
============================================
This is my Aspect:
============================================
package test;
/**
* This class
*
* <p>More</p>
*
* @version 1.0
* @since Feb 24, 2012
*/
public aspect LogCount {
pointcut howManyNeedles() : execution(* Test01.count(..));
// pointcut count2() : call(int count(String, String));
/* First Before */
before() : howManyNeedles() {
System.out.println("About to count...."); //$NON-NLS-1$
}
/* First After */
after() returning() : howManyNeedles() {
System.out.println("...Needles counted"); //$NON-NLS-1$
}
/* Second After */
after(int num, String needle, String haystack) returning:
target(num)
&& args(needle, haystack)
&& call(* Test01.count(..)) {
System.out.println("** needle = " + needle + "; haystack = " +
haystack + "; num = " + num); //$NON-NLS-1$
}
}
============================================
The "First Before" and "First After" pointcuts work fine. But the
"Second After" resolutely refuses to work despite many different
variations on the call() statement. I've tried everything I can think of
but NOTHING works.
I'm sure this is something very simple but I'm darned if I can figure it
out. I wonder if someone on this mailing list can help me see what's wrong?
--
Rhino