2


I have android application with 2 modules.

First module contains Activity class defined like so: MyActivity extends AppCompatActivity

Second module contains aspect class, where I want to create @Pointcut to MyActivity.onCreate method.

It works if defined like so: @Pointcut("execution(* *.onCreate(..))")

Just don't want ANY onCreate call, but MyActivity.onCreate or AppCompatActivity.onCreate.

Tried @Pointcut(execution(* MyActivity.onCreate(..))), but it doesn't work.

So, how can I reference class from another module with @Pointcut ?

How extended classes behave with aspects ? For example creating @Pointcut to AppCompatActivity also works at MyActivity, beacuse it is it's child ?

Thanks for any responses :)

milkamar
  • 443
  • 6
  • 16
  • Found out that difference between `execution` and `call` is time, when it is determinated. It is nicely describen here: http://perfspy.blogspot.cz/2013/09/differences-between-aspectj-call-and.html – milkamar Oct 12 '16 at 18:51

1 Answers1

0

In your pointcut definition, whenever using a class, the compiler needs to know which class you're refering to unambigously. To do so, you should use the canonical name of your class.

For instance, if your activity is in package com.company.project, then your pointcut should be :

@Pointcut(execution(* com.company.project.MyActivity.onCreate(..)))
XGouchet
  • 10,002
  • 10
  • 48
  • 83
  • Actually this is not completely correct because @milkamar wanted a pointcut which also captures the base class. Therefore it should be `@Pointcut("execution(* com.x.y.AppCompatActivity.onCreate(..))")`. This captures the base class method as well as overridden ones from subclasses. If you want to make it more explicit you can optionally also use `+` to denote your intent to capture subclasses. It is not strictly necessary in this case but helpful in others. It would look like this: `@Pointcut("execution(* com.x.y.AppCompatActivity+.onCreate(..))")`. You also forgot the double quotes. – kriegaex Oct 16 '16 at 11:03