From cdf6229fffed2aa09f5fd613eed0b15c62422e5b Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 15 May 2015 13:16:13 +0300 Subject: [PATCH] KT-7486 Auto import inserts qualified name in companion object #KT-7486 Fixed --- .../kotlin/resolve/lazy/ElementResolver.kt | 16 +++++++--------- .../handlers/basic/PlatformStaticInClass.kt | 5 +++++ .../basic/PlatformStaticInClass.kt.after | 7 +++++++ .../basic/PlatformStaticInCompanionObject.kt | 7 +++++++ .../PlatformStaticInCompanionObject.kt.after | 9 +++++++++ .../BasicCompletionHandlerTestGenerated.java | 12 ++++++++++++ 6 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt create mode 100644 idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt.after create mode 100644 idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt create mode 100644 idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt.after diff --git a/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/ElementResolver.kt b/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/ElementResolver.kt index f3870845c42..e665316c6bf 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/ElementResolver.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/ElementResolver.kt @@ -273,18 +273,16 @@ public abstract class ElementResolver protected( private fun getAnnotationsByDeclaration(resolveSession: ResolveSession, modifierList: JetModifierList, declaration: JetDeclaration): Annotations { var descriptor = resolveSession.resolveToDescriptor(declaration) if (declaration is JetClass) { - val jetClass = declaration - val classDescriptor = descriptor as ClassDescriptor - if (modifierList == jetClass.getPrimaryConstructorModifierList()) { - descriptor = classDescriptor.getUnsubstitutedPrimaryConstructor() + if (modifierList == declaration.getPrimaryConstructorModifierList()) { + descriptor = (descriptor as ClassDescriptor).getUnsubstitutedPrimaryConstructor() ?: error("No constructor found: ${declaration.getText()}") } - else if (modifierList.getParent() == jetClass.getBody()) { - if (classDescriptor is LazyClassDescriptor) { - return classDescriptor.getDanglingAnnotations() - } - } } + + if (declaration is JetClassOrObject && modifierList.getParent() == declaration.getBody() && descriptor is LazyClassDescriptor) { + return descriptor.getDanglingAnnotations() + } + return descriptor.getAnnotations() } diff --git a/idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt b/idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt new file mode 100644 index 00000000000..9da09b18d57 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt @@ -0,0 +1,5 @@ +class A { + pl +} + +// ELEMENT: platformStatic \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt.after b/idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt.after new file mode 100644 index 00000000000..83b4ee6ab89 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt.after @@ -0,0 +1,7 @@ +import kotlin.platform.platformStatic + +class A { + platformStatic +} + +// ELEMENT: platformStatic \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt b/idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt new file mode 100644 index 00000000000..4684a5f72f6 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt @@ -0,0 +1,7 @@ +class A { + companion object { + pl + } +} + +// ELEMENT: platformStatic \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt.after b/idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt.after new file mode 100644 index 00000000000..09fd0ec89be --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt.after @@ -0,0 +1,9 @@ +import kotlin.platform.platformStatic + +class A { + companion object { + platformStatic + } +} + +// ELEMENT: platformStatic \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java index b9ed943b8db..0d0b8786f8c 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java @@ -107,6 +107,18 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion doTest(fileName); } + @TestMetadata("PlatformStaticInClass.kt") + public void testPlatformStaticInClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/PlatformStaticInClass.kt"); + doTest(fileName); + } + + @TestMetadata("PlatformStaticInCompanionObject.kt") + public void testPlatformStaticInCompanionObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/PlatformStaticInCompanionObject.kt"); + doTest(fileName); + } + @TestMetadata("ReplaceFunctionCallByProperty.kt") public void testReplaceFunctionCallByProperty() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/ReplaceFunctionCallByProperty.kt");