Do not suggest destructuring for invisible properties #KT-18665 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
c4ebfe8e84
commit
c149c37ac7
@@ -28,8 +28,10 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator
|
||||
import org.jetbrains.kotlin.idea.core.isVisible
|
||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
@@ -333,6 +335,10 @@ class DestructureIntention : SelfTargetingRangeIntention<KtDeclaration>(
|
||||
if (property != null && property.isVar) return null
|
||||
|
||||
val descriptor = qualifiedExpression.getResolvedCall(context)?.resultingDescriptor ?: return null
|
||||
if (!descriptor.isVisible(dataClassUsage, qualifiedExpression.receiverExpression,
|
||||
context, dataClassUsage.containingKtFile.getResolutionFacade())) {
|
||||
return null
|
||||
}
|
||||
return SingleUsageData(descriptor = descriptor, usageToReplace = qualifiedExpression, declarationToDrop = property)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,4 +71,12 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Use destructuring declaration</problem_class>
|
||||
<description>Use destructuring declaration</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>visible.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/visible.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Use destructuring declaration</problem_class>
|
||||
<description>Use destructuring declaration</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,16 @@
|
||||
// SKIP_ERRORS_BEFORE
|
||||
// SKIP_ERRORS_AFTER
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun foo(s: String) {}
|
||||
|
||||
data class Example(private val str: String) {
|
||||
fun doWithExample(block : (Example) -> Unit) = block(Example("hello"))
|
||||
|
||||
}
|
||||
|
||||
fun Example.runExample() {
|
||||
doWithExample { example<caret> ->
|
||||
foo(example.str)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo(s: String) {}
|
||||
|
||||
data class Example(private val str: String) {
|
||||
fun doWithExample(block : (Example) -> Unit) = block(Example("hello"))
|
||||
|
||||
fun runExample() {
|
||||
doWithExample { example<caret> ->
|
||||
foo(example.str)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo(s: String) {}
|
||||
|
||||
data class Example(private val str: String) {
|
||||
fun doWithExample(block : (Example) -> Unit) = block(Example("hello"))
|
||||
|
||||
fun runExample() {
|
||||
doWithExample { (str1) ->
|
||||
foo(str1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7985,6 +7985,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("invisible.kt")
|
||||
public void testInvisible() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringInLambda/invisible.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("last.kt")
|
||||
public void testLast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringInLambda/last.kt");
|
||||
@@ -8056,6 +8062,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringInLambda/variables.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("visible.kt")
|
||||
public void testVisible() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringInLambda/visible.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/destructuringVariables")
|
||||
|
||||
Reference in New Issue
Block a user