Helper class called by all the others:
package de.scrum_master.app;
public class Other {
public void doOther() {}
}
Driver application with all kinds of inner classes:
Here we have
- non-static inner class,
- static inner class,
- local inner class,
- anonymous class
- and of course the normal class.
package de.scrum_master.app;
public class Application {
public String foo(int number) {
new Other().doOther();
return "foo";
}
public class MyInner {
public void doSomething() {
new Other().doOther();
}
}
public static class MyStaticInner {
public void doSomethingElse() {
new Other().doOther();
}
}
public static void main(String[] args) {
new Application().foo(11);
new Application().new MyInner().doSomething();
new Application.MyStaticInner().doSomethingElse();
class LocalInner {
public void doWhatever() {
new Other().doOther();
}
}
new LocalInner().doWhatever();
new Runnable() {
@Override public void run() {
new Other().doOther();
}
}.run();
}
}
Aspect logging caller class names:
package de.scrum_master.aspect;
public aspect CallingClassLogger {
before(Object caller) : !within(CallingClassLogger) && call(* *(..)) && this(caller) {
System.out.println(caller.getClass().getName());
}
}
Console log:
de.scrum_master.app.Application
de.scrum_master.app.Application$MyInner
de.scrum_master.app.Application$MyStaticInner
de.scrum_master.app.Application$1LocalInner
de.scrum_master.app.Application$1
Your aspect would have printed something like
Application.java:5
Application.java:11
Application.java:17
Application.java:28
Application.java:35
which is not so helpful IMO if you are interested in class names.