KT-14680 import statement to typealias reported as unused when using only TA constructor
#KT-14680 fixed
This commit is contained in:
committed by
Simon Ogorodnik
parent
46bb636cea
commit
f1c4230a68
@@ -66,13 +66,14 @@ fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
||||
return !name.isSpecial
|
||||
}
|
||||
|
||||
val parentClass = containingDeclaration as? ClassDescriptor ?: return false
|
||||
if (!parentClass.canBeReferencedViaImport()) return false
|
||||
//Both TypeAliasDescriptor and ClassDescriptor
|
||||
val parentClassifier = containingDeclaration as? ClassifierDescriptorWithTypeParameters ?: return false
|
||||
if (!parentClassifier.canBeReferencedViaImport()) return false
|
||||
|
||||
return when (this) {
|
||||
is ConstructorDescriptor -> !parentClass.isInner // inner class constructors can't be referenced via import
|
||||
is ClassDescriptor -> true
|
||||
else -> parentClass.kind == ClassKind.OBJECT
|
||||
is ConstructorDescriptor -> !parentClassifier.isInner // inner class constructors can't be referenced via import
|
||||
is ClassDescriptor, is TypeAliasDescriptor -> true
|
||||
else -> parentClassifier is ClassDescriptor && parentClassifier.kind == ClassKind.OBJECT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
class Outer {
|
||||
|
||||
private abstract class Base {
|
||||
|
||||
protected sealed class Sealed {
|
||||
object OOO : Sealed()
|
||||
}
|
||||
|
||||
typealias OOO = Sealed.OOO
|
||||
}
|
||||
|
||||
private class Derived : Base() {
|
||||
|
||||
fun foo(): Sealed {
|
||||
ArrayList<Int>()
|
||||
return OOO
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
class Outer {
|
||||
|
||||
private abstract class Base {
|
||||
|
||||
protected sealed class Sealed {
|
||||
object OOO : Sealed()
|
||||
}
|
||||
|
||||
typealias OOO = Sealed.OOO
|
||||
}
|
||||
|
||||
private class Derived : Base() {
|
||||
|
||||
fun foo(): Sealed {
|
||||
ArrayList<Int>()
|
||||
return OOO
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package p1
|
||||
|
||||
class Some
|
||||
typealias SomeAlias = Some
|
||||
|
||||
annotation class Ann
|
||||
typealias AnnAlias = Ann
|
||||
@@ -0,0 +1,5 @@
|
||||
import p1.SomeAlias
|
||||
import p1.AnnAlias
|
||||
|
||||
@AnnAlias
|
||||
val some = SomeAlias()
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package p1
|
||||
|
||||
class Some
|
||||
typealias SomeAlias = Some
|
||||
|
||||
annotation class Ann
|
||||
typealias AnnAlias = Ann
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Optimize imports" "false"
|
||||
|
||||
import p1.SomeAlias<caret>
|
||||
import p1.AnnAlias
|
||||
|
||||
@AnnAlias
|
||||
val some = SomeAlias()
|
||||
@@ -104,12 +104,6 @@ public class JvmOptimizeImportsTestGenerated extends AbstractJvmOptimizeImportsT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT13766.kt")
|
||||
public void testKT13766() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/jvm/KT13766.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Kt1850FullQualified.kt")
|
||||
public void testKt1850FullQualified() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/jvm/Kt1850FullQualified.kt");
|
||||
|
||||
@@ -1801,6 +1801,21 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/optimizeImports")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class OptimizeImports extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInOptimizeImports() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/optimizeImports"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("notRemoveImportsForTypeAliases.before.Main.kt")
|
||||
public void testNotRemoveImportsForTypeAliases() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/optimizeImports/notRemoveImportsForTypeAliases.before.Main.kt");
|
||||
doTestWithExtraFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/override")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user