Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
1952b41f
Commit
1952b41f
authored
3 years ago
by
Jinseong Jeon
Browse files
Options
Download
Email Patches
Plain Diff
FIR/UAST: resolve implicit lambda parameter
^KTIJ-18800 Fixed
parent
69b88c81
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
plugins/kotlin/uast/uast-kotlin-base/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt
+47
-0
.../uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt
plugins/kotlin/uast/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt
+9
-0
...brains/uast/kotlin/FirKotlinUastResolveProviderService.kt
plugins/kotlin/uast/uast-kotlin-fir/test/org/jetbrains/kotlin/idea/fir/uast/FirUastResolveApiFixtureTest.kt
+8
-0
...ains/kotlin/idea/fir/uast/FirUastResolveApiFixtureTest.kt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaExpressionFunctionalInterfaceType.resolved.fe10.txt
+1
-1
...LambdaExpressionFunctionalInterfaceType.resolved.fe10.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaExpressionFunctionalInterfaceType.resolved.fir.txt
+1
-1
.../LambdaExpressionFunctionalInterfaceType.resolved.fir.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaParameters.resolved.fe10.txt
+1
-1
...estData/legacyResolved/LambdaParameters.resolved.fe10.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaParameters.resolved.fir.txt
+1
-1
...testData/legacyResolved/LambdaParameters.resolved.fir.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaReturn.resolved.fe10.txt
+2
-2
...ir/testData/legacyResolved/LambdaReturn.resolved.fe10.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaReturn.resolved.fir.txt
+2
-2
...fir/testData/legacyResolved/LambdaReturn.resolved.fir.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Lambdas.resolved.fe10.txt
+1
-1
...lin-fir/testData/legacyResolved/Lambdas.resolved.fe10.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Lambdas.resolved.fir.txt
+1
-1
...tlin-fir/testData/legacyResolved/Lambdas.resolved.fir.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Resolve.resolved.fe10.txt
+1
-1
...lin-fir/testData/legacyResolved/Resolve.resolved.fe10.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Resolve.resolved.fir.txt
+1
-1
...tlin-fir/testData/legacyResolved/Resolve.resolved.fir.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/TypeReferences.resolved.fe10.txt
+1
-1
.../testData/legacyResolved/TypeReferences.resolved.fe10.txt
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/TypeReferences.resolved.fir.txt
+1
-1
...r/testData/legacyResolved/TypeReferences.resolved.fir.txt
plugins/kotlin/uast/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt
+18
-2
...jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt
plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1UastResolveApiFixtureTest.kt
+9
-1
...st/test/kotlin/comparison/FE1UastResolveApiFixtureTest.kt
plugins/kotlin/uast/uast-kotlin/tests/testData/Resolve.resolved.txt
+1
-1
...tlin/uast/uast-kotlin/tests/testData/Resolve.resolved.txt
plugins/kotlin/uast/uast-kotlin/tests/testData/TypeReferences.resolved.txt
+1
-1
...st/uast-kotlin/tests/testData/TypeReferences.resolved.txt
with
107 additions
and
19 deletions
+107
-19
plugins/kotlin/uast/uast-kotlin-base/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt
+
47
-
0
View file @
1952b41f
...
...
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCaseBase
import
org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCaseBase.assertContainsElements
import
org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCaseBase.assertDoesntContain
import
org.jetbrains.kotlin.psi.KtConstructor
import
org.jetbrains.kotlin.psi.KtParameter
import
org.jetbrains.kotlin.utils.addToStdlib.cast
import
org.jetbrains.uast.*
import
org.jetbrains.uast.kotlin.KotlinUFunctionCallExpression
...
...
@@ -380,6 +381,52 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
TestCase
.
assertEquals
(
"message"
,
resolved
.
name
)
}
fun
checkResolveExplicitLambdaParameter
(
myFixture
:
JavaCodeInsightTestFixture
)
{
myFixture
.
configureByText
(
"main.kt"
,
"""
inline fun <T, R> T.use(block: (T) -> R): R {
return block(this)
}
fun foo() {
42.use { it ->
i<caret>t.toString()
}
}
"""
.
trimIndent
()
)
val
uCallExpression
=
myFixture
.
file
.
findElementAt
(
myFixture
.
caretOffset
).
toUElement
().
getUCallExpression
()
.
orFail
(
"cant convert to UCallExpression"
)
TestCase
.
assertEquals
(
"it"
,
(
uCallExpression
.
receiver
as
?
USimpleNameReferenceExpression
)
?.
identifier
)
// Expect to be resolved to source KtParameter
val
resolved
=
(
uCallExpression
.
receiver
?.
tryResolve
()
as
?
KtParameter
)
.
orFail
(
"cant resolve explicit lambda parameter"
)
TestCase
.
assertEquals
(
"it"
,
resolved
.
name
)
}
fun
checkResolveImplicitLambdaParameter
(
myFixture
:
JavaCodeInsightTestFixture
)
{
myFixture
.
configureByText
(
"main.kt"
,
"""
inline fun <T, R> T.use(block: (T) -> R): R {
return block(this)
}
fun foo() {
42.use { i<caret>t.toString() }
}
"""
.
trimIndent
()
)
val
uCallExpression
=
myFixture
.
file
.
findElementAt
(
myFixture
.
caretOffset
).
toUElement
().
getUCallExpression
()
.
orFail
(
"cant convert to UCallExpression"
)
TestCase
.
assertEquals
(
"it"
,
(
uCallExpression
.
receiver
as
?
USimpleNameReferenceExpression
)
?.
identifier
)
// No source for implicit lambda parameter. Expect to be resolved to fake PsiParameter used inside ULambdaExpression
val
resolved
=
(
uCallExpression
.
receiver
?.
tryResolve
()
as
?
PsiParameter
)
.
orFail
(
"cant resolve implicit lambda parameter"
)
TestCase
.
assertEquals
(
"it"
,
resolved
.
name
)
}
fun
checkResolveSyntheticMethod
(
myFixture
:
JavaCodeInsightTestFixture
)
{
myFixture
.
configureByText
(
"MyClass.kt"
,
"""
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt
+
9
-
0
View file @
1952b41f
...
...
@@ -358,6 +358,15 @@ interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderSer
)
?.
let
{
return
it
}
}
}
is
KtFunctionLiteral
->
{
// Implicit lambda parameter `it`
if
((
resolvedTargetSymbol
as
?
KtValueParameterSymbol
)
?.
isImplicitLambdaParameter
==
true
)
{
// From its containing lambda (of function literal), build ULambdaExpression
val
lambda
=
resolvedTargetElement
.
toUElementOfType
<
ULambdaExpression
>()
// and return javaPsi of the corresponding lambda implicit parameter
lambda
?.
valueParameters
?.
singleOrNull
()
?.
javaPsi
?.
let
{
return
it
}
}
}
}
// TODO: need to handle resolved target to library source
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/test/org/jetbrains/kotlin/idea/fir/uast/FirUastResolveApiFixtureTest.kt
+
8
-
0
View file @
1952b41f
...
...
@@ -117,6 +117,14 @@ class FirUastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
doCheck
(
"ResolveCompiledAnnotation"
,
::
checkResolveCompiledAnnotation
)
}
fun
testResolveExplicitLambdaParameter
()
{
doCheck
(
"ResolveExplicitLambdaParameter"
,
::
checkResolveExplicitLambdaParameter
)
}
fun
testResolveImplicitLambdaParameter
()
{
doCheck
(
"ResolveImplicitLambdaParameter"
,
::
checkResolveImplicitLambdaParameter
)
}
fun
testResolveSyntheticMethod
()
{
doCheck
(
"ResolveSyntheticMethod"
,
::
checkResolveSyntheticMethod
)
}
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaExpressionFunctionalInterfaceType.resolved.fe10.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -10,5 +10,5 @@ UBlockExpression -> UQualifiedReferenceExpression -> Decompiled_Method: map
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = of) -> Decompiled_Method: of
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = map) -> Decompiled_Method: map
UReturnExpression -> UQualifiedReferenceExpression -> Decompiled_Method: toString
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = toString) -> Decompiled_Method: toString
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaExpressionFunctionalInterfaceType.resolved.fir.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -10,5 +10,5 @@ UBlockExpression -> UQualifiedReferenceExpression -> Decompiled_Method: map
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = of) -> Decompiled_Method: of
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = map) -> Decompiled_Method: map
UReturnExpression -> UQualifiedReferenceExpression -> null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = toString) -> FUN: toString
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaParameters.resolved.fe10.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -2,4 +2,4 @@ UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolve
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = append) -> Decompiled_Method: append
UBlockExpression -> UQualifiedReferenceExpression -> Decompiled_Method: let
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = let) -> Decompiled_Method: let
UReturnExpression -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UReturnExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaParameters.resolved.fir.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -2,4 +2,4 @@ UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolve
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = append) -> Decompiled_Method: append
UBlockExpression -> UQualifiedReferenceExpression -> null: null
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to null) -> USimpleNameReferenceExpression (identifier = let) -> FUN: let
UReturnExpression -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UReturnExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaReturn.resolved.fe10.txt
+
2
-
2
View file @
1952b41f
...
...
@@ -34,9 +34,9 @@ UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = ko
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = +) -> Kotlin_Light_Method: plus
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = a) -> VALUE_PARAMETER: a
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Kotlin_Light_Method) -> USimpleNameReferenceExpression (identifier = bar) -> Kotlin_Light_Method: bar
UBinaryExpression (operator = >) -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UBinaryExpression (operator = >) -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UBinaryExpression (operator = >) -> USimpleNameReferenceExpression (identifier = >) -> null: null
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = +) -> null: null
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = b) -> Kotlin_Light_Variable: b
UTypeReferenceExpression (name = kotlin.Unit) -> USimpleNameReferenceExpression (identifier = Unit) -> Decompiled_Class: Unit
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/LambdaReturn.resolved.fir.txt
+
2
-
2
View file @
1952b41f
...
...
@@ -34,9 +34,9 @@ UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = ko
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = +) -> FUN: plus
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = a) -> VALUE_PARAMETER: a
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Kotlin_Light_Method) -> USimpleNameReferenceExpression (identifier = bar) -> Kotlin_Light_Method: bar
UBinaryExpression (operator = >) -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UBinaryExpression (operator = >) -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UBinaryExpression (operator = >) -> USimpleNameReferenceExpression (identifier = >) -> FUN: compareTo
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = +) -> FUN: plus
UBinaryExpression (operator = +) -> USimpleNameReferenceExpression (identifier = b) -> Kotlin_Light_Variable: b
UTypeReferenceExpression (name = kotlin.Unit) -> USimpleNameReferenceExpression (identifier = Unit) -> Decompiled_Class: Unit
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Lambdas.resolved.fe10.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -12,7 +12,7 @@ UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = St
UTypeReferenceExpression (name = java.lang.String) -> USimpleNameReferenceExpression (identifier = String) -> Decompiled_Class: String
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = filter) -> Decompiled_Method: filter
UReturnExpression -> UQualifiedReferenceExpression -> Decompiled_Method: isEmpty
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = isEmpty) -> Decompiled_Method: isEmpty
UTypeReferenceExpression (name = kotlin.Unit) -> USimpleNameReferenceExpression (identifier = Unit) -> Decompiled_Class: Unit
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = selectItemFunction) -> Kotlin_Light_Value_Parameter: selectItemFunction
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Lambdas.resolved.fir.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -12,7 +12,7 @@ UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = St
UTypeReferenceExpression (name = java.lang.String) -> USimpleNameReferenceExpression (identifier = String) -> null: null
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = filter) -> Decompiled_Method: filter
UReturnExpression -> UQualifiedReferenceExpression -> null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = isEmpty) -> FUN: isEmpty
UTypeReferenceExpression (name = kotlin.Unit) -> USimpleNameReferenceExpression (identifier = Unit) -> Decompiled_Class: Unit
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = selectItemFunction) -> Kotlin_Light_Value_Parameter: selectItemFunction
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Resolve.resolved.fe10.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -24,7 +24,7 @@ UBlockExpression -> UQualifiedReferenceExpression -> Kotlin_Light_Method: foo
}: A
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = forEach) -> Decompiled_Method: forEach
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = println) -> Decompiled_Method: println
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UBlockExpression -> UQualifiedReferenceExpression -> Decompiled_Method: joinToString
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = listOf) -> Decompiled_Method: listOf
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = joinToString) -> Decompiled_Method: joinToString
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/Resolve.resolved.fir.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -24,7 +24,7 @@ UBlockExpression -> UQualifiedReferenceExpression -> Kotlin_Light_Method: foo
}: A
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to null) -> USimpleNameReferenceExpression (identifier = forEach) -> FUN: forEach
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = println) -> Decompiled_Method: println
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UBlockExpression -> UQualifiedReferenceExpression -> null: null
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to null) -> USimpleNameReferenceExpression (identifier = listOf) -> FUN: listOf
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = joinToString) -> FUN: joinToString
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/TypeReferences.resolved.fe10.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -23,7 +23,7 @@ UTypeReferenceExpression (name = T) -> USimpleNameReferenceExpression (identifie
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = tl) -> Kotlin_Light_Variable: tl
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to Decompiled_Method) -> USimpleNameReferenceExpression (identifier = map) -> Decompiled_Method: map
UReturnExpression -> UQualifiedReferenceExpression -> null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = toString) -> null: null
UTypeReferenceExpression (name = java.util.List<? extends java.util.List<? extends java.lang.String>>) -> USimpleNameReferenceExpression (identifier = List) -> Decompiled_Class: List
UTypeReferenceExpression (name = java.util.List<? extends java.lang.String>) -> USimpleNameReferenceExpression (identifier = List) -> Decompiled_Class: List
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/testData/legacyResolved/TypeReferences.resolved.fir.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -23,7 +23,7 @@ UTypeReferenceExpression (name = T) -> USimpleNameReferenceExpression (identifie
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = tl) -> Kotlin_Light_Variable: tl
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to null) -> USimpleNameReferenceExpression (identifier = map) -> FUN: map
UReturnExpression -> UQualifiedReferenceExpression -> null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
FUNCTION_LITERAL: <anonymous>
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Kotlin_Light_Value_Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = toString) -> FUN: toString
UTypeReferenceExpression (name = java.util.List<? extends java.util.List<? extends java.lang.String>>) -> USimpleNameReferenceExpression (identifier = List) -> Decompiled_Class: List
UTypeReferenceExpression (name = java.util.List<? extends java.lang.String>) -> USimpleNameReferenceExpression (identifier = List) -> Decompiled_Class: List
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt
+
18
-
2
View file @
1952b41f
...
...
@@ -14,16 +14,17 @@ import com.intellij.psi.impl.compiled.StubBuildingVisitor
import
com.intellij.psi.util.PsiTypesUtil
import
com.intellij.util.SmartList
import
org.jetbrains.kotlin.asJava.*
import
org.jetbrains.kotlin.backend.jvm.serialization.DisabledDescriptorMangler.signatureString
import
org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype
import
org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
import
org.jetbrains.kotlin.descriptors.*
import
org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import
org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import
org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
import
org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
import
org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import
org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import
org.jetbrains.kotlin.idea.KotlinLanguage
import
org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
import
org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment
import
org.jetbrains.kotlin.load.java.sam.SamAdapterDescriptor
import
org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryPackageSourceElement
...
...
@@ -45,7 +46,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstr
import
org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
import
org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import
org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl
import
org.jetbrains.kotlin.resolve.calls.util.isFakePsiElement
import
org.jetbrains.kotlin.resolve.constants.*
import
org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import
org.jetbrains.kotlin.resolve.references.ReferenceAccess
...
...
@@ -384,6 +384,13 @@ fun resolveToDeclarationImpl(sourcePsi: KtExpression, declarationDescriptor: Dec
if
(
parentDeclaration
is
PsiClass
&&
parentDeclaration
.
isAnnotationType
)
{
parentDeclaration
.
findMethodsByName
(
declarationDescriptor
.
name
.
asString
(),
false
).
firstOrNull
()
?.
let
{
return
it
}
}
// Implicit lambda parameter `it`
if
(
declarationDescriptor
.
isImplicitLambdaParameter
(
sourcePsi
))
{
// From its containing lambda (of function literal), build ULambdaExpression
val
lambda
=
declarationDescriptor
.
containingDeclaration
.
findPsi
().
toUElementOfType
<
ULambdaExpression
>()
// and return javaPsi of the corresponding lambda implicit parameter
return
lambda
?.
valueParameters
?.
singleOrNull
()
?.
javaPsi
}
}
if
(
declarationDescriptor
is
CallableMemberDescriptor
&&
declarationDescriptor
.
kind
==
CallableMemberDescriptor
.
Kind
.
FAKE_OVERRIDE
)
{
...
...
@@ -398,6 +405,15 @@ fun resolveToDeclarationImpl(sourcePsi: KtExpression, declarationDescriptor: Dec
return
null
}
private
fun
ValueParameterDescriptor
.
isImplicitLambdaParameter
(
sourcePsi
:
KtExpression
):
Boolean
{
return
containingDeclaration
is
AnonymousFunctionDescriptor
&&
name
.
identifierOrNullIfSpecial
==
"it"
&&
// Implicit lambda parameter doesn't have a source PSI.
source
.
getPsi
()
==
null
&&
// But, that could be the case for a declaration from Library. Double-check the slice in the binding context
sourcePsi
.
analyze
().
get
(
BindingContext
.
AUTO_CREATED_IT
,
this
)
!=
null
}
private
fun
resolveContainingDeserializedClass
(
context
:
KtElement
,
memberDescriptor
:
DeserializedCallableMemberDescriptor
):
PsiClass
?
{
return
when
(
val
containingDeclaration
=
memberDescriptor
.
containingDeclaration
)
{
is
LazyJavaPackageFragment
->
{
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1UastResolveApiFixtureTest.kt
+
9
-
1
View file @
1952b41f
...
...
@@ -63,6 +63,14 @@ class FE1UastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
checkResolveCompiledAnnotation
(
myFixture
)
}
fun
testResolveExplicitLambdaParameter
()
{
checkResolveExplicitLambdaParameter
(
myFixture
)
}
fun
testResolveImplicitLambdaParameter
()
{
checkResolveImplicitLambdaParameter
(
myFixture
)
}
fun
testResolveSyntheticMethod
()
{
checkResolveSyntheticMethod
(
myFixture
)
}
...
...
@@ -82,4 +90,4 @@ class FE1UastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
fun
testSyntheticEnumMethods
()
{
checkSyntheticEnumMethods
(
myFixture
)
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin/tests/testData/Resolve.resolved.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -24,7 +24,7 @@ UBlockExpression -> UQualifiedReferenceExpression -> KtUltraLightMethodForSource
}: A
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to PsiMethod:forEach) -> USimpleNameReferenceExpression (identifier = forEach) -> PsiMethod:forEach: forEach
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to PsiMethod:println) -> USimpleNameReferenceExpression (identifier = println) -> PsiMethod:println: println
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to PsiMethod:println) -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to PsiMethod:println) -> USimpleNameReferenceExpression (identifier = it) ->
Light Parameter: it
UBlockExpression -> UQualifiedReferenceExpression -> PsiMethod:joinToString: joinToString
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to PsiMethod:listOf) -> USimpleNameReferenceExpression (identifier = listOf) -> PsiMethod:listOf: listOf
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to PsiMethod:joinToString) -> USimpleNameReferenceExpression (identifier = joinToString) -> PsiMethod:joinToString: joinToString
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin/tests/testData/TypeReferences.resolved.txt
+
1
-
1
View file @
1952b41f
...
...
@@ -23,7 +23,7 @@ UTypeReferenceExpression (name = T) -> USimpleNameReferenceExpression (identifie
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = tl) -> LightVariableBuilder:tl: tl
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))(resolves to PsiMethod:map) -> USimpleNameReferenceExpression (identifier = map) -> PsiMethod:map: map
UReturnExpression -> UQualifiedReferenceExpression -> null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
null: null
UQualifiedReferenceExpression -> USimpleNameReferenceExpression (identifier = it) ->
Light Parameter: it
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))(resolves to null) -> USimpleNameReferenceExpression (identifier = toString) -> null: null
UTypeReferenceExpression (name = java.util.List<? extends java.util.List<? extends java.lang.String>>) -> USimpleNameReferenceExpression (identifier = List) -> PsiClass:List: List
UTypeReferenceExpression (name = java.util.List<? extends java.lang.String>) -> USimpleNameReferenceExpression (identifier = List) -> PsiClass:List: List
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment