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