KT-9839 related, primary constructor to secondary: comment restoration
(cherry picked from commit 48a1853)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
d1958be2a8
commit
3508bea391
+5
-1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.util.CommentSaver
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.THIS_KEYWORD
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.VARARG_KEYWORD
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -58,6 +59,7 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
||||
val klass = element.containingClassOrObject as? KtClass ?: return
|
||||
val context = klass.analyze()
|
||||
val factory = KtPsiFactory(klass)
|
||||
val commentSaver = CommentSaver(element)
|
||||
val initializerMap = mutableMapOf<KtProperty, String>()
|
||||
for (property in klass.getProperties()) {
|
||||
if (property.typeReference == null) {
|
||||
@@ -116,7 +118,9 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
||||
}
|
||||
}.asString()
|
||||
)
|
||||
klass.addDeclarationBefore(constructor, null)
|
||||
with (klass.addDeclarationBefore(constructor, null)) {
|
||||
commentSaver.restore(this)
|
||||
}
|
||||
for (valueParameter in element.valueParameters.reversed()) {
|
||||
if (!valueParameter.hasValOrVar()) continue
|
||||
val isVararg = valueParameter.hasModifier(VARARG_KEYWORD)
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* An important class
|
||||
*/
|
||||
class WithComments
|
||||
/**
|
||||
* Some nasty constructor
|
||||
*/
|
||||
<caret>constructor(
|
||||
/* First parameter */
|
||||
val first: Int,
|
||||
/* Second Parameter */
|
||||
val second: Double)
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* An important class
|
||||
*/
|
||||
class WithComments
|
||||
/**
|
||||
* Some nasty constructor
|
||||
*/
|
||||
{/* First parameter */
|
||||
/* Second Parameter */
|
||||
val first: Int
|
||||
val second: Double
|
||||
|
||||
constructor(first: Int, second: Double) {
|
||||
this.first = first
|
||||
this.second = second
|
||||
}
|
||||
}
|
||||
@@ -4462,6 +4462,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withComments.kt")
|
||||
public void testWithComments() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/withComments.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withMultipleInheritance.kt")
|
||||
public void testWithMultipleInheritance() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/withMultipleInheritance.kt");
|
||||
|
||||
Reference in New Issue
Block a user