Uast: explicitly expose implicit Lambda parameters
This commit is contained in:
+18
-2
@@ -18,11 +18,13 @@ package org.jetbrains.uast.kotlin
|
|||||||
|
|
||||||
import com.intellij.psi.PsiType
|
import com.intellij.psi.PsiType
|
||||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
|
||||||
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext.FUNCTION
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsResultOfLambda
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsResultOfLambda
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameterBase
|
||||||
|
|
||||||
class KotlinULambdaExpression(
|
class KotlinULambdaExpression(
|
||||||
override val sourcePsi: KtLambdaExpression,
|
override val sourcePsi: KtLambdaExpression,
|
||||||
@@ -58,9 +60,23 @@ class KotlinULambdaExpression(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val valueParameters by lz {
|
override val valueParameters by lz {
|
||||||
sourcePsi.valueParameters.mapIndexed { i, p ->
|
|
||||||
|
val explicitParameters = sourcePsi.valueParameters.mapIndexed { i, p ->
|
||||||
KotlinUParameter(UastKotlinPsiParameter.create(p, sourcePsi, this, i), p, this)
|
KotlinUParameter(UastKotlinPsiParameter.create(p, sourcePsi, this, i), p, this)
|
||||||
}
|
}
|
||||||
|
if (explicitParameters.isNotEmpty()) return@lz explicitParameters
|
||||||
|
|
||||||
|
val functionDescriptor = sourcePsi.analyze()[FUNCTION, sourcePsi.functionLiteral] ?: return@lz emptyList()
|
||||||
|
functionDescriptor.valueParameters.mapIndexed { i, p ->
|
||||||
|
KotlinUParameter(
|
||||||
|
UastKotlinPsiParameterBase(
|
||||||
|
p.name.asString(),
|
||||||
|
p.type.toPsiType(this, sourcePsi, false),
|
||||||
|
sourcePsi, sourcePsi, sourcePsi.language, p.isVararg, null
|
||||||
|
),
|
||||||
|
null, this
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun asRenderString(): String {
|
override fun asRenderString(): String {
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ UFile (package = org.jetbrains.uast.kotlin)
|
|||||||
UIdentifier (Identifier (bar))
|
UIdentifier (Identifier (bar))
|
||||||
USimpleNameReferenceExpression (identifier = bar, resolvesTo = null)
|
USimpleNameReferenceExpression (identifier = bar, resolvesTo = null)
|
||||||
ULambdaExpression
|
ULambdaExpression
|
||||||
|
UParameter (name = it)
|
||||||
UBlockExpression
|
UBlockExpression
|
||||||
UIfExpression
|
UIfExpression
|
||||||
UBinaryExpression (operator = >)
|
UBinaryExpression (operator = >)
|
||||||
|
|||||||
+2
-1
@@ -24,7 +24,8 @@ public final class LambdaReturnKt {
|
|||||||
var lam5: kotlin.jvm.functions.Function1<? super java.lang.Integer,? extends java.lang.String> = fun (@org.jetbrains.annotations.NotNull var a: int) {
|
var lam5: kotlin.jvm.functions.Function1<? super java.lang.Integer,? extends java.lang.String> = fun (@org.jetbrains.annotations.NotNull var a: int) {
|
||||||
return "a" + a
|
return "a" + a
|
||||||
}
|
}
|
||||||
bar({
|
bar({ var it: int ->
|
||||||
|
|
||||||
if (it > 5) return
|
if (it > 5) return
|
||||||
var b: int = 1
|
var b: int = 1
|
||||||
return it + b
|
return it + b
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ UFile (package = )
|
|||||||
UIdentifier (Identifier (filter))
|
UIdentifier (Identifier (filter))
|
||||||
USimpleNameReferenceExpression (identifier = filter, resolvesTo = null)
|
USimpleNameReferenceExpression (identifier = filter, resolvesTo = null)
|
||||||
ULambdaExpression
|
ULambdaExpression
|
||||||
|
UParameter (name = it)
|
||||||
UBlockExpression
|
UBlockExpression
|
||||||
UReturnExpression
|
UReturnExpression
|
||||||
UQualifiedReferenceExpression
|
UQualifiedReferenceExpression
|
||||||
|
|||||||
+2
-1
@@ -2,7 +2,8 @@ import java.util.stream.Stream
|
|||||||
|
|
||||||
public final class LambdasKt {
|
public final class LambdasKt {
|
||||||
public static final fun foo() : void {
|
public static final fun foo() : void {
|
||||||
Stream.empty().filter({
|
Stream.empty().filter({ var it: java.lang.String ->
|
||||||
|
|
||||||
return it.isEmpty()
|
return it.isEmpty()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ UFile (package = )
|
|||||||
UIdentifier (Identifier (map))
|
UIdentifier (Identifier (map))
|
||||||
USimpleNameReferenceExpression (identifier = map, resolvesTo = null)
|
USimpleNameReferenceExpression (identifier = map, resolvesTo = null)
|
||||||
ULambdaExpression
|
ULambdaExpression
|
||||||
|
UParameter (name = it)
|
||||||
UBlockExpression
|
UBlockExpression
|
||||||
UReturnExpression
|
UReturnExpression
|
||||||
UQualifiedReferenceExpression
|
UQualifiedReferenceExpression
|
||||||
|
|||||||
+2
-1
@@ -12,7 +12,8 @@ public final class TypeReferencesKt {
|
|||||||
if (var708e23eb != null) var708e23eb else return
|
if (var708e23eb != null) var708e23eb else return
|
||||||
}
|
}
|
||||||
var tl: java.util.List<? extends T> = listOf(at)
|
var tl: java.util.List<? extends T> = listOf(at)
|
||||||
var tsl: java.util.List<? extends java.lang.String> = tl.map({
|
var tsl: java.util.List<? extends java.lang.String> = tl.map({ var it: T ->
|
||||||
|
|
||||||
return it.toString()
|
return it.toString()
|
||||||
})
|
})
|
||||||
var lls: java.util.List<? extends java.util.List<? extends java.lang.String>>
|
var lls: java.util.List<? extends java.util.List<? extends java.lang.String>>
|
||||||
|
|||||||
Reference in New Issue
Block a user