Shorten References: Do not shorten qualified expression if receiver values are changed
#KT-5180 Fixed
This commit is contained in:
@@ -33,9 +33,11 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPropertyDescriptor
|
|||||||
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyPackageFragmentForJavaClass
|
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyPackageFragmentForJavaClass
|
||||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaMethodDescriptor
|
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaMethodDescriptor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.SmartPointerManager
|
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
|
||||||
|
import org.jetbrains.jet.renderer.DescriptorRenderer.FQ_NAMES_IN_TYPES
|
||||||
|
|
||||||
public object ShortenReferences {
|
public object ShortenReferences {
|
||||||
public fun process(element: JetElement) {
|
public fun process(element: JetElement) {
|
||||||
@@ -313,7 +315,13 @@ public object ShortenReferences {
|
|||||||
|
|
||||||
private fun resolveState(referenceExpression: JetReferenceExpression, bindingContext: BindingContext): Any? {
|
private fun resolveState(referenceExpression: JetReferenceExpression, bindingContext: BindingContext): Any? {
|
||||||
val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression]
|
val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression]
|
||||||
if (target != null) return target.asString()
|
if (target != null) {
|
||||||
|
val resolvedCallKey = (referenceExpression.getParent() as? JetThisExpression) ?: referenceExpression
|
||||||
|
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, resolvedCallKey]
|
||||||
|
if (resolvedCall != null) return resolvedCall.asString()
|
||||||
|
|
||||||
|
return target.asString()
|
||||||
|
}
|
||||||
|
|
||||||
val targets = bindingContext[BindingContext.AMBIGUOUS_REFERENCE_TARGET, referenceExpression]
|
val targets = bindingContext[BindingContext.AMBIGUOUS_REFERENCE_TARGET, referenceExpression]
|
||||||
if (targets != null) return HashSet(targets.map{it.asString()})
|
if (targets != null) return HashSet(targets.map{it.asString()})
|
||||||
@@ -334,6 +342,10 @@ public object ShortenReferences {
|
|||||||
|
|
||||||
private fun DeclarationDescriptor.asString() = DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this)
|
private fun DeclarationDescriptor.asString() = DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this)
|
||||||
|
|
||||||
|
private fun ResolvedCall<*>.asString(): String {
|
||||||
|
return "${getReceiverArgument()}, ${getThisObject()} -> ${getResultingDescriptor()?.let {FQ_NAMES_IN_TYPES.render(it)}}"
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: do we need this "IfNeeded" check?
|
//TODO: do we need this "IfNeeded" check?
|
||||||
private fun addImportIfNeeded(descriptor: DeclarationDescriptor, file: JetFile) {
|
private fun addImportIfNeeded(descriptor: DeclarationDescriptor, file: JetFile) {
|
||||||
ImportInsertHelper.addImportDirectiveIfNeeded(DescriptorUtils.getFqNameSafe(descriptor), file)
|
ImportInsertHelper.addImportDirectiveIfNeeded(DescriptorUtils.getFqNameSafe(descriptor), file)
|
||||||
|
|||||||
+1
-1
@@ -6,5 +6,5 @@ fun Z.foo(): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Z.i(): Int {
|
fun Z.i(): Int {
|
||||||
return a
|
return this.a
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,5 +6,5 @@ fun Z.foo(): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Z.i(): Int {
|
fun Z.i(): Int {
|
||||||
return a + a
|
return this.a + a
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
trait T : Iterable<String>
|
||||||
|
|
||||||
|
abstract class C : T {
|
||||||
|
fun foo(c: C) {
|
||||||
|
if (<selection>c.any { it.size > 1 }</selection>) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
trait T : Iterable<String>
|
||||||
|
|
||||||
|
abstract class C : T {
|
||||||
|
fun foo(c: C) {
|
||||||
|
if (c.any { it.size > 1 }) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,11 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
|||||||
doTest("idea/testData/shortenRefs/JavaStaticMethod.kt");
|
doTest("idea/testData/shortenRefs/JavaStaticMethod.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noShortening.kt")
|
||||||
|
public void testNoShortening() throws Exception {
|
||||||
|
doTest("idea/testData/shortenRefs/noShortening.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/shortenRefs/constructor")
|
@TestMetadata("idea/testData/shortenRefs/constructor")
|
||||||
public static class Constructor extends AbstractShortenRefsTest {
|
public static class Constructor extends AbstractShortenRefsTest {
|
||||||
public void testAllFilesPresentInConstructor() throws Exception {
|
public void testAllFilesPresentInConstructor() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user