Put parameters on line: don't suggest if parameters has end-of-line comments

#KT-35214 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-02 19:06:05 +09:00
committed by igoriakovlev
parent efa981db36
commit 89cc5777ce
4 changed files with 30 additions and 1 deletions
@@ -6,10 +6,13 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.codeStyle.CodeStyleManager
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
@@ -22,7 +25,8 @@ abstract class AbstractJoinListIntention<TList : KtElement, TElement : KtElement
override fun isApplicableTo(element: TList): Boolean {
val elements = element.elements()
if (elements.isEmpty()) return false
return hasLineBreakBefore(elements.first()) || elements.any { hasLineBreakAfter(it) }
return (hasLineBreakBefore(elements.first()) || elements.any { hasLineBreakAfter(it) })
&& element.allChildren.none { it is PsiComment && it.node.elementType == KtTokens.EOL_COMMENT }
}
override fun applyTo(element: TList, editor: Editor?) {
@@ -0,0 +1,10 @@
// IS_APPLICABLE: false
fun foo(
a: Int, // comment
b: Int
) = 1
val x = foo(
<caret>1, // comment
2
)
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
fun foo(
<caret>a: Int, // comment
b: Int
) = 1
@@ -10412,6 +10412,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/joinArgumentList"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("hasEndOfLineComment.kt")
public void testHasEndOfLineComment() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/hasEndOfLineComment.kt");
}
@TestMetadata("hasLineBreakBeforeFirstArg.kt")
public void testHasLineBreakBeforeFirstArg() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/hasLineBreakBeforeFirstArg.kt");
@@ -10613,6 +10618,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/joinParameterList"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("hasEndOfLineComment.kt")
public void testHasEndOfLineComment() throws Exception {
runTest("idea/testData/intentions/joinParameterList/hasEndOfLineComment.kt");
}
@TestMetadata("hasLineBreakBeforeFirstParam.kt")
public void testHasLineBreakBeforeFirstParam() throws Exception {
runTest("idea/testData/intentions/joinParameterList/hasLineBreakBeforeFirstParam.kt");