Conflicting extension is recognized as redundant for setter with expression body

This commit is contained in:
Valentin Kipyatkov
2015-09-01 13:17:12 +03:00
parent f244bfb073
commit 16650e8f5c
4 changed files with 20 additions and 3 deletions
@@ -129,9 +129,13 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
private fun checkSetterBodyIsSetMethodCall(setter: JetPropertyAccessor, setMethod: FunctionDescriptor): Boolean {
val valueParameterName = setter.valueParameters.singleOrNull()?.nameAsName ?: return false
if (!setter.hasBlockBody()) return false
val statement = (setter.bodyExpression as? JetBlockExpression)?.statements?.singleOrNull() ?: return false
return statement.isSetMethodCall(setMethod, valueParameterName)
if (setter.hasBlockBody()) {
val statement = (setter.bodyExpression as? JetBlockExpression)?.statements?.singleOrNull() ?: return false
return statement.isSetMethodCall(setMethod, valueParameterName)
}
else {
return setter.bodyExpression.isSetMethodCall(setMethod, valueParameterName)
}
}
private fun JetExpression?.isGetMethodCall(getMethod: FunctionDescriptor): Boolean {
@@ -0,0 +1,5 @@
// "Delete redundant extension property" "true"
var Thread.<caret>priority: Int
get() = getPriority()
set(value) = setPriority(value)
@@ -0,0 +1,2 @@
// "Delete redundant extension property" "true"
@@ -3955,6 +3955,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("setterWithExpressionBody.kt")
public void testSetterWithExpressionBody() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/conflictingExtension/setterWithExpressionBody.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/conflictingExtension/simple.kt");