Optimize imports: fixed bug with references in class declaration header

This commit is contained in:
Valentin Kipyatkov
2015-02-17 21:44:42 +03:00
parent 84027124db
commit c58536f1d9
4 changed files with 22 additions and 2 deletions
@@ -216,8 +216,8 @@ public class KotlinImportOptimizer() : ImportOptimizer {
container.getContainingDeclaration() as? ClassDescriptor ?: return false
else
container
val declaration = DescriptorToSourceUtils.classDescriptorToDeclaration(scope)
return declaration != null && declaration.getContainingFile() == file && declaration.isAncestor(place)
val classBody = (DescriptorToSourceUtils.classDescriptorToDeclaration(scope) as? JetClassOrObject)?.getBody()
return classBody != null && classBody.getContainingFile() == file && classBody.isAncestor(place)
}
}
}
@@ -0,0 +1,7 @@
package ppp
import ppp.Base.Nested
class Base(p: Nested) {
class Nested
}
@@ -0,0 +1,7 @@
package ppp
import ppp.Base.Nested
class Base(p: Nested) {
class Nested
}
@@ -139,6 +139,12 @@ public class OptimizeImportsTestGenerated extends AbstractOptimizeImportsTest {
doTest(fileName);
}
@TestMetadata("NestedClassReferenceOutsideClassBody.kt")
public void testNestedClassReferenceOutsideClassBody() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt");
doTest(fileName);
}
@TestMetadata("PartiallyQualified.kt")
public void testPartiallyQualified() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/PartiallyQualified.kt");