Re: Method Name extraction
Wojtek wrote:
Daniel Pitts wrote :
Hmm, were you hoping for something like:
@FillWithMethodName
final String myMethodName = "";
Well yes, actually...
Though I was thinking more like:
@MethodNameExtract(WOJTEK1)
private static final String WOJTEK1 = "";
public String getFoo()
{
Log.trace(CLASS_NAME,WOJTEK1,"getting Foo");
return "Foo";
}
So after the (pre) compiler does its thing, the code would look like:
private static final String WOJTEK1 = "getFoo";
Here is an AspectJ example:
public class C1 {
public void m1() {
System.out.println(Current.getClznam() + " " +
Current.getMthnam());
C2 o = new C2();
o.m2();
}
public static void main(String[] args) {
C1 o = new C1();
o.m1();
}
}
public class C2 {
public void m2() {
System.out.println(Current.getClznam() + " " +
Current.getMthnam());
}
}
import org.aspectj.lang.*;
import org.aspectj.lang.annotation.*;
@Aspect
public class Current {
private static String clznam;
private static String mthnam;
@Pointcut("call(public * *.*(..)) && !within(Current) &&
!call(public * Current.*(..)) && !call(public * java.lang.*.*(..))")
public void allcalls() { };
@Before("allcalls()")
public void beforeCall(JoinPoint thisJoinPoint) {
clznam = thisJoinPoint.getSignature().getDeclaringTypeName();
mthnam = thisJoinPoint.getSignature().getName();
}
public static String getClznam() {
return clznam;
}
public static String getMthnam() {
return mthnam;
}
}
Absolutely not good OOP code, but it shows some of the
capabilities.
Arne