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?

Ah!  Perfect, thank you - especially for the doc links, I see now the get() and set() pointcuts for access to fields... I couldn't find any examples that showed direct field access, only calling of accessor methods.  And I did not find a search function for the online docs...  Possibly a case of lazy user syndrome.  {sigh}

On Thu, Jul 2, 2026, at 9:26 PM, Alexander Kriegisch via aspectj-users wrote:
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?
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users



Back to the top