Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Generics and Advice not being applied (Beginner Question)

Hello,

     I am currently  migrating some existing code to use Generics. During the course of the migration I ran into a problem with generics and  pointcut definition which I am unable to resolve, and any help is greatly appreciated.

The original definition of a method that I am selecting is

BOIterator load(BusinessObjectDef boDef, String[] aIntgFieldName, String sWhereClause, String sOrderBy, PRequestOptions opts)
            throws ServerException, BusinessObjectException, NetworkException

and the corresponding pointcut definition is

pointcut loadWhereClause(BusinessObjectDef boDef, String[] fields, String sWhereClause, String sOrderBy, PRequestOptions options) : args(boDef, fields, sWhereClause, sOrderBy, options) && execution (BOIterator *Session*.load(BusinessObjectDef, String[], String, String, PRequestOptions));

Upon migrating to generics the method signature changes to

<T extends BusinessObject> BOIterator<T> load(BusinessObjectDef boDef, String[] aIntgFieldName, String sWhereClause, String sOrderBy, PRequestOptions opts) throws ServerException, BusinessObjectException, NetworkException

I noticed that eclipse complained of unchecked conversion from BOIterator<? extends BusinessObject> to BOIterator [Xlint:uncheckedAdviceConversion]. In an attempt to fix it I tried a few alternatives. I changed the pointcut definition to include the generic type definitions as follows

pointcut loadWhereClause(BusinessObjectDef boDef, String[] fields, String sWhereClause, String sOrderBy, PRequestOptions options) : args(boDef, fields, sWhereClause, sOrderBy, options) && execution (BOIterator<? extends BusinessObject> *Session*.load(BusinessObjectDef, String[], String, String, PRequestOptions));

Unfortunately the advise is not being applied anymore. I have defined an around advice as follows

BOIterator<? extends  BusinessObject> around(BusinessObjectDef boDef, String[] fields, String sWhereClause, String sOrderBy, PRequestOptions options) : loadWhereClause(boDef, fields, sWhereClause, sOrderBy, options)

On a side note is generic support included if the above code were to be migrated to use load time weaving i.e. how are pointcut definitions which include generic information applied at runtime (given erasure).

Once again as I mentioned in the subject, I am a beginner to aspectj and generics in java, and apologize for any glaring errors. Thank you for your assistance

Thanks
Bhaskar


Back to the top