Created
July 11, 2012 09:28
-
-
Save siosio/3089274 to your computer and use it in GitHub Desktop.
クロージャの名前
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hogehoge { | |
def cls = {} | |
static hogefuga = {} | |
} | |
cls = {} | |
def cls2 = {} | |
def method(Closure c) { | |
println getDeclaredName(c) | |
} | |
def getDeclaredName(Closure c) { | |
def clazz = c.class | |
def field = clazz.declaredFields.find {it.type == Reference.class} | |
if (field) { | |
return field.name | |
} else { | |
def method = clazz.declaredMethods.find {it.name =~ /getCallSiteArray/} | |
method.accessible = true | |
return method.invoke(null)[0].name | |
} | |
} | |
method {cls} | |
method {cls2} | |
method {new Hogehoge().cls} | |
method {Hogehoge.hogefuga} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment