-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb: > What do you use for getting your pointcut patterns right?
Hi Jakub, indeed, using AspectJ now since several years, I've found there is the possibility to get astray. Some of my observations/guidelines: - - the moment you're going to target individual methods or (worse) specific parameter patterns, you should be alarmed. Such tends to be unstable and cause endless maintenance problems. - - try fist to create specific interfaces, which capture a concept precisely. And then write your pointcuts against those interfaces. - - use annotations instead of method/class names to direct the match - - try to be *declarative* That means: a set of pointcuts should describe a *logical* relationship, and *not* a specific execution situation. - - and by all means: *name* your pointcuts! Never create such a "train wreck" sequence of && and || with dozens of individual patterns. Instead, create small logical groups (1..3 clauses) and *try to give them a descriptive and precise name* Naming is not just avoidable bla bla. It's the key of getting things right. If you aren't able to give a pointcut a proper name, you should consider it broken! If you adhere to this rules, testing is rather simple. Write a test/dummy before advice for each separately named pointcut, and verify (either with the AJDT cross reference view or by log messages) that it matches the right targets. Regarding the example you quoted, I'd propose the following: > (portletEntryMethods() AND !cflowbelow(portletEntryMethods())) > || (call(* javax.xml.soap.SOAPConnection.call(..)) > AND within(com.tonbeller.jpivot.xmla.XMLA_SOAP)) > || (within(com.tonbeller..*) > AND (execution(* XMLA_SOAP.discover(..)) > || execution.... - - the final "top level" pointcut, which you are addressing in your advice should be just a disjunction of named pointcuts - - the parts in turn should be the conjugation of named sub-pointcuts - - the within() pointcuts should be declared abstract and the specific packages pushed down into the concrete aspect. - - you can use *one* aspect just to place annotations on specific methods; which then can be targeted by other aspects! Couldn't you utilise this technique to simplify your pointcut? for example all the various execution pointcuts could be replaced by a pointcut targeting the execution of a method with a custom annotation. And another aspect would place this annotation at the right places. Hope this helps Cheers, Hermann Vosseler -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkq8wMwACgkQZbZrB6HelLKTZQCbBKRsEbliPTlgxSIgXQEkVEqN uhMAn3+ee+/1KFnbxmz0WKNyH8vVgSqy =DIxE -----END PGP SIGNATURE----- _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
