Reflection: add API for declaration modifiers

#KT-10447 Fixed
This commit is contained in:
Alexander Udalov
2016-07-12 19:06:00 +03:00
parent ada81923dc
commit 7e317f7a7c
24 changed files with 681 additions and 1 deletions
@@ -62,4 +62,19 @@ public interface KCallable<out R> : KAnnotatedElement {
* or its type does not match the type of the provided value, an exception is thrown.
*/
public fun callBy(args: Map<KParameter, Any?>): R
/**
* `true` if this callable is `final`.
*/
public val isFinal: Boolean
/**
* `true` if this callable is `open`.
*/
public val isOpen: Boolean
/**
* `true` if this callable is `abstract`.
*/
public val isAbstract: Boolean
}
@@ -73,6 +73,49 @@ public interface KClass<T : Any> : KDeclarationContainer, KAnnotatedElement, KCl
*/
public val supertypes: List<KType>
/**
* `true` if this class is `final`.
*/
public val isFinal: Boolean
/**
* `true` if this class is `open`.
*/
public val isOpen: Boolean
/**
* `true` if this class is `abstract`.
*/
public val isAbstract: Boolean
/**
* `true` if this class is `sealed`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/classes.html#sealed-classes)
* for more information.
*/
public val isSealed: Boolean
/**
* `true` if this class is a data class.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/data-classes.html)
* for more information.
*/
public val isData: Boolean
/**
* `true` if this class is an inner class.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/nested-classes.html#inner-classes)
* for more information.
*/
public val isInner: Boolean
/**
* `true` if this class is a companion object.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects)
* for more information.
*/
public val isCompanion: Boolean
/**
* Returns `true` if [other] is a [KClass] instance representing the same class on a given platform.
*
+41 -1
View File
@@ -19,4 +19,44 @@ package kotlin.reflect
/**
* Represents a function with introspection capabilities.
*/
public interface KFunction<out R> : KCallable<R>, Function<R>
public interface KFunction<out R> : KCallable<R>, Function<R> {
/**
* `true` if this function is `inline`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/inline-functions.html)
* for more information.
*/
public val isInline: Boolean
/**
* `true` if this function is `external`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/java-interop.html#using-jni-with-kotlin)
* for more information.
*/
public val isExternal: Boolean
/**
* `true` if this function is `operator`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/operator-overloading.html)
* for more information.
*/
public val isOperator: Boolean
/**
* `true` if this function is `infix`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/functions.html#infix-notation)
* for more information.
*/
public val isInfix: Boolean
/**
* `true` if this function is `tailrec`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/functions.html#tail-recursive-functions)
* for more information.
*/
public val isTailrec: Boolean
/**
* `true` if this is a suspending function.
*/
public val isSuspend: Boolean
}
@@ -69,4 +69,30 @@ public interface KParameter : KAnnotatedElement {
* 2. The parameter is declared in a member function and one of the corresponding parameters in the super functions is optional.
*/
public val isOptional: Boolean
/**
* `true` if this parameter is `vararg`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/functions.html#variable-number-of-arguments-varargs)
* for more information.
*/
public val isVararg: Boolean
/**
* `true` if this parameter is `noinline`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/inline-functions.html#noinline)
* for more information.
*/
public val isNoinline: Boolean
/**
* `true` if this parameter is `crossinline`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/inline-functions.html#non-local-returns)
* for more information.
*/
public val isCrossinline: Boolean
/**
* `true` if this parameter is `coroutine`.
*/
public val isCoroutine: Boolean
}
@@ -25,6 +25,20 @@ package kotlin.reflect
* @param R the type of the property.
*/
public interface KProperty<out R> : KCallable<R> {
/**
* `true` if this property is `lateinit`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#late-initialized-properties)
* for more information.
*/
public val isLateinit: Boolean
/**
* `true` if this property is `const`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#compile-time-constants)
* for more information.
*/
public val isConst: Boolean
/** The getter of this property, used to obtain the value of the property. */
public val getter: Getter<R>
@@ -40,4 +40,11 @@ public interface KTypeParameter : KClassifier {
* for more information.
*/
public val variance: KVariance
/**
* `true` if this type parameter is `reified`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/inline-functions.html#reified-type-parameters)
* for more information.
*/
public val isReified: Boolean
}