Reformat CreateTypeParameterByUnresolvedRefActionFactory
This commit is contained in:
committed by
Dmitry Gridin
parent
5b666ff33f
commit
68609401c4
+18
-18
@@ -38,14 +38,14 @@ import org.jetbrains.kotlin.types.Variance
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.containsError
|
import org.jetbrains.kotlin.types.typeUtil.containsError
|
||||||
|
|
||||||
data class TypeParameterInfo(
|
data class TypeParameterInfo(
|
||||||
val name: String,
|
val name: String,
|
||||||
val upperBoundType: KotlinType?,
|
val upperBoundType: KotlinType?,
|
||||||
val fakeTypeParameter: TypeParameterDescriptor
|
val fakeTypeParameter: TypeParameterDescriptor
|
||||||
)
|
)
|
||||||
|
|
||||||
data class CreateTypeParameterData(
|
data class CreateTypeParameterData(
|
||||||
val declaration: KtTypeParameterListOwner,
|
val declaration: KtTypeParameterListOwner,
|
||||||
val typeParameters: List<TypeParameterInfo>
|
val typeParameters: List<TypeParameterInfo>
|
||||||
)
|
)
|
||||||
|
|
||||||
object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFactoryWithDelegate<KtUserType, CreateTypeParameterData>() {
|
object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFactoryWithDelegate<KtUserType, CreateTypeParameterData>() {
|
||||||
@@ -77,9 +77,9 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createFixes(
|
override fun createFixes(
|
||||||
originalElementPointer: SmartPsiElementPointer<KtUserType>,
|
originalElementPointer: SmartPsiElementPointer<KtUserType>,
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
quickFixDataFactory: () -> CreateTypeParameterData?
|
quickFixDataFactory: () -> CreateTypeParameterData?
|
||||||
): List<QuickFixWithDelegateFactory> {
|
): List<QuickFixWithDelegateFactory> {
|
||||||
val ktUserType = originalElementPointer.element ?: return emptyList()
|
val ktUserType = originalElementPointer.element ?: return emptyList()
|
||||||
val name = ktUserType.referencedName ?: return emptyList()
|
val name = ktUserType.referencedName ?: return emptyList()
|
||||||
@@ -87,7 +87,7 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
|
|||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { it.typeParameters.all { it.name != name } }
|
.filter { it.typeParameters.all { it.name != name } }
|
||||||
.map {
|
.map {
|
||||||
QuickFixWithDelegateFactory factory@ {
|
QuickFixWithDelegateFactory factory@{
|
||||||
val originalElement = originalElementPointer.element ?: return@factory null
|
val originalElement = originalElementPointer.element ?: return@factory null
|
||||||
val data = quickFixDataFactory()?.copy(declaration = it) ?: return@factory null
|
val data = quickFixDataFactory()?.copy(declaration = it) ?: return@factory null
|
||||||
CreateTypeParameterFromUsageFix(originalElement, data, presentTypeParameterNames = true)
|
CreateTypeParameterFromUsageFix(originalElement, data, presentTypeParameterNames = true)
|
||||||
@@ -99,18 +99,18 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
|
|||||||
|
|
||||||
fun createFakeTypeParameterDescriptor(containingDescriptor: DeclarationDescriptor, name: String): TypeParameterDescriptor {
|
fun createFakeTypeParameterDescriptor(containingDescriptor: DeclarationDescriptor, name: String): TypeParameterDescriptor {
|
||||||
return TypeParameterDescriptorImpl
|
return TypeParameterDescriptorImpl
|
||||||
.createWithDefaultBound(containingDescriptor, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier(name), -1)
|
.createWithDefaultBound(containingDescriptor, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier(name), -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPossibleTypeParameterContainers(startFrom: PsiElement): List<KtTypeParameterListOwner> {
|
fun getPossibleTypeParameterContainers(startFrom: PsiElement): List<KtTypeParameterListOwner> {
|
||||||
val stopAt = startFrom.parents.firstOrNull(::isObjectOrNonInnerClass)?.parent
|
val stopAt = startFrom.parents.firstOrNull(::isObjectOrNonInnerClass)?.parent
|
||||||
return (if (stopAt != null) startFrom.parents.takeWhile { it != stopAt } else startFrom.parents)
|
return (if (stopAt != null) startFrom.parents.takeWhile { it != stopAt } else startFrom.parents)
|
||||||
.filterIsInstance<KtTypeParameterListOwner>()
|
.filterIsInstance<KtTypeParameterListOwner>()
|
||||||
.filter {
|
.filter {
|
||||||
((it is KtClass && !it.isInterface() && it !is KtEnumEntry) ||
|
((it is KtClass && !it.isInterface() && it !is KtEnumEntry) ||
|
||||||
it is KtNamedFunction ||
|
it is KtNamedFunction ||
|
||||||
(it is KtProperty && !it.isLocal) ||
|
(it is KtProperty && !it.isLocal) ||
|
||||||
it is KtTypeAlias) && it.nameIdentifier != null
|
it is KtTypeAlias) && it.nameIdentifier != null
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user