Create from Usage: Implement "Create type alias" quickfix
#KT-12904 Fixed
This commit is contained in:
@@ -106,9 +106,12 @@ class KtPsiFactory(private val project: Project) {
|
||||
}
|
||||
|
||||
fun createTypeAlias(name: String, typeParameters: List<String>, typeElement: KtTypeElement): KtTypeAlias {
|
||||
return createTypeAlias(name, typeParameters, "X").apply { getTypeReference()!!.replace(createType(typeElement)) }
|
||||
}
|
||||
|
||||
fun createTypeAlias(name: String, typeParameters: List<String>, body: String): KtTypeAlias {
|
||||
val typeParametersText = if (typeParameters.isNotEmpty()) typeParameters.joinToString(prefix = "<", postfix = ">") else ""
|
||||
return createDeclaration<KtTypeAlias>("typealias $name$typeParametersText = X")
|
||||
.apply { getTypeReference()!!.replace(createType(typeElement)) }
|
||||
return createDeclaration<KtTypeAlias>("typealias $name$typeParametersText = $body")
|
||||
}
|
||||
|
||||
fun createStar(): PsiElement {
|
||||
|
||||
@@ -95,4 +95,7 @@ fun KtExpression.isUnreachableCode(context: BindingContext): Boolean = context[B
|
||||
fun KtExpression.getReferenceTargets(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val targetDescriptor = if (this is KtReferenceExpression) context[BindingContext.REFERENCE_TARGET, this] else null
|
||||
return targetDescriptor?.let { listOf(it) } ?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this].orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
fun KtTypeReference.getAbbreviatedTypeOrType(context: BindingContext) =
|
||||
context[BindingContext.ABBREVIATED_TYPE, this] ?: context[BindingContext.TYPE, this]
|
||||
Reference in New Issue
Block a user