SourceNavigationHelper: fix navigation to callables
Previously we could differentiate between callables with the same name
when relevant type declaration were in the same file only
Problem manifested most severely when several copies of sources were attached
to the same library
This commit is contained in:
+2
-22
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.decompiler.navigation
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.DumbService
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.OrderEntry
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
@@ -31,14 +30,11 @@ import com.intellij.util.containers.ContainerUtil
|
||||
import gnu.trove.THashSet
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.context.ContextForNewModule
|
||||
import org.jetbrains.kotlin.context.ProjectContext
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.frontend.di.createLazyResolveSession
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.BinaryModuleInfo
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.SourceForBinaryModuleInfo
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getModuleInfoByVirtualFile
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.decompiler.navigation.MemberMatching.*
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelFunctionFqnNameIndex
|
||||
@@ -50,7 +46,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
||||
|
||||
object SourceNavigationHelper {
|
||||
private val LOG = Logger.getInstance(SourceNavigationHelper::class.java)
|
||||
@@ -162,10 +157,8 @@ object SourceNavigationHelper {
|
||||
}
|
||||
}
|
||||
|
||||
val analyzer = createAnalyzer(candidates, declaration.project)
|
||||
|
||||
for (candidate in candidates) {
|
||||
val candidateDescriptor = analyzer.resolveToDescriptor(candidate) as CallableDescriptor
|
||||
val candidateDescriptor = candidate.resolveToDescriptor() as CallableDescriptor
|
||||
if (receiversMatch(declaration, candidateDescriptor)
|
||||
&& valueParametersTypesMatch(declaration, candidateDescriptor)
|
||||
&& typeParametersMatch(declaration as KtTypeParameterListOwner, candidateDescriptor.typeParameters)) {
|
||||
@@ -176,19 +169,6 @@ object SourceNavigationHelper {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun createAnalyzer(
|
||||
candidates: Collection<KtNamedDeclaration>,
|
||||
project: Project
|
||||
): KotlinCodeAnalyzer {
|
||||
val context = ContextForNewModule(
|
||||
ProjectContext(project), Name.special("<library module>"), DefaultBuiltIns.Instance, null
|
||||
)
|
||||
context.setDependencies(context.module, context.module.builtIns.builtInsModule)
|
||||
val resolveSession = createLazyResolveSession(context, candidates.getContainingFiles())
|
||||
context.initializeModuleContents(resolveSession.packageFragmentProvider)
|
||||
return resolveSession
|
||||
}
|
||||
|
||||
private fun <T : KtNamedDeclaration> findFirstMatchingInIndex(
|
||||
entity: T,
|
||||
navigationKind: NavigationKind,
|
||||
|
||||
+5
-1
@@ -1,4 +1,8 @@
|
||||
package testData.libraries
|
||||
|
||||
public fun func(str : kotlin.String) {
|
||||
}
|
||||
}
|
||||
|
||||
public fun processDouble(d: Double) {}
|
||||
|
||||
public fun processDouble(d: kotlin.Double) {}
|
||||
@@ -111,11 +111,6 @@ public inline fun <T> T.filter(predicate: (T)-> Boolean) : T? = this
|
||||
|
||||
public class Double
|
||||
|
||||
public fun processDouble(d: Double) {}
|
||||
|
||||
public fun processDouble(d: kotlin.Double) {}
|
||||
|
||||
|
||||
public fun <T: CharSequence> funWithTypeParam(t: T) {
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
Double.class
|
||||
Double.class
|
||||
public final class Double public <3>constructor() {
|
||||
MainKt.class
|
||||
ExtraKt.class
|
||||
public fun <1>processDouble(d: kotlin.Double): kotlin.Unit { /* compiled code */ }
|
||||
|
||||
public fun <2>processDouble(d: testData.libraries.Double): kotlin.Unit { /* compiled code */ }
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
main.kt
|
||||
public class <3>Double
|
||||
|
||||
extra.kt
|
||||
public fun <2>processDouble(d: Double) {}
|
||||
|
||||
public fun <1>processDouble(d: kotlin.Double) {}
|
||||
main.kt
|
||||
public class <3>Double
|
||||
|
||||
Reference in New Issue
Block a user