Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to get the enclosing class in a Pointcut

Just want to 100% understand your requirement:

I want to find which classes and methods  outside our application that calls to our application classes with public methods that has annotation @Deprecated.

You want to find calls to your API *from* code marked @Deprecated or you want to find calls made *to* @Deprecated code?

If you mean the latter then your pointcut isn’t quite right.


pointcut deprecatedMethods() : call(public * *.*(..)) && @withincode(Deprecated);

This says “match calls made to public methods *from* code marked @Deprecated”.

If you want to match calls *to* deprecated methods it would be more like:

“call(public * *(..)) && @annotation(Deprecated)”

In this second case the enclosingjoinpoint would be the Demo.test and the target of the call would be the deprecated method getBoards().

Is that any help?

cheers,
Andy


On Sep 18, 2017, at 6:27 AM, Mikael Petterson <mikaelpetterson@xxxxxxxxxxx> wrote:

Hi,

I have started to look into aspectj , now that I have a working dev environment in Eclipse 😊

I want to find which classes and methods  outside our application that calls to our application classes with public methods that has annotation @Deprecated.

I have created the following 'pointcut':

pointcut deprecatedMethods() : call(public * *.*(..)) && @withincode(Deprecated);
    before() : deprecatedMethods() {
      log("[Deprecated Method Usage]" +" --> "+ thisEnclosingJoinPointStaticPart.getSignature().toShortString+"\n");

    }


The above will give something like:

[Deprecated Method Usage] --> HandlerImpl.getBoards(..)

 I can see which classes' methods with @Deprecated gets called. But I cannot see  what the name of the enclosing class and method is, in this case Demo.test() ( see below).

  1. Is it possible to get this using aspectj?
  2. What would be the correct pointcut to use?

br.

//mike


public class Demo extends Test{

    @Test
    public void test() {
      Node node = new Node();
      Handler handler = node.getObjectHandler();
      //getBoards() is the deprecated method.
      Boards boards = handler.getBoards();
      
 
    }
}


 
 
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top