A facility for getting the current method's name

Sebastian Sickelmann sebastian.sickelmann at gmx.de
Thu Sep 29 12:22:22 PDT 2011


Am 28.09.2011 07:02, schrieb Krystal Mok:
> Yeah, I'm sure there are a lot of ways one can implement this feature. 
> It's just the matter of whether or not the feature should be supported 
> by the core libs.
Yes. This is the big question. If i think of the two solutions i had 
first in mind the compile-time solutions
wins agains the vm-load-time solution. Haven't seen the annotation 
processor solutions (maybe
because i haven't used it myself), but it looks much less complex than 
changing the javac.

Is there any annotation processor that is fixed (or hard coded) in the 
javac? I think about this
@NotNull annotation, how are these implemented?
>
> I can even imagine (ab-)using an annotation processor to pull it off. 
> Something that looks like:
>
> public class Foo {
>   public void bar() {
>     @CurrentMethodName
>     String __method__ = null; // suppose this local variable is 
> generated by some refactoring tool
>   }
> }
>
> where @CurrentMethodName is a ElementType.LOCAL_VARIABLE + 
> RetentionPolicy.SOURCE annotation, and the null assignment gets 
> replaced to the actual value, by a custom annotation processor at 
> compile time.
>
> Regards,
> Kris Mok
<snip long thread/>
-- Sebastian


More information about the jdk8-dev mailing list