Minor: reformat CreateTypeParameterUnmatchedTypeArgumentActionFactory
This commit is contained in:
+18
-18
@@ -35,48 +35,48 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||
|
||||
object CreateTypeParameterUnmatchedTypeArgumentActionFactory : KotlinIntentionActionFactoryWithDelegate<KtTypeArgumentList, CreateTypeParameterData>() {
|
||||
object CreateTypeParameterUnmatchedTypeArgumentActionFactory :
|
||||
KotlinIntentionActionFactoryWithDelegate<KtTypeArgumentList, CreateTypeParameterData>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic) = diagnostic.psiElement as? KtTypeArgumentList
|
||||
|
||||
override fun extractFixData(element: KtTypeArgumentList, diagnostic: Diagnostic): CreateTypeParameterData? {
|
||||
val project = element.project
|
||||
val typeArguments = element.arguments
|
||||
val context = element.analyze()
|
||||
val parent = element.parent
|
||||
val referencedDescriptor = when (parent) {
|
||||
val referencedDescriptor = when (val parent = element.parent) {
|
||||
is KtUserType -> context[BindingContext.REFERENCE_TARGET, parent.referenceExpression]
|
||||
is KtCallElement -> parent.getResolvedCall(context)?.resultingDescriptor
|
||||
else -> null
|
||||
} ?: return null
|
||||
val referencedDeclaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, referencedDescriptor) as? KtTypeParameterListOwner
|
||||
?: return null
|
||||
?: return null
|
||||
|
||||
val missingParameterCount = typeArguments.size - referencedDeclaration.typeParameters.size
|
||||
if (missingParameterCount <= 0) return null
|
||||
|
||||
val scope = referencedDeclaration.getResolutionScope()
|
||||
val suggestedNames = KotlinNameSuggester.suggestNamesForTypeParameters(
|
||||
missingParameterCount,
|
||||
CollectingNameValidator(referencedDeclaration.typeParameters.mapNotNull { it.name }) {
|
||||
scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null
|
||||
}
|
||||
missingParameterCount,
|
||||
CollectingNameValidator(referencedDeclaration.typeParameters.mapNotNull { it.name }) {
|
||||
scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null
|
||||
}
|
||||
)
|
||||
val typeParameterInfos = suggestedNames.map { name ->
|
||||
TypeParameterInfo(
|
||||
name,
|
||||
null,
|
||||
createFakeTypeParameterDescriptor(referencedDescriptor, name)
|
||||
)
|
||||
}
|
||||
TypeParameterInfo(
|
||||
name,
|
||||
null,
|
||||
createFakeTypeParameterDescriptor(referencedDescriptor, name)
|
||||
)
|
||||
}
|
||||
return CreateTypeParameterData(referencedDeclaration, typeParameterInfos)
|
||||
}
|
||||
|
||||
override fun createFixes(
|
||||
originalElementPointer: SmartPsiElementPointer<KtTypeArgumentList>,
|
||||
diagnostic: Diagnostic,
|
||||
quickFixDataFactory: () -> CreateTypeParameterData?
|
||||
originalElementPointer: SmartPsiElementPointer<KtTypeArgumentList>,
|
||||
diagnostic: Diagnostic,
|
||||
quickFixDataFactory: () -> CreateTypeParameterData?
|
||||
): List<QuickFixWithDelegateFactory> {
|
||||
return QuickFixWithDelegateFactory factory@ {
|
||||
return QuickFixWithDelegateFactory factory@{
|
||||
val originalElement = originalElementPointer.element ?: return@factory null
|
||||
val data = quickFixDataFactory() ?: return@factory null
|
||||
if (!data.declaration.isWritable) return@factory null
|
||||
|
||||
Reference in New Issue
Block a user