Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] around two methods ?

Can't you just write it in a regular Java program and use AJ to weave it
in where you want it to happen? Doesn't look like a crosscutting problem
to me.

Charles Zhang 		(http://www.eecg.utoronto.ca/~czhang)
Candidate of M.A.Sc.  Computer Group, Dept. of Elec. & Comp. Engineering 
U. of Toronto, Ontario, Canada
*********************************************************
" Yawn!!" (Charles Zhang) 

On Fri, 28 Mar 2003, [iso-8859-1] julien bieren wrote:

> N.B.: I posted this message two weeksago. I dare to
> re-post it becasue i would really need help. Thanks.
> 
> Hi,
> 
> A question that may sound stupid to someone:
> 
> 1) The simple case
> 
> Let's assume i have a Java program such as:
> ...
> method1();
> method2();
> ...
> 
> and i want to add an aspect and get the result:
> ...
> if (cond) {
>   method1();
> } else {
>   method1bis();
> }
> method2();
> 
> It is fine, i only need an around call (void
> method1()), i test the cond then proceed() or execute
> method1bis().
> 
> 2) 
> But let's assume i have this:
> method1();
> method2();
> method3();
> 
> and i want to add an aspect to get the result:
> if (cond) {
>   method1();
>   method2();
> } else {
>   method1bis();
>   method2bis();
> //method4(); as many as wanted
> }
> method3();
> 
> And here i don't know. At the moment i have two
> solutions:
>   - i encapsulate method1 and method2 into void
> method12 { method1(); method2();} and use the same
> kind of around advice as before. But for some reasons
> (in complex cases) this method is not convenient,
>   - i use one around advice for method1 and one for
> method2. In this around i execute as many methods of
> the "else" path and keep trace of which branch i am in
> with a boolean or int. In that case for instance: 
> 
> boolean elsePath = false;
> 
> void around(): call (void method1()) {
>   if (cond) {
>     proceed();
>   } else {
>     elsePath = true;
>     method1bis();
>     method2bis();
>     //method4(); as many as wanted
>   }
> }
> 
> void around(): call (void method2()) {
>   if (elsePath) {
>    return;
>   } else {
>     proceed();
>   }
> }
> 
> But this solution would look very ugly in complex
> cases.
> 
> Does anybody have another solution to do this ?
> 
> OK, i hope the question won't be harder to understand
> (due to unclearness) than the problem to solve.
> 
> Thank you everybody.
> 
> Julien BIEREN
> Computer Science Student.
> 
> ___________________________________________________________
> Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en fran?ais !
> Yahoo! Mail : http://fr.mail.yahoo.com
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top