KT-14391 RemoveUnnecessaryParenthesesIntention lost comment

on closing parenthesis

 ^KT-14391 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-05-07 10:40:28 +03:00
committed by Natalia Selezneva
parent 143c3ccb95
commit 534cbae4ef
4 changed files with 16 additions and 1 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.psi.KtParenthesizedExpression
import org.jetbrains.kotlin.psi.KtPsiUtil
@@ -29,6 +30,8 @@ class RemoveUnnecessaryParenthesesIntention : SelfTargetingRangeIntention<KtPare
}
override fun applyTo(element: KtParenthesizedExpression, editor: Editor?) {
element.replace(element.expression!!)
val commentSaver = CommentSaver(element)
val replaced = element.replace(element.expression!!)
commentSaver.restore(replaced)
}
}
@@ -0,0 +1,3 @@
fun foo(x: Int): Int {
return <caret>(/* aaa */ x /* bbb */)/* ccc */
}
@@ -0,0 +1,3 @@
fun foo(x: Int): Int {
return /* aaa */ x /* bbb *//* ccc */
}
@@ -13075,6 +13075,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
public void testUnnecessaryParentheses8() throws Exception {
runTest("idea/testData/intentions/removeUnnecessaryParentheses/unnecessaryParentheses8.kt");
}
@TestMetadata("unnecessaryParenthesesWithComment.kt")
public void testUnnecessaryParenthesesWithComment() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/unnecessaryParenthesesWithComment.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/replaceAddWithPlusAssign")