Replace JavaClass.innerClasses with innerClassNames

Also add a findInnerClass method that can find an inner class
by its name

This change helps to avoid loading all the inner class files
eagerly (that may be rather slow), while all the names are available
in InnerClass attribute
This commit is contained in:
Denis Zharkov
2017-04-13 13:11:09 +03:00
parent 5936424659
commit 506d7ab3d2
5 changed files with 27 additions and 13 deletions
@@ -31,7 +31,7 @@ class ReflectJavaClass(
override val modifiers: Int get() = klass.modifiers
override val innerClasses: List<ReflectJavaClass>
override val innerClassNames: List<Name>
get() = klass.declaredClasses
.asSequence()
.filterNot {
@@ -40,8 +40,13 @@ class ReflectJavaClass(
// nested class constructor accessed from the outer class
it.simpleName.isEmpty()
}
.map(::ReflectJavaClass)
.toList()
.mapNotNull { it.simpleName.takeIf(Name::isValidIdentifier)?.let(Name::identifier) }.toList()
override fun findInnerClass(name: Name) = klass.declaredClasses
.asSequence()
.firstOrNull {
it.simpleName == name.asString()
}?.let(::ReflectJavaClass)
override val fqName: FqName
get() = klass.classId.asSingleFqName()