Move to class body: don't suggest on data class
#KT-40558 Fixed
This commit is contained in:
committed by
igoriakovlev
parent
28700ed64c
commit
5e91ffb156
@@ -13,18 +13,21 @@ import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter
|
||||
import org.jetbrains.kotlin.resolve.AnnotationChecker
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
|
||||
class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(
|
||||
KtParameter::class.java,
|
||||
KotlinBundle.lazyMessage("move.to.class.body")
|
||||
) {
|
||||
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean =
|
||||
element.isPropertyParameter() && (element.ownerFunction as KtPrimaryConstructor).isNotContainedInAnnotation()
|
||||
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
||||
if (!element.isPropertyParameter()) return false
|
||||
val containingClass = element.containingClass() ?: return false
|
||||
return !containingClass.isAnnotation() && !containingClass.isData()
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtParameter, editor: Editor?) {
|
||||
val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return
|
||||
@@ -94,6 +97,4 @@ class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(
|
||||
nextSibling?.delete() // ':' symbol after use site
|
||||
delete()
|
||||
}
|
||||
|
||||
private fun KtPrimaryConstructor.isNotContainedInAnnotation() = !getContainingClassOrObject().isAnnotation()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// IS_APPLICABLE: false
|
||||
annotation class TestClass(val <caret>text: String)
|
||||
@@ -0,0 +1,2 @@
|
||||
// IS_APPLICABLE: false
|
||||
data class TestClass(val <caret>text: String)
|
||||
@@ -12510,11 +12510,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/movePropertyToClassBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotationClass.kt")
|
||||
public void testAnnotationClass() throws Exception {
|
||||
runTest("idea/testData/intentions/movePropertyToClassBody/annotationClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("annotationWithUseSite.kt")
|
||||
public void testAnnotationWithUseSite() throws Exception {
|
||||
runTest("idea/testData/intentions/movePropertyToClassBody/annotationWithUseSite.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dataClass.kt")
|
||||
public void testDataClass() throws Exception {
|
||||
runTest("idea/testData/intentions/movePropertyToClassBody/dataClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("location1.kt")
|
||||
public void testLocation1() throws Exception {
|
||||
runTest("idea/testData/intentions/movePropertyToClassBody/location1.kt");
|
||||
|
||||
Reference in New Issue
Block a user