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
9036a3ca
Commit
9036a3ca
authored
1 year ago
by
Jinseong Jeon
Browse files
Options
Download
Email Patches
Plain Diff
K2 UAST: handle call resolution to binary operators
parent
867b7677
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt
+12
-6
.../uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt
plugins/kotlin/uast/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt
+1
-0
...brains/uast/kotlin/FirKotlinUastResolveProviderService.kt
with
13 additions
and
6 deletions
+13
-6
plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt
+
12
-
6
View file @
9036a3ca
...
@@ -1113,6 +1113,8 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
...
@@ -1113,6 +1113,8 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
u++
u++
u + 1
u + 1
u + v
u + v
var x = Point(0, 0)
x += Point(4, 2)
}
}
"""
.
trimIndent
()
"""
.
trimIndent
()
)
)
...
@@ -1172,7 +1174,15 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
...
@@ -1172,7 +1174,15 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
val
uPlusV
=
uFile
.
findElementByTextFromPsi
<
UBinaryExpression
>(
"u + v"
,
strict
=
false
)
val
uPlusV
=
uFile
.
findElementByTextFromPsi
<
UBinaryExpression
>(
"u + v"
,
strict
=
false
)
.
orFail
(
"cant convert to UBinaryExpression"
)
.
orFail
(
"cant convert to UBinaryExpression"
)
TestCase
.
assertEquals
(
"+"
,
uPlusV
.
operatorIdentifier
?.
name
)
TestCase
.
assertEquals
(
"+"
,
uPlusV
.
operatorIdentifier
?.
name
)
val
plusPoint
=
uPlusV
.
resolveOperator
()
var
plusPoint
=
uPlusV
.
resolveOperator
()
TestCase
.
assertEquals
(
"plus"
,
plusPoint
?.
name
)
TestCase
.
assertEquals
(
"other"
,
plusPoint
?.
parameters
?.
get
(
0
)
?.
name
)
TestCase
.
assertEquals
(
"Point"
,
plusPoint
?.
containingClass
?.
name
)
val
xPlusEq
=
uFile
.
findElementByTextFromPsi
<
UBinaryExpression
>(
"x +="
,
strict
=
false
)
.
orFail
(
"cant convert to UBinaryExpression"
)
TestCase
.
assertEquals
(
"+"
,
uPlusV
.
operatorIdentifier
?.
name
)
plusPoint
=
xPlusEq
.
resolveOperator
()
TestCase
.
assertEquals
(
"plus"
,
plusPoint
?.
name
)
TestCase
.
assertEquals
(
"plus"
,
plusPoint
?.
name
)
TestCase
.
assertEquals
(
"other"
,
plusPoint
?.
parameters
?.
get
(
0
)
?.
name
)
TestCase
.
assertEquals
(
"other"
,
plusPoint
?.
parameters
?.
get
(
0
)
?.
name
)
TestCase
.
assertEquals
(
"Point"
,
plusPoint
?.
containingClass
?.
name
)
TestCase
.
assertEquals
(
"Point"
,
plusPoint
?.
containingClass
?.
name
)
...
@@ -1309,11 +1319,7 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
...
@@ -1309,11 +1319,7 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
val
plusEq
=
uFile
.
findElementByTextFromPsi
<
UBinaryExpression
>(
"x.foo +="
,
strict
=
false
)
val
plusEq
=
uFile
.
findElementByTextFromPsi
<
UBinaryExpression
>(
"x.foo +="
,
strict
=
false
)
.
orFail
(
"cant convert to UBinaryExpression"
)
.
orFail
(
"cant convert to UBinaryExpression"
)
val
wholePlusEq
=
plusEq
.
resolveOperator
()
val
wholePlusEq
=
plusEq
.
resolveOperator
()
if
(
isK2
)
{
TestCase
.
assertEquals
(
"plus"
,
wholePlusEq
?.
name
)
TestCase
.
assertNull
(
wholePlusEq
)
}
else
{
TestCase
.
assertEquals
(
"plus"
,
wholePlusEq
?.
name
)
}
// `x.foo` from `x.foo += 42`
// `x.foo` from `x.foo += 42`
val
left
=
(
plusEq
.
leftOperand
as
?
UResolvable
)
?.
resolve
()
as
?
PsiMethod
val
left
=
(
plusEq
.
leftOperand
as
?
UResolvable
)
?.
resolve
()
as
?
PsiMethod
if
(
isK2
)
{
if
(
isK2
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/kotlin/uast/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt
+
1
-
0
View file @
9036a3ca
...
@@ -250,6 +250,7 @@ interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderSer
...
@@ -250,6 +250,7 @@ interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderSer
?.
symbol
?.
symbol
?.
let
{
return
toPsiMethod
(
it
,
ktElement
)
}
?.
let
{
return
toPsiMethod
(
it
,
ktElement
)
}
return
when
(
ktElement
)
{
return
when
(
ktElement
)
{
is
KtBinaryExpression
,
is
KtPrefixExpression
,
is
KtPrefixExpression
,
is
KtPostfixExpression
->
{
is
KtPostfixExpression
->
{
ktCallInfo
.
singleCallOrNull
<
KtCompoundVariableAccessCall
>()
ktCallInfo
.
singleCallOrNull
<
KtCompoundVariableAccessCall
>()
...
...
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