Extraction Engine: Consider declarations when comparing descriptors
#KT-6960 Fixed
This commit is contained in:
@@ -201,7 +201,7 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
||||
else {
|
||||
return descriptors.filter { desc ->
|
||||
!alreadyAddedDescriptors.any {
|
||||
comparePossiblyOverridingDescriptors(it, desc)
|
||||
comparePossiblyOverridingDescriptors(project, it, desc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ data class ExtractionData(
|
||||
if (parent is JetUserType && (parent.getParent() as? JetUserType)?.getQualifier() == parent) continue
|
||||
|
||||
val descriptor = context[BindingContext.REFERENCE_TARGET, ref]
|
||||
if (!compareDescriptors(originalResolveResult.descriptor, descriptor)
|
||||
if (!compareDescriptors(project, originalResolveResult.descriptor, descriptor)
|
||||
&& !originalResolveResult.declaration.isInsideOf(originalElements)) {
|
||||
referencesInfo.add(ResolvedReferenceInfo(ref, offset, originalResolveResult))
|
||||
}
|
||||
|
||||
+1
-1
@@ -912,7 +912,7 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts
|
||||
if (diagnostics.any { it.getFactory() == Errors.UNRESOLVED_REFERENCE }
|
||||
|| (currentDescriptor != null
|
||||
&& !ErrorUtils.isError(currentDescriptor)
|
||||
&& !comparePossiblyOverridingDescriptors(currentDescriptor, resolveResult.descriptor))) {
|
||||
&& !comparePossiblyOverridingDescriptors(extractionData.project, currentDescriptor, resolveResult.descriptor))) {
|
||||
conflicts.putValue(
|
||||
resolveResult.originalRefExpr,
|
||||
getDeclarationMessage(resolveResult.declaration, "0.will.no.longer.be.accessible.after.extraction")
|
||||
|
||||
@@ -97,6 +97,7 @@ import com.intellij.psi.PsiJavaCodeReferenceElement
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
|
||||
fun <T: Any> PsiElement.getAndRemoveCopyableUserData(key: Key<T>): T? {
|
||||
val data = getCopyableUserData(key)
|
||||
@@ -403,16 +404,19 @@ public fun chooseContainerElementIfNecessary<T>(
|
||||
|
||||
public fun PsiElement.isTrueJavaMethod(): Boolean = this is PsiMethod && this !is KotlinLightMethod
|
||||
|
||||
fun compareDescriptors(d1: DeclarationDescriptor?, d2: DeclarationDescriptor?): Boolean {
|
||||
return d1 == d2 ||
|
||||
(d1 != null && d2 != null &&
|
||||
DescriptorRenderer.FQ_NAMES_IN_TYPES.render(d1) == DescriptorRenderer.FQ_NAMES_IN_TYPES.render(d2))
|
||||
fun compareDescriptors(project: Project, d1: DeclarationDescriptor?, d2: DeclarationDescriptor?): Boolean {
|
||||
if (d1 == d2) return true
|
||||
if (d1 == null || d2 == null) return false
|
||||
if (DescriptorToSourceUtilsIde.getAllDeclarations(project, d1) == DescriptorToSourceUtilsIde.getAllDeclarations(project, d2)) return true
|
||||
return DescriptorRenderer.FQ_NAMES_IN_TYPES.render(d1) == DescriptorRenderer.FQ_NAMES_IN_TYPES.render(d2)
|
||||
}
|
||||
|
||||
public fun comparePossiblyOverridingDescriptors(currentDescriptor: DeclarationDescriptor?, originalDescriptor: DeclarationDescriptor?): Boolean {
|
||||
if (compareDescriptors(currentDescriptor, originalDescriptor)) return true
|
||||
public fun comparePossiblyOverridingDescriptors(project: Project,
|
||||
currentDescriptor: DeclarationDescriptor?,
|
||||
originalDescriptor: DeclarationDescriptor?): Boolean {
|
||||
if (compareDescriptors(project, currentDescriptor, originalDescriptor)) return true
|
||||
if (originalDescriptor is CallableDescriptor) {
|
||||
if (!OverridingUtil.traverseOverridenDescriptors(originalDescriptor) { !compareDescriptors(currentDescriptor, it) }) return true
|
||||
if (!OverridingUtil.traverseOverridenDescriptors(originalDescriptor) { !compareDescriptors(project, currentDescriptor, it) }) return true
|
||||
if (originalDescriptor !is CallableMemberDescriptor || currentDescriptor !is CallableMemberDescriptor) return false
|
||||
val kind = originalDescriptor.getKind()
|
||||
if (kind != Kind.FAKE_OVERRIDE && kind != Kind.DELEGATION) return false
|
||||
@@ -422,7 +426,7 @@ public fun comparePossiblyOverridingDescriptors(currentDescriptor: DeclarationDe
|
||||
val currentOverriddenDescriptors = currentDescriptor.getOverriddenDescriptors()
|
||||
if (originalOverriddenDescriptors.size() != currentOverriddenDescriptors.size()) return false
|
||||
return (currentOverriddenDescriptors zip originalOverriddenDescriptors ).all {
|
||||
comparePossiblyOverridingDescriptors(it.first, it.second)
|
||||
comparePossiblyOverridingDescriptors(project, it.first, it.second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class J {
|
||||
public static Map<Boolean, Boolean> getMap() {
|
||||
return new HashMap<Boolean, Boolean>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
// PARAM_DESCRIPTOR: value-parameter val it: kotlin.Map.Entry<(Boolean..Boolean?), (Boolean..Boolean?)> defined in test.<anonymous>
|
||||
// PARAM_TYPES: kotlin.Map.Entry<(Boolean..Boolean?), (Boolean..Boolean?)>
|
||||
fun test() {
|
||||
J.getMap().filter { <selection>it.getKey()</selection> }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// PARAM_DESCRIPTOR: value-parameter val it: kotlin.Map.Entry<(Boolean..Boolean?), (Boolean..Boolean?)> defined in test.<anonymous>
|
||||
// PARAM_TYPES: kotlin.Map.Entry<(Boolean..Boolean?), (Boolean..Boolean?)>
|
||||
fun test() {
|
||||
J.getMap().filter { b(it) }
|
||||
}
|
||||
|
||||
private fun b(it: Map.Entry<Boolean, Boolean>) = it.getKey()
|
||||
+6
@@ -346,6 +346,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/refactoring/extractFunction/basic"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("callWithPlatformTypeReceiver.kt")
|
||||
public void testCallWithPlatformTypeReceiver() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/callWithPlatformTypeReceiver.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("delegatingFunction.kt")
|
||||
public void testDelegatingFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/delegatingFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user