Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Join point for directly accessing a field?

You want to familiarise yourself with get() and set() pointcut types:

https://eclipse.dev/aspectj/doc/latest/progguide/progguide.html#quick-pointcuts
https://eclipse.dev/aspectj/doc/latest/progguide/progguide.html#_field_related_pointcuts

For example, assuming all this code is inside file A.aj and compiled
with ajc:

public class A {
  public static int a = 42;

  public static void main(String[] args) {
    new B().b();
  }
}

class B {
  void b() {
    System.out.println(A.a);
  }
}

aspect MyAspect {
  before() : get(* A.a) {
    System.out.println(thisJoinPoint);
  }
}

Console log:

get(int A.a)
42

In your pseudo code, class A is static, as if it was contained in
another class. In that case, the class qualifier in the pointcut would
need to contain the outer class.
-- 
Alexander Kriegisch
https://scrum-master.de


rich.tail3690--- via aspectj-users schrieb am 03.07.2026 um 08:09:
> If I have the following:
> 
> public static class A {
>    public static int a = 42;
> }
> 
> class B {
>    void b {
>       System.out.println(A.a);
>    }
> }
> 
> What pointcut would define the join point accessing class A's field?
> In other words, how do I add advice to the use of A.a?


Back to the top