From c63eb18b3cea7e05ddff43cfa384b983467f04a1 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 20 Sep 2017 12:14:27 +0300 Subject: [PATCH] Fixed nested class in companion object case --- .../org/jetbrains/kotlin/idea/core/ShortenReferences.kt | 5 +++-- .../shortenRefs/classInCompanionObject.dependency.kt | 7 +++++++ idea/testData/shortenRefs/classInCompanionObject.kt | 5 +++++ idea/testData/shortenRefs/classInCompanionObject.kt.after | 5 +++++ .../kotlin/shortenRefs/ShortenRefsTestGenerated.java | 6 ++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 idea/testData/shortenRefs/classInCompanionObject.dependency.kt create mode 100644 idea/testData/shortenRefs/classInCompanionObject.kt create mode 100644 idea/testData/shortenRefs/classInCompanionObject.kt.after diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt index b5aa4ee257e..fe615157125 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt @@ -548,9 +548,10 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT when (targetDescriptor) { is ClassDescriptor -> { if (targetDescriptor.kind != ClassKind.OBJECT) return true - // for object receiver we should additionally check that it's dispatch receiver (that is the member is inside the object) + // for object receiver we should additionally check that it's dispatch receiver (that is the member is inside the object) or not a receiver at all val resolvedCall = element.getResolvedCall(bindingContext) ?: return false - return resolvedCall.explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER + val receiverKind = resolvedCall.explicitReceiverKind + return receiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER || receiverKind == ExplicitReceiverKind.NO_EXPLICIT_RECEIVER } is PackageViewDescriptor -> return true diff --git a/idea/testData/shortenRefs/classInCompanionObject.dependency.kt b/idea/testData/shortenRefs/classInCompanionObject.dependency.kt new file mode 100644 index 00000000000..3b46ce9e12e --- /dev/null +++ b/idea/testData/shortenRefs/classInCompanionObject.dependency.kt @@ -0,0 +1,7 @@ +package dependency + +class C { + companion object { + class Nested + } +} \ No newline at end of file diff --git a/idea/testData/shortenRefs/classInCompanionObject.kt b/idea/testData/shortenRefs/classInCompanionObject.kt new file mode 100644 index 00000000000..4b40920657d --- /dev/null +++ b/idea/testData/shortenRefs/classInCompanionObject.kt @@ -0,0 +1,5 @@ +import dependency.C.Companion.Nested + +fun foo() { + dependency.C.Companion.Nested() +} \ No newline at end of file diff --git a/idea/testData/shortenRefs/classInCompanionObject.kt.after b/idea/testData/shortenRefs/classInCompanionObject.kt.after new file mode 100644 index 00000000000..af3dc2fd4c9 --- /dev/null +++ b/idea/testData/shortenRefs/classInCompanionObject.kt.after @@ -0,0 +1,5 @@ +import dependency.C.Companion.Nested + +fun foo() { + Nested() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java b/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java index ae85ac09952..473d31974ef 100644 --- a/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java @@ -39,6 +39,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest { runTest("idea/testData/shortenRefs/callableRefsOnCompanion.kt"); } + @TestMetadata("classInCompanionObject.kt") + public void testClassInCompanionObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/classInCompanionObject.kt"); + doTest(fileName); + } + @TestMetadata("ClassNameConflict.kt") public void testClassNameConflict() throws Exception { runTest("idea/testData/shortenRefs/ClassNameConflict.kt");