Create from Usage: Implement "Create type alias" quickfix

#KT-12904 Fixed
This commit is contained in:
Alexey Sedunov
2016-07-20 14:34:49 +03:00
parent 17edbac72b
commit 6a2edabbd4
50 changed files with 555 additions and 101 deletions
@@ -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]