[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] LTW, inter-type fields and pertarget() aspects

Hi Jochen,
could you post the advice using inter-type fields and giving the error?
I'm using inter-type fields from singleton aspects all the time, and
never had this problem. Anyway, consider that a private field added by
an aspect is private TO THAT ASPECT, not to the class it is being added
to, probably that could be the problem .. but the compiler should catch it.

Simone

Jochen Wuttke wrote:
> Hi,
>
> I started playing with LTW, inter-type fields and pertarget() aspects
> and ran into an interesting problem.
> I was trying to use inter-type fields to carry some information I need
> on a per-object basis. But every time the advice using these
> inter-type fields got executed I got a NoSuchFieldException (the
> compiler gave me a typeNotExposedToWeaver warning, but I think that's
> ok, because I use LTW). So I changed my aspect to be pertarget() and
> it behaves like expected (aspect code below).
>
> Now here are my questions:
> - Shouldn't a pertarget/perthis aspect declare field pretty much the
> same way as an inter-type declaration in a singleton aspect?
> - I'm not sure if I should use a pertarget or perthis aspect for what
> I want to do. The content of the fields should be carried around with
> the advised object across the objects lifetime (which is why I
> originally wanted to use inter-types).
> - When running the LTW with -showWeaveInfo I get a log message for
> every jointpoint that gets woven. What should the message look like
> for weaving inter-type fields. Or should there be a message at all?
>
> Thanks,
> Jochen
>
> P.S.: My aspect looks like this:
>
> public aspect JspIdConsumerUnique pertarget(
> instanceCreation(UIComponentClassicTagBase) ||
> setUniqueProperty(UIComponentClassicTagBase) ) {
>     
>     private boolean lumi_uniquePropertySet = false;
>     private Object lumi_uniqueProperty = null;
>
>     pointcut instanceCreation( UIComponentClassicTagBase _consumer ):
> target(_consumer) && execution( UIComponentClassicTagBase+.new(..) );
>        
>     after(UIComponentClassicTagBase _consumer) : instanceCreation(
> _consumer ) {
>         safeAddObject( _consumer );
>     }
>     
>     pointcut setUniqueProperty( UIComponentClassicTagBase _consumer ):
> target(_consumer) &&
>         call( * UIComponentClassicTagBase+.setJspId(..) );
>     
>     before( UIComponentClassicTagBase _consumer ): setUniqueProperty(
> _consumer ) {
>         uniqueProperty = _consumer.getJspId();
>     }
>     
>     after( UIComponentClassicTagBase _consumer ): setUniqueProperty(
> _consumer ) {
>         if ( propertyHasChanged( _consumer.getJspId() ) ) {
>             lumi_uniquePropertySet = true;
>             updateContainer( uniqueProperty, _consumer );
>         }
>     }
>     
>     //private methods go here
>
> }
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/