Use CodegenContext to determine outer class & enclosing method

This commit is contained in:
Alexander Udalov
2015-02-11 00:38:44 +03:00
parent c417d984c4
commit 9b28e19551
8 changed files with 239 additions and 156 deletions
@@ -0,0 +1,25 @@
class O {
class object {
// Currently we consider <clinit> in class O as the enclosing method of this lambda,
// so we write outer class = O and enclosing method = null
val f = {}
}
}
fun box(): String {
val javaClass = O.f.javaClass
val enclosingMethod = javaClass.getEnclosingMethod()
if (enclosingMethod != null) return "method: $enclosingMethod"
val enclosingConstructor = javaClass.getEnclosingConstructor()
if (enclosingConstructor != null) return "constructor: $enclosingConstructor"
val enclosingClass = javaClass.getEnclosingClass()
if (enclosingClass?.getName() != "O") return "enclosing class: $enclosingClass"
val declaringClass = javaClass.getDeclaringClass()
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
return "OK"
}