Supported obtaining function type parameter names from KotlinType
This commit is contained in:
@@ -20,7 +20,9 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
object KotlinTypeFactory {
|
||||
private fun computeMemberScope(constructor: TypeConstructor, arguments: List<TypeProjection>): MemberScope {
|
||||
@@ -49,6 +51,14 @@ object KotlinTypeFactory {
|
||||
arguments: List<TypeProjection>
|
||||
): SimpleType = SimpleTypeImpl(annotations, descriptor.typeConstructor, arguments, false, descriptor.getMemberScope(arguments))
|
||||
|
||||
@JvmStatic
|
||||
fun functionType(
|
||||
annotations: Annotations,
|
||||
descriptor: ClassDescriptor,
|
||||
arguments: List<TypeProjection>,
|
||||
parameterNames: List<Name>
|
||||
): FunctionType = FunctionType(simpleNotNullType(annotations, descriptor, arguments), parameterNames)
|
||||
|
||||
@JvmStatic
|
||||
fun simpleType(
|
||||
baseType: SimpleType,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
@@ -42,13 +43,31 @@ class AbbreviatedType(override val delegate: SimpleType, val abbreviation: Simpl
|
||||
override val isError: Boolean get() = false
|
||||
}
|
||||
|
||||
fun KotlinType.getAbbreviatedType(): AbbreviatedType? = (unwrap() as? AbbreviatedType)
|
||||
fun KotlinType.getAbbreviatedType(): AbbreviatedType? = unwrap() as? AbbreviatedType
|
||||
|
||||
fun SimpleType.withAbbreviation(abbreviatedType: SimpleType): SimpleType {
|
||||
if (isError) return this
|
||||
return AbbreviatedType(this, abbreviatedType)
|
||||
}
|
||||
|
||||
class FunctionType(
|
||||
override val delegate: SimpleType,
|
||||
/**
|
||||
* SpecialNames.NO_NAME_PROVIDED if no parameter name specified
|
||||
*/
|
||||
val parameterNames: List<Name>
|
||||
) : DelegatingSimpleType() {
|
||||
override fun replaceAnnotations(newAnnotations: Annotations)
|
||||
= FunctionType(delegate.replaceAnnotations(newAnnotations), parameterNames)
|
||||
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean)
|
||||
= FunctionType(delegate.makeNullableAsSpecified(newNullability), parameterNames)
|
||||
|
||||
override val isError: Boolean get() = false
|
||||
}
|
||||
|
||||
fun KotlinType.getFunctionTypeParameterNames(): List<Name>? = (unwrap() as? FunctionType)?.parameterNames
|
||||
|
||||
class LazyWrappedType(storageManager: StorageManager, computation: () -> KotlinType): WrappedType() {
|
||||
private val lazyValue = storageManager.createLazyValue(computation)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user