Revert ""Put/Join arguments/parameters" intention: don't suggest on nested argument list"

This reverts commit 4a328981
This commit is contained in:
Yan Zhulanow
2020-10-24 00:21:54 +09:00
parent 3321ce6325
commit 04457e92d0
17 changed files with 11 additions and 237 deletions
@@ -8,33 +8,31 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.application.options.CodeStyle import com.intellij.application.options.CodeStyle
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.inspections.findExistingEditor
import org.jetbrains.kotlin.idea.formatter.kotlinCommonSettings import org.jetbrains.kotlin.idea.formatter.kotlinCommonSettings
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.psi.psiUtil.allChildren
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.psi.psiUtil.startOffset
abstract class AbstractChopListIntention<TList : KtElement, TElement : KtElement>( abstract class AbstractChopListIntention<TList : KtElement, TElement : KtElement>(
listClass: Class<TList>, listClass: Class<TList>,
private val elementClass: Class<TElement>, private val elementClass: Class<TElement>,
textGetter: () -> String textGetter: () -> String
) : SelfTargetingIntention<TList>(listClass, textGetter) { ) : SelfTargetingOffsetIndependentIntention<TList>(listClass, textGetter) {
override fun allowCaretInsideElement(element: PsiElement) =
element !is KtValueArgument && super.allowCaretInsideElement(element)
open fun leftParOnNewLine(commonCodeStyleSettings: CommonCodeStyleSettings): Boolean = false open fun leftParOnNewLine(commonCodeStyleSettings: CommonCodeStyleSettings): Boolean = false
open fun rightParOnNewLine(commonCodeStyleSettings: CommonCodeStyleSettings): Boolean = false open fun rightParOnNewLine(commonCodeStyleSettings: CommonCodeStyleSettings): Boolean = false
override fun isApplicableTo(element: TList, caretOffset: Int): Boolean { override fun isApplicableTo(element: TList): Boolean {
val elements = element.elements() val elements = element.elements()
if (elements.size <= 1) return false if (elements.size <= 1) return false
if (!isApplicableCaretOffset(caretOffset, element)) return false
if (elements.dropLast(1).all { hasLineBreakAfter(it) }) return false if (elements.dropLast(1).all { hasLineBreakAfter(it) }) return false
return true return true
} }
@@ -84,12 +82,6 @@ abstract class AbstractChopListIntention<TList : KtElement, TElement : KtElement
it as TElement it as TElement
} }
.toList() .toList()
protected fun isApplicableCaretOffset(caretOffset: Int, element: TList): Boolean {
val elementBeforeCaret = element.containingFile.findElementAt(caretOffset - 1) ?: return true
if (elementBeforeCaret.node.elementType != KtTokens.RPAR) return true
return elementBeforeCaret.parent == element
}
} }
class ChopParameterListIntention : AbstractChopListIntention<KtParameterList, KtParameter>( class ChopParameterListIntention : AbstractChopListIntention<KtParameterList, KtParameter>(
@@ -97,9 +89,9 @@ class ChopParameterListIntention : AbstractChopListIntention<KtParameterList, Kt
KtParameter::class.java, KtParameter::class.java,
KotlinBundle.lazyMessage("put.parameters.on.separate.lines") KotlinBundle.lazyMessage("put.parameters.on.separate.lines")
) { ) {
override fun isApplicableTo(element: KtParameterList, caretOffset: Int): Boolean { override fun isApplicableTo(element: KtParameterList): Boolean {
if (element.parent is KtFunctionLiteral) return false if (element.parent is KtFunctionLiteral) return false
return super.isApplicableTo(element, caretOffset) return super.isApplicableTo(element)
} }
override fun leftParOnNewLine(commonCodeStyleSettings: CommonCodeStyleSettings): Boolean { override fun leftParOnNewLine(commonCodeStyleSettings: CommonCodeStyleSettings): Boolean {
@@ -22,10 +22,9 @@ abstract class AbstractJoinListIntention<TList : KtElement, TElement : KtElement
elementClass: Class<TElement>, elementClass: Class<TElement>,
textGetter: () -> String textGetter: () -> String
) : AbstractChopListIntention<TList, TElement>(listClass, elementClass, textGetter) { ) : AbstractChopListIntention<TList, TElement>(listClass, elementClass, textGetter) {
override fun isApplicableTo(element: TList, caretOffset: Int): Boolean { override fun isApplicableTo(element: TList): Boolean {
val elements = element.elements() val elements = element.elements()
if (elements.isEmpty()) return false if (elements.isEmpty()) return false
if (!isApplicableCaretOffset(caretOffset, element)) 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 } && element.allChildren.none { it is PsiComment && it.node.elementType == KtTokens.EOL_COMMENT }
} }
@@ -54,9 +53,9 @@ class JoinParameterListIntention : AbstractJoinListIntention<KtParameterList, Kt
KtParameter::class.java, KtParameter::class.java,
KotlinBundle.lazyMessage("put.parameters.on.one.line") KotlinBundle.lazyMessage("put.parameters.on.one.line")
) { ) {
override fun isApplicableTo(element: KtParameterList, caretOffset: Int): Boolean { override fun isApplicableTo(element: KtParameterList): Boolean {
if (element.parent is KtFunctionLiteral) return false if (element.parent is KtFunctionLiteral) return false
return super.isApplicableTo(element, caretOffset) return super.isApplicableTo(element)
} }
} }
@@ -1,12 +0,0 @@
// IS_APPLICABLE: false
fun foo() {
f(1, 2, g(<caret>
3,
4,
5
), 3)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,12 +0,0 @@
// IS_APPLICABLE: false
fun foo() {
f(1, 2, g<caret>(
3,
4,
5
), 3)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,12 +0,0 @@
// IS_APPLICABLE: false
fun foo() {
f(1, 2, g(
3,
4,
5
)<caret>, 3)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,12 +0,0 @@
fun foo() {
f(
1,
2,
g(3, 4, 5)<caret>,
3
)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,16 +0,0 @@
fun foo() {
f(
1,
2,
g(
3,
4,
5
),
3
)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,11 +0,0 @@
fun foo() {
f(1, 2, g(
3,
4,
5
), 3)<caret>
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,16 +0,0 @@
fun foo() {
f(
1,
2,
g(
3,
4,
5
),
3
)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,13 +0,0 @@
// IS_APPLICABLE: false
fun foo() {
f(
1,
2,
g(<caret>3, 4, 5),
3
)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,13 +0,0 @@
// IS_APPLICABLE: false
fun foo() {
f(
1,
2,
g<caret>(3, 4, 5),
3
)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,13 +0,0 @@
// IS_APPLICABLE: false
fun foo() {
f(
1,
2,
g(3, 4, 5)<caret>,
3
)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,11 +0,0 @@
fun foo() {
f(1, 2, g(
3,
4,
5
)<caret>, 3)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,7 +0,0 @@
fun foo() {
f(1, 2, g(3, 4, 5), 3)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,12 +0,0 @@
fun foo() {
f(
1,
2,
g(3, 4, 5),
3
)<caret>
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -1,7 +0,0 @@
fun foo() {
f(1, 2, g(3, 4, 5), 3)
}
fun f(a: Int, b: Int, c: Int, d: Int): Int = 0
fun g(a: Int, b: Int, c: Int): Int = 0
@@ -3763,31 +3763,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/chop/argumentList"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/chop/argumentList"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
} }
@TestMetadata("onNestedArgumentList.kt")
public void testOnNestedArgumentList() throws Exception {
runTest("idea/testData/intentions/chop/argumentList/onNestedArgumentList.kt");
}
@TestMetadata("onNestedArgumentList2.kt")
public void testOnNestedArgumentList2() throws Exception {
runTest("idea/testData/intentions/chop/argumentList/onNestedArgumentList2.kt");
}
@TestMetadata("onNestedArgumentList3.kt")
public void testOnNestedArgumentList3() throws Exception {
runTest("idea/testData/intentions/chop/argumentList/onNestedArgumentList3.kt");
}
@TestMetadata("onNestedArgumentList4.kt")
public void testOnNestedArgumentList4() throws Exception {
runTest("idea/testData/intentions/chop/argumentList/onNestedArgumentList4.kt");
}
@TestMetadata("onRightParenthesis.kt")
public void testOnRightParenthesis() throws Exception {
runTest("idea/testData/intentions/chop/argumentList/onRightParenthesis.kt");
}
@TestMetadata("leftParOnSameLine.kt") @TestMetadata("leftParOnSameLine.kt")
public void testLeftParOnSameLine() throws Exception { public void testLeftParOnSameLine() throws Exception {
runTest("idea/testData/intentions/chop/argumentList/leftParOnSameLine.kt"); runTest("idea/testData/intentions/chop/argumentList/leftParOnSameLine.kt");
@@ -10693,31 +10668,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/joinArgumentList/noLineBreak.kt"); runTest("idea/testData/intentions/joinArgumentList/noLineBreak.kt");
} }
@TestMetadata("onNestedArgumentList.kt")
public void testOnNestedArgumentList() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/onNestedArgumentList.kt");
}
@TestMetadata("onNestedArgumentList2.kt")
public void testOnNestedArgumentList2() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/onNestedArgumentList2.kt");
}
@TestMetadata("onNestedArgumentList3.kt")
public void testOnNestedArgumentList3() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/onNestedArgumentList3.kt");
}
@TestMetadata("onNestedArgumentList4.kt")
public void testOnNestedArgumentList4() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/onNestedArgumentList4.kt");
}
@TestMetadata("onRightParenthesis.kt")
public void testOnRightParenthesis() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/onRightParenthesis.kt");
}
@TestMetadata("oneArg.kt") @TestMetadata("oneArg.kt")
public void testOneArg() throws Exception { public void testOneArg() throws Exception {
runTest("idea/testData/intentions/joinArgumentList/oneArg.kt"); runTest("idea/testData/intentions/joinArgumentList/oneArg.kt");