Support KClass.primaryConstructor

This commit is contained in:
Alexander Udalov
2015-07-23 19:06:00 +03:00
parent 699a801ce9
commit 7fc499df46
3 changed files with 70 additions and 0 deletions
@@ -16,7 +16,19 @@
package kotlin.reflect
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import kotlin.reflect.jvm.internal.KClassImpl
import kotlin.reflect.jvm.internal.KFunctionImpl
/**
* Returns the primary constructor of this class, or `null` if this class has no primary constructor.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/classes.html#constructors)
* for more information.
*/
public val <T : Any> KClass<T>.primaryConstructor: KFunction<T>?
get() = (this as KClassImpl<T>).constructors.firstOrNull {
((it as KFunctionImpl).descriptor as ConstructorDescriptor).isPrimary
}
/**
* Returns all functions declared in this class.