Shorten References: Skip companion receivers on callable references

This is temporary fix due to KT-13934 which prevents resolution
of references like X::foo where foo is a member or extension
of X companion object
This commit is contained in:
Alexey Sedunov
2017-03-22 12:33:00 +03:00
parent d71cefee8a
commit aad11ff0f4
4 changed files with 51 additions and 1 deletions
@@ -603,6 +603,10 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
}
override fun analyzeQualifiedElement(element: KtDotQualifiedExpression, bindingContext: BindingContext): AnalyzeQualifiedElementResult {
val parent = element.parent
// TODO: Delete this code when KT-13934 is fixed
if (parent is KtCallableReferenceExpression && parent.receiverExpression == element) return AnalyzeQualifiedElementResult.Skip
val receiver = element.receiverExpression
if (PsiTreeUtil.getParentOfType(
@@ -616,7 +620,7 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
if (receiverTarget.companionObjectDescriptor != selectorTarget) return AnalyzeQualifiedElementResult.Skip
val selectorsSelector = (element.parent as? KtDotQualifiedExpression)?.selectorExpression
val selectorsSelector = (parent as? KtDotQualifiedExpression)?.selectorExpression
?: return AnalyzeQualifiedElementResult.ShortenNow
val selectorsSelectorTarget = selectorsSelector.singleTarget(bindingContext) ?: return AnalyzeQualifiedElementResult.Skip
+20
View File
@@ -0,0 +1,20 @@
package test
class A {
companion object {
fun foo() {
}
}
}
fun A.Companion.bar() {
}
fun test() {
<selection>A.Companion::foo
A.Companion::bar
(A.Companion)::foo
(A.Companion)::bar</selection>
}
@@ -0,0 +1,20 @@
package test
class A {
companion object {
fun foo() {
}
}
}
fun A.Companion.bar() {
}
fun test() {
A.Companion::foo
A.Companion::bar
(A)::foo
(A)::bar
}
@@ -42,6 +42,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
doTest(fileName);
}
@TestMetadata("callableRefsOnCompanion.kt")
public void testCallableRefsOnCompanion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/callableRefsOnCompanion.kt");
doTest(fileName);
}
@TestMetadata("ClassNameConflict.kt")
public void testClassNameConflict() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/ClassNameConflict.kt");