Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] toString Aspect aspect browser

Thanks for the workaround.

An interesting thought, to exclude subtypes.  Needs a +:

-- from:
> declare parents : (IPhilipsTarget && !com.philips..*)

-- to:
> declare parents : (IPhilipsTarget+ && !com.philips..*)
                                   ^

(and assumes IPhilipsTarget is in com.philips..*)

Now, if there were a com.philips..* class
that extended a class outside com.philips..*
that extended a class inside com.philips..*,
then... *smile*

(Given the idiom traffic in tag interfaces, it seems clear
that we should be considering ways to name a set of
staticly determinable types.  Adrian's offered one...)

Wes

Ron Bodkin wrote:

Wes,

It's a bit convoluted, but this should work around the limitation you cited:

private interface IPhilipsTarget {}

private interface IPhilipsTargetException {}

declare parents : (!ToStringEnhancer && com.philips..*)
           implements IPhilipsTarget;

// exclude any subclasses that are not defined in com.philips or a subpackage
declare parents : (IPhilipsTarget && !com.philips..*)
           implements IPhilipsTargetException;

String around(Object targ) : target(targ)
          && target(IPhilipsTarget) && !target(IPhilipsTargetException)
...

Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895


------------Original Message-------------
From: Wes Isberg <wes@xxxxxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Thu, Jul-24-2003 11:55 AM
Subject: Re: [aspectj-users] toString Aspect aspect browser

This is an interesting question: how to advise toString()
that could be implemented in a superclass.

It's not clear which calls to toString() you want:

- *all* calls, from and to any code
- only calls to your code, though from anywhere

Writing a pointcut for "all" or "anywhere" runs up against
issues with code the compiler controls, but it might work
to combine call and execution.  Some background, in brief:

- to handle method call join points, ajc needs the calling code
- to handle method execution join points, ajc needs the code
  implementing the method
- call join points enclose a corresponding execution
  join point

(See links below for more details)

Since you are replacing the join point, you can combine
call and execution:

  // warnings: weak style, untested...
  String around(Object targ) : target(targ)
       && !cflow(execution(String toStringUtil(Object)))
       && (call(String toString()))
          || execution(String toString()))) {
      return toStringUtil(targ);
  }

So where ajc controls the caller, it will be replaced at
the call join point.  Where ajc controls the implementation,
it will be replaced at the execution join point.

Note that I used cflow to prevent recursion, so
toStringUtil(Object) { {code} } can use toString().

This pointcut might be bad style because it speaks to all
code, though the runtime namespace will include code that
was and wasn't controlled by ajc.  (i.e., it is implicitly
restricted by the scope of code the compiler controls).
One way restrict the scope to your code is as follows:

    private interface IPhilipsTarget {}

    declare parents : (!ToStringEnhancer && com.philips..*)
        implements IPhilipsTarget;

    String around(Object targ) : target(targ)
         && target(IPhilipsTarget)
         ...rest the same

There's one problem with this.  A subtype of a com.philips..*
type will be treated as IPhilipsTarget even if it is not in
com.philips..*

Wes

Links:
- The Programming guide limitations appendix

  http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/limitations.html

- The FAQ entry on the difference between call and execution

  http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq.html#q:comparecallandexecution

- The 1.1 readme section on callee-side call join points
  (implemented in 1.0, but not in 1.1)

  http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/README-11.html#NO_CALLEE_SIDE_CALL



jon.pallas@xxxxxxxxxxx wrote:


Thanks Ron

I now see that i should have used execution() rather than call()


The problem is that if

public String toString()  if is implemented only in java.lang,Object;

The aspect cant find it as a joinpoint.

if i implement toString() in my class

public String toString() { return "You wont see this because the aspect will get there first";}

It is found by the asect and i get my nice string out.


Is there a way around this??

Thanks again Jon











"DiFrango, Ron" <ron.difrango@xxxxxxxxxxxxxx>
2003-07-24 03:38 PM


       To:     "'aspectj-users@xxxxxxxxxxx'" <aspectj-users@xxxxxxxxxxx>
       cc:     Jon Pallas/EHV/CE/PHILIPS@EMEA3
       Subject:        RE: [aspectj-users] toString Aspect aspect browser
Classification:


Jon,

I got it to work with the following:

      public pointcut myClass(Object obj) : within(com.philips.sct..*)
                                && this(obj);

public pointcut myToString(Object obj) : myClass(obj)
                                && execution(public String toString());

                String around(Object obj) : myToString(obj) {
return StringUtil.toString(obj); }

Thanks,

Ron DiFrango


-----Original Message-----
From: jon.pallas@xxxxxxxxxxx [mailto:jon.pallas@xxxxxxxxxxx] Sent: Thursday, July 24, 2003 7:58 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] toString Aspect aspect browser


Hi All

I am new to aspectj so I may be doing something simple wrong any help would be apperciated.

I have writen an Aspect that i want to intersept any call to toString(). The code is below using the aspect browser in eclipse i can see that it only affects classes that are not in com.philips.sct? but his is what i want tbe be affected?
Is it just the browser or is it my code?

Thanks
Jon




1)

package com.philips.sct.aspects;

import com.philips.common.util.StringUtil;

public aspect ToStringEnhancerAspect {

public pointcut myClass(Object obj) : within(com.philips.sct..*) && this(obj);


       public pointcut myAspects() : within(com.philips.sct.aspects.*);


       public pointcut myToString(Object obj) : !myAspects()
                       &&  myClass(obj)
                       &&  call(public String toString())
                       ;

       String around (Object obj): myToString(obj){
return StringUtil.toString(obj); }
}


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users

**************************************************************************
The information transmitted herewith is sensitive information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top