FIR UAST: fix import resolve test

The `resolve` failure (or `null` return) of import directive for
`java.lang.Thread.sleep` is legitimate, since there are two static methods
in `java.lang.Thread`:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Thread.html
hence not able to resolve to a single method.

Unless we change `UImportStatement` to be a subtype of `UMultiResolvable`,
instead of `UResolvable`, we can't properly test `resolve` API for that.
This commit is contained in:
Jinseong Jeon
2021-06-09 22:51:54 -07:00
committed by teamcityserver
parent da25d58fa7
commit 3769fd8e07
@@ -40,8 +40,10 @@ class FirUastResolveApiTest : AbstractFirUastTest() {
fun testImports() {
doCheck("plugins/uast-kotlin/testData/Imports.kt") { _, uFile ->
uFile.imports.forEach { uImport ->
if ((uImport.sourcePsi as? KtImportDirective)?.text?.contains("sleep") == true) {
//todo investigate
if ((uImport.sourcePsi as? KtImportDirective)?.text?.endsWith("sleep") == true) {
// There are two static [sleep] in [java.lang.Thread], so the import (w/o knowing its usage) can't be resolved to
// a single function, hence `null` (as [resolve] result).
// TODO: make [UImportStatement] a subtype of [UMultiResolvable], instead of [UResolvable]?
return@forEach
}
val resolvedImport = uImport.resolve()
@@ -52,8 +54,8 @@ class FirUastResolveApiTest : AbstractFirUastTest() {
resolvedImport.name == "Thread" || resolvedImport.name == "UncaughtExceptionHandler"
}
is PsiMethod -> {
// import java.lang.Thread.(currentThread/sleep)
resolvedImport.name == "currentThread" || resolvedImport.name == "sleep"
// import java.lang.Thread.currentThread
resolvedImport.name == "currentThread"
}
is PsiField -> {
// import java.lang.Thread.NORM_PRIORITY