Call expression changes in property initializer are OCB
#KT-38443 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
1cc58518c0
commit
1565fc0211
+16
-6
@@ -222,13 +222,23 @@ abstract class KotlinCodeBlockModificationListenerCompat(protected val project:
|
|||||||
// }
|
// }
|
||||||
if (blockDeclaration.typeReference != null) {
|
if (blockDeclaration.typeReference != null) {
|
||||||
val accessors =
|
val accessors =
|
||||||
blockDeclaration.accessors.map { it.initializer ?: it.bodyExpression } + blockDeclaration.initializer
|
blockDeclaration.accessors.map { it.initializer ?: it.bodyExpression }
|
||||||
for (accessor in accessors) {
|
|
||||||
|
val accessorList = if (blockDeclaration.initializer.isAncestor(element) &&
|
||||||
|
// call expression changes in property initializer are OCB, see KT-38443
|
||||||
|
KtPsiUtil.getTopmostParentOfTypes(element, KtCallExpression::class.java) == null
|
||||||
|
) {
|
||||||
|
accessors + blockDeclaration.initializer
|
||||||
|
} else {
|
||||||
|
accessors
|
||||||
|
}
|
||||||
|
|
||||||
|
for (accessor in accessorList) {
|
||||||
accessor?.takeIf {
|
accessor?.takeIf {
|
||||||
it.isAncestor(element) &&
|
it.isAncestor(element) &&
|
||||||
// adding annotations to accessor is the same as change contract of property
|
// adding annotations to accessor is the same as change contract of property
|
||||||
(element !is KtAnnotated || element.annotationEntries.isEmpty())
|
(element !is KtAnnotated || element.annotationEntries.isEmpty())
|
||||||
}
|
}
|
||||||
?.let { expression ->
|
?.let { expression ->
|
||||||
val declaration =
|
val declaration =
|
||||||
KtPsiUtil.getTopmostParentOfTypes(blockDeclaration, KtClassOrObject::class.java) as? KtElement ?:
|
KtPsiUtil.getTopmostParentOfTypes(blockDeclaration, KtClassOrObject::class.java) as? KtElement ?:
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// OUT_OF_CODE_BLOCK: TRUE
|
||||||
|
// ERROR: No value passed for parameter 'i2'
|
||||||
|
// TYPE: '\b\b'
|
||||||
|
class Test {
|
||||||
|
val foo = bar(1, 2<caret>)
|
||||||
|
|
||||||
|
fun bar(i: Int, i2: Int) = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: it has to be non OCB !
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// TODO: it has to be non OCB !
|
||||||
|
// OUT_OF_CODE_BLOCK: TRUE
|
||||||
|
// ERROR: No value passed for parameter 'i2'
|
||||||
|
// TYPE: '\b\b'
|
||||||
|
class Test {
|
||||||
|
val foo: String? = "a" + bar(1, 2<caret>)
|
||||||
|
|
||||||
|
fun bar(i: Int, i2: Int) = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// SKIP_ANALYZE_CHECK
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// TODO: it has to be non OCB !
|
||||||
|
// OUT_OF_CODE_BLOCK: TRUE
|
||||||
|
// ERROR: The integer literal does not conform to the expected type String?
|
||||||
|
// TYPE: '\b\b\b\b'
|
||||||
|
class Test {
|
||||||
|
val foo: String? = "a"+<caret>1
|
||||||
|
|
||||||
|
fun bar(i: Int, i2: Int) = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// SKIP_ANALYZE_CHECK
|
||||||
+15
@@ -113,6 +113,21 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif
|
|||||||
runTest("idea/testData/codeInsight/outOfBlock/InClassPropertyAccessor.kt");
|
runTest("idea/testData/codeInsight/outOfBlock/InClassPropertyAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InClassPropertyInitializer.kt")
|
||||||
|
public void testInClassPropertyInitializer() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/outOfBlock/InClassPropertyInitializer.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InClassPropertyInitializerWithoutInference.kt")
|
||||||
|
public void testInClassPropertyInitializerWithoutInference() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/outOfBlock/InClassPropertyInitializerWithoutInference.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InClassPropertyInitializerWithoutInference2.kt")
|
||||||
|
public void testInClassPropertyInitializerWithoutInference2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/outOfBlock/InClassPropertyInitializerWithoutInference2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InComment.kt")
|
@TestMetadata("InComment.kt")
|
||||||
public void testInComment() throws Exception {
|
public void testInComment() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/outOfBlock/InComment.kt");
|
runTest("idea/testData/codeInsight/outOfBlock/InComment.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user