Extract Superclass/Interface: Allow extracting class with special name (and quotes)

#KT-15353 Fixed
This commit is contained in:
Alexey Sedunov
2017-01-11 12:25:28 +03:00
parent 5de4e9fdac
commit 52e9117e9d
8 changed files with 55 additions and 6 deletions
+1
View File
@@ -476,6 +476,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-12704`](https://youtrack.jetbrains.com/issue/KT-12704), [`KT-15583`](https://youtrack.jetbrains.com/issue/KT-15583) Override/Implement Members: Support all nullability annotations respected by the Kotlin compiler
- [`KT-15563`](https://youtrack.jetbrains.com/issue/KT-15563) Override Members: Allow overriding virtual synthetic members (e.g. equals(), hashCode(), toString(), etc.) in data classes
- [`KT-15355`](https://youtrack.jetbrains.com/issue/KT-15355) Extract Interface: Disable "Make abstract" and assume it to be true for abstract members of an interface
- [`KT-15353`](https://youtrack.jetbrains.com/issue/KT-15353) Extract Superclass/Interface: Allow extracting class with special name (and quotes)
#### Intention actions, inspections and quickfixes
@@ -37,10 +37,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.codeInsight.shorten.performDelayedShortening
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.copied
import org.jetbrains.kotlin.idea.core.getPackage
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.refactoring.introduce.insertDeclaration
import org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberInfo
import org.jetbrains.kotlin.idea.refactoring.memberInfo.getChildrenToAnalyze
@@ -206,7 +203,7 @@ class ExtractSuperRefactoring(
private fun createClass(superClassEntry: KtSuperTypeListEntry?): KtClass {
val targetParent = extractInfo.targetParent
val newClassName = extractInfo.newClassName
val newClassName = extractInfo.newClassName.quoteIfNeeded()
val originalClass = extractInfo.originalClass
val kind = if (extractInfo.isInterface) "interface" else "class"
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren
@@ -113,7 +114,7 @@ fun applyMarking(
substitutor: TypeSubstitutor, targetClassDescriptor: ClassDescriptor
) {
val psiFactory = KtPsiFactory(declaration)
val targetThis = psiFactory.createExpression("this@${targetClassDescriptor.name.asString()}")
val targetThis = psiFactory.createExpression("this@${targetClassDescriptor.name.asString().quoteIfNeeded()}")
val shorteningOptionsForThis = ShortenReferences.Options(removeThisLabels = true, removeThis = true)
declaration.accept(
@@ -0,0 +1,8 @@
// NAME: class
// SIBLING:
class <caret>A {
// INFO: {checked: "true"}
fun foo() {
}
}
@@ -0,0 +1,11 @@
interface `class` {
// INFO: {checked: "true"}
fun foo() {
}
}
// NAME: class
// SIBLING:
class A : `class` {
}
@@ -0,0 +1,8 @@
// NAME: class
// SIBLING:
class <caret>A {
// INFO: {checked: "true"}
fun foo() {
}
}
@@ -0,0 +1,11 @@
open class `class` {
// INFO: {checked: "true"}
fun foo() {
}
}
// NAME: class
// SIBLING:
class A : `class`() {
}
@@ -4312,6 +4312,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractSuperclass/replaceSuperclass.kt");
doExtractSuperclassTest(fileName);
}
@TestMetadata("specialName.kt")
public void testSpecialName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractSuperclass/specialName.kt");
doExtractSuperclassTest(fileName);
}
}
@TestMetadata("idea/testData/refactoring/extractInterface")
@@ -4351,5 +4357,11 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractInterface/annotation.kt");
doExtractInterfaceTest(fileName);
}
@TestMetadata("specialName.kt")
public void testSpecialName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractInterface/specialName.kt");
doExtractInterfaceTest(fileName);
}
}
}