Join declaration & assignment: do not suggest for non-first line of init / constructor #KT-15545 Fixed
This commit is contained in:
+5
-1
@@ -134,7 +134,11 @@ class JoinDeclarationAndAssignmentIntention : SelfTargetingOffsetIndependentInte
|
||||
|
||||
val first = assignments.firstOrNull() ?: return null
|
||||
if (assignments.any { it !== first && it.parent.parent is KtSecondaryConstructor}) return null
|
||||
return first
|
||||
|
||||
if (propertyContainer !is KtClassBody) return first
|
||||
|
||||
val blockParent = first.parent as? KtBlockExpression ?: return null
|
||||
return if (blockParent.statements.firstOrNull() == first) first else null
|
||||
}
|
||||
|
||||
// a block that only contains comments is not empty
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
class A
|
||||
|
||||
class AFabric {
|
||||
lateinit var instance: A
|
||||
fun init(config: Unit) {
|
||||
instance = A()
|
||||
}
|
||||
}
|
||||
|
||||
class V(fabric: AFabric) {
|
||||
val a: A<caret>
|
||||
init {
|
||||
val config = getConfig()
|
||||
fabric.init(config)
|
||||
a = fabric.instance
|
||||
}
|
||||
fun getConfig() = Unit
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
class A
|
||||
|
||||
class AFabric {
|
||||
lateinit var instance: A
|
||||
fun init(config: Unit) {
|
||||
instance = A()
|
||||
}
|
||||
}
|
||||
|
||||
val fabric = AFabric()
|
||||
|
||||
class V {
|
||||
val a: A<caret>
|
||||
|
||||
constructor() {
|
||||
val config = getConfig()
|
||||
fabric.init(config)
|
||||
a = fabric.instance
|
||||
}
|
||||
|
||||
fun getConfig() = Unit
|
||||
}
|
||||
@@ -8922,6 +8922,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notFirstInitLine.kt")
|
||||
public void testNotFirstInitLine() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/joinDeclarationAndAssignment/notFirstInitLine.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notFirstSecondaryConstructorLine.kt")
|
||||
public void testNotFirstSecondaryConstructorLine() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/joinDeclarationAndAssignment/notFirstSecondaryConstructorLine.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyReassignment.kt")
|
||||
public void testPropertyReassignment() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/joinDeclarationAndAssignment/propertyReassignment.kt");
|
||||
|
||||
Reference in New Issue
Block a user