KT-10770 IDEA cannot keep import if a type is only referenced by kdoc.
#KT-10770 Fixed
This commit is contained in:
@@ -189,7 +189,11 @@ fun KtExpression.readWriteAccess(useResolveForReadWrite: Boolean): ReferenceAcce
|
|||||||
|
|
||||||
fun KtReference.canBeResolvedViaImport(target: DeclarationDescriptor): Boolean {
|
fun KtReference.canBeResolvedViaImport(target: DeclarationDescriptor): Boolean {
|
||||||
if (!target.canBeReferencedViaImport()) return false
|
if (!target.canBeReferencedViaImport()) return false
|
||||||
|
|
||||||
|
if (this is KDocReference) return element.getQualifiedName().size == 1
|
||||||
|
|
||||||
if (target.isExtension) return true // assume that any type of reference can use imports when resolved to extension
|
if (target.isExtension) return true // assume that any type of reference can use imports when resolved to extension
|
||||||
|
|
||||||
val referenceExpression = this.element as? KtNameReferenceExpression ?: return false
|
val referenceExpression = this.element as? KtNameReferenceExpression ?: return false
|
||||||
if (CallTypeAndReceiver.detect(referenceExpression).receiver != null) return false
|
if (CallTypeAndReceiver.detect(referenceExpression).receiver != null) return false
|
||||||
if (element.parent is KtThisExpression || element.parent is KtSuperExpression) return false // TODO: it's a bad design of PSI tree, we should change it
|
if (element.parent is KtThisExpression || element.parent is KtSuperExpression) return false // TODO: it's a bad design of PSI tree, we should change it
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// RUNTIME
|
||||||
|
import kotlin.concurrent.fixedRateTimer
|
||||||
|
import kotlin.concurrent.read
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to [ArrayList]
|
||||||
|
* Reference to [fixedRateTimer]
|
||||||
|
* Reference to [kotlin.concurrent.read]
|
||||||
|
*/
|
||||||
|
fun foo() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// RUNTIME
|
||||||
|
import java.util.ArrayList
|
||||||
|
import kotlin.concurrent.fixedRateTimer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to [ArrayList]
|
||||||
|
* Reference to [fixedRateTimer]
|
||||||
|
* Reference to [kotlin.concurrent.read]
|
||||||
|
*/
|
||||||
|
fun foo() {
|
||||||
|
}
|
||||||
@@ -88,4 +88,13 @@
|
|||||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused import directive</problem_class>
|
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused import directive</problem_class>
|
||||||
<description>Unused import directive</description>
|
<description>Unused import directive</description>
|
||||||
</problem>
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>kDocReferences.kt</file>
|
||||||
|
<line>2</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="kDocReferences.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused import directive</problem_class>
|
||||||
|
<description>Unused import directive</description>
|
||||||
|
</problem>
|
||||||
</problems>
|
</problems>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import kotlin.concurrent.fixedRateTimer
|
||||||
|
import kotlin.concurrent.read
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to [ArrayList]
|
||||||
|
* Reference to [fixedRateTimer]
|
||||||
|
* Reference to [kotlin.concurrent.read]
|
||||||
|
*/
|
||||||
|
fun foo() {
|
||||||
|
}
|
||||||
@@ -137,6 +137,12 @@ public class OptimizeImportsTestGenerated extends AbstractOptimizeImportsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("KDocReference.kt")
|
||||||
|
public void testKDocReference() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/KDocReference.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("KT10226.kt")
|
@TestMetadata("KT10226.kt")
|
||||||
public void testKT10226() throws Exception {
|
public void testKT10226() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/KT10226.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/KT10226.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user