Archinamon / android-gradle-aspectj

gradle plug-in adding supports of AspectJ into Android project
Apache License 2.0
363 stars 58 forks source link

Can not track lambda expressions #56

Closed jdvp closed 7 years ago

jdvp commented 7 years ago

Hello, perhaps I am using the library wrong somehow but I can't get pointcuts to work on lambda expressions in android code.

For instance, if I have the pointcut for a dialog's button click

@Before("execution(* android.content.DialogInterface.OnClickListener+.onClick(..))")

the logging function will be called as expected in a regularly-defined listener such as the following:

builder.setNegativeButton("string", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        //do something
    }
});

but not when it is defined using lambda notation:

builder.setNegativeButton("string", (dialog, which) -> {
      //do something
});

I'm not sure if this is expected behavior and couldn't find anything on the internet about it so I thought I would ask you about if you've experienced this.

Thanks, and sorry if this have been covered somewhere else!

Badya commented 7 years ago

@jdvp, do you use retrolambda?

I think if you inspect decompiled bytecode, you may find some java.util.function.* object handling your lambda.

Even more - lambdas can create additional classes in bytecode (ex: OnClickListener$1.OnClick()$1 etc..), so i suppose pointcut has to be tuned somehow to work with lambdas

jdvp commented 7 years ago

@Badya No we are using DexGuard for lambdas.

Thanks for the help though. I actually went with that approach and made a separate pointcut for dealing with the lambdas themselves!

I will close this issue since I don't think this is something that actually has to be fixed