Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Getting the reference to an annotated class

> I got that doubt only because my other pointcut threw a null pointer exception.

"this" in call join points refers to the caller.  And "this" is null in the
context of constructor-execution.

Read the programmer's guide section on join points:

  http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html

> Is there any way to remove the reference to PersonalDetail completely 
> from this pointcut definition ?

Do you want to? thisJoinPoint is expensive.  It is more efficient and type-safe
to bind the variable.

Also, I suspect you want after-returning rather than after advice.

hth - Wes

------------Original Message------------
From: Mohan Radhakrishnan <radhakrishnan.mohan@xxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Tue, Feb-14-2006 8:04 AM
Subject: Re: [aspectj-users] Getting the reference to an annotated class
Hi,
     I got that doubt only because my other pointcut threw a null pointer exception.

after() : call ( public PersonalDetail.new(..) ){
  System.out.println( "Call [" + thisJoinPoint.getThis() + "]");
  (( PersonalDetail )thisJoinPoint.getThis())
     .setDao( DAOFactory.getDAOFactory ( 2 ).getAddressDAO() );
 }
 
and this one did not match

 after( PersonalDetail p ) : call ( public PersonalDetail.new(..) )&& this( p ){
  System.out.println( "Call [" + thisJoinPoint.getThis() + "]");
  (( PersonalDetail )thisJoinPoint.getThis()) 
     .setDao( DAOFactory.getDAOFactory( 2 ).getAddressDAO() );
 }
 

Thanks,
Mohan

 
On 2/14/06, Eric Bodden <eric.bodden@xxxxxxxxxxxxxx> wrote: 
> but could not write   thisJoinPoint.getThis().setDao(
> DAOFactory.getDAOFactory( 2 ).getAddressDAO() ); becuase 
> thisJoinPoint.getThis()
> returns an Object.

You have to simply cast it to the interface/class you require.
thisJoinPoint has no knowledge about the class, hence it can only return
Object.

So try:


after( Entity e ) : execution ( PersonalDetail.new(..) ) && annotation(
e ){  .....
PersonalDetail = (PersonalDetail) thisJoinPoint.getThis();
}

You should not use *.new(..) in stat case because that could also bind 
"this" to other types if they have the Entity annotation, which would
make your cast fail.

If PersonalDetail is still too specific for you in the signature, then
you have to create some interface in between. You do need some 
information about the type you are working on - otherwise you cannot add
a reference.

Eric

--
Eric Bodden
Sable Research Group, McGill University
Montreal, Canada

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


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



Back to the top