"Create type parameter from usage": don't remove backticks if necessary

#KT-33299 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-09-20 18:00:18 +09:00
committed by Dmitry Gridin
parent bfc698a521
commit 5b666ff33f
4 changed files with 16 additions and 1 deletions
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.TypeProjectionImpl
import org.jetbrains.kotlin.types.TypeSubstitutor
@@ -96,7 +97,8 @@ class CreateTypeParameterFromUsageFix(
IdeDescriptorRenderers.SOURCE_CODE.renderType(upperBoundType)
} else null
val upperBound = upperBoundText?.let { psiFactory.createType(it) }
val newTypeParameterText = if (upperBound != null) "${typeParameter.name} : ${upperBound.text}" else typeParameter.name
val typeParameterName = typeParameter.name.quoteIfNeeded()
val newTypeParameterText = if (upperBound != null) "$typeParameterName : ${upperBound.text}" else typeParameterName
val newTypeParameter = declaration.addTypeParameter(psiFactory.createTypeParameter(newTypeParameterText))
?: error("Couldn't create type parameter from '$newTypeParameterText' for '$declaration'")
elementsToShorten += newTypeParameter
@@ -0,0 +1,4 @@
// "Create type parameter 'test text' in function 'a'" "true"
fun a() {
val c: `test text`<caret>
}
@@ -0,0 +1,4 @@
// "Create type parameter 'test text' in function 'a'" "true"
fun <`test text`> a() {
val c: `test text`
}
@@ -4698,6 +4698,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("backticks.kt")
public void testBackticks() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/backticks.kt");
}
@TestMetadata("classNoExplication.kt")
public void testClassNoExplication() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/classNoExplication.kt");