Skip to main content

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


> - Shouldn't a pertarget/perthis aspect declare field pretty much the same way as an inter-type declaration in a singleton aspect?
Sometimes.  The instantiation model of the aspect won't affect the application of static crosscutting.  An intertype field declaration onto some type will apply for all instances of that type, not just a subset that might be selected by the instantiation model - so the fields will always be there, but when they are used depends on your advice.  perthis()/pertarget() allow for even finer grained control over the state lifecycle where you want some state to exist for just a subset of the join points that occur during execution.

> - 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).
An intertype declaration will allow you to associate extra state with all instances of some type.  If you are associating the state with the objects via ITD then you can just write normal advice (no need for something other than singleton) to set/get the field related to the object in question (but you will need to use this/target to determine the object upon which you want to manipulate the field instance).  If you are keeping the state internal to the aspect (as fields) then you will need to choose perthis/pertarget to ensure multiple aspect instances.  As with regular advice - if using call() then use target() and if using execution() then use this().  So if you are writing execution() advice then use perthis().

> - 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?

All intertype declarations have associated weave info messages:

C:\temp>ajc -1.5 A.java -showWeaveInfo
Type 'A' (A.java) has intertyped field from 'X' (A.java:'int A.i')


Andy.

2008/10/14 Jochen Wuttke <jochen.wuttke@xxxxxx>
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


Back to the top