CreateTypeParameterFromUsageFix: cleanup code
This commit is contained in:
+7
-14
@@ -70,8 +70,8 @@ class CreateTypeParameterFromUsageFix(
|
|||||||
ReferencesSearch
|
ReferencesSearch
|
||||||
.search(declaration)
|
.search(declaration)
|
||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
it.element.getParentOfTypeAndBranch<KtUserType> { referenceExpression } ?:
|
it.element.getParentOfTypeAndBranch<KtUserType> { referenceExpression }
|
||||||
it.element.getParentOfTypeAndBranch<KtCallElement> { calleeExpression }
|
?: it.element.getParentOfTypeAndBranch<KtCallElement> { calleeExpression }
|
||||||
}
|
}
|
||||||
.filter {
|
.filter {
|
||||||
val arguments = when (it) {
|
val arguments = when (it) {
|
||||||
@@ -94,8 +94,7 @@ class CreateTypeParameterFromUsageFix(
|
|||||||
val upperBoundType = typeParameter.upperBoundType
|
val upperBoundType = typeParameter.upperBoundType
|
||||||
val upperBoundText = if (upperBoundType != null && !upperBoundType.isNullableAny()) {
|
val upperBoundText = if (upperBoundType != null && !upperBoundType.isNullableAny()) {
|
||||||
IdeDescriptorRenderers.SOURCE_CODE.renderType(upperBoundType)
|
IdeDescriptorRenderers.SOURCE_CODE.renderType(upperBoundType)
|
||||||
}
|
} else null
|
||||||
else null
|
|
||||||
val upperBound = upperBoundText?.let { psiFactory.createType(it) }
|
val upperBound = upperBoundText?.let { psiFactory.createType(it) }
|
||||||
val newTypeParameterText = if (upperBound != null) "${typeParameter.name} : ${upperBound.text}" else typeParameter.name
|
val newTypeParameterText = if (upperBound != null) "${typeParameter.name} : ${upperBound.text}" else typeParameter.name
|
||||||
val newTypeParameter = declaration.addTypeParameter(psiFactory.createTypeParameter(newTypeParameterText))!!
|
val newTypeParameter = declaration.addTypeParameter(psiFactory.createTypeParameter(newTypeParameterText))!!
|
||||||
@@ -117,19 +116,14 @@ class CreateTypeParameterFromUsageFix(
|
|||||||
when (it) {
|
when (it) {
|
||||||
is KtUserType -> {
|
is KtUserType -> {
|
||||||
val typeArgumentList = it.typeArgumentList
|
val typeArgumentList = it.typeArgumentList
|
||||||
elementsToShorten += if (typeArgumentList != null) {
|
elementsToShorten += typeArgumentList?.addArgument(anonymizedUpperBoundAsTypeArg) ?: it.addAfter(
|
||||||
typeArgumentList.addArgument(anonymizedUpperBoundAsTypeArg)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
it.addAfter(
|
|
||||||
psiFactory.createTypeArguments("<${anonymizedUpperBoundAsTypeArg.text}>"),
|
psiFactory.createTypeArguments("<${anonymizedUpperBoundAsTypeArg.text}>"),
|
||||||
it.referenceExpression!!
|
it.referenceExpression!!
|
||||||
) as KtTypeArgumentList
|
) as KtTypeArgumentList
|
||||||
}
|
}
|
||||||
}
|
|
||||||
is KtCallElement -> {
|
is KtCallElement -> {
|
||||||
if (it.analyze(BodyResolveMode.PARTIAL_WITH_DIAGNOSTICS).diagnostics.forElement(it.calleeExpression!!).any {
|
if (it.analyze(BodyResolveMode.PARTIAL_WITH_DIAGNOSTICS).diagnostics.forElement(it.calleeExpression!!).any { diagnostic ->
|
||||||
it.factory in Errors.TYPE_INFERENCE_ERRORS
|
diagnostic.factory in Errors.TYPE_INFERENCE_ERRORS
|
||||||
}) {
|
}) {
|
||||||
callsToExplicateArguments += it
|
callsToExplicateArguments += it
|
||||||
}
|
}
|
||||||
@@ -148,8 +142,7 @@ class CreateTypeParameterFromUsageFix(
|
|||||||
}
|
}
|
||||||
|
|
||||||
it.typeArgumentList
|
it.typeArgumentList
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
typeArgumentList.addArgument(anonymizedUpperBoundAsTypeArg)
|
typeArgumentList.addArgument(anonymizedUpperBoundAsTypeArg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user