Uast: include parameters of reified methods to uast tree (KT-37613)
This commit is contained in:
@@ -34,6 +34,7 @@ import org.jetbrains.uast.*
|
|||||||
import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionULambdaExpression
|
import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionULambdaExpression
|
||||||
import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression
|
import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression
|
||||||
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||||
|
|
||||||
abstract class KotlinAbstractUElement(private val givenParent: UElement?) : KotlinUElementWithComments,
|
abstract class KotlinAbstractUElement(private val givenParent: UElement?) : KotlinUElementWithComments,
|
||||||
@@ -86,16 +87,16 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl
|
|||||||
?: parent
|
?: parent
|
||||||
AnnotationUseSiteTarget.FIELD ->
|
AnnotationUseSiteTarget.FIELD ->
|
||||||
parent = (parentUnwrapped as? KtProperty)
|
parent = (parentUnwrapped as? KtProperty)
|
||||||
?: (parentUnwrapped as? KtParameter)
|
?: (parentUnwrapped as? KtParameter)
|
||||||
?.takeIf { it.isPropertyParameter() }
|
?.takeIf { it.isPropertyParameter() }
|
||||||
?.let(LightClassUtil::getLightClassBackingField)
|
?.let(LightClassUtil::getLightClassBackingField)
|
||||||
?: parent
|
?: parent
|
||||||
AnnotationUseSiteTarget.SETTER_PARAMETER ->
|
AnnotationUseSiteTarget.SETTER_PARAMETER ->
|
||||||
parent = (parentUnwrapped as? KtParameter)
|
parent = (parentUnwrapped as? KtParameter)
|
||||||
?.toLightSetter()?.parameterList?.parameters?.firstOrNull() ?: parent
|
?.toLightSetter()?.parameterList?.parameters?.firstOrNull() ?: parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (psi is UastKotlinPsiVariable && parent != null) {
|
if ((psi is UastKotlinPsiVariable || psi is UastKotlinPsiParameter) && parent != null) {
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier
|
|||||||
import org.jetbrains.uast.kotlin.declarations.KotlinUMethod
|
import org.jetbrains.uast.kotlin.declarations.KotlinUMethod
|
||||||
import org.jetbrains.uast.kotlin.declarations.KotlinUMethodWithFakeLightDelegate
|
import org.jetbrains.uast.kotlin.declarations.KotlinUMethodWithFakeLightDelegate
|
||||||
import org.jetbrains.uast.kotlin.expressions.*
|
import org.jetbrains.uast.kotlin.expressions.*
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastFakeLightMethod
|
||||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||||
|
|
||||||
@@ -487,6 +488,7 @@ internal object KotlinConverter {
|
|||||||
return with(expectedTypes) {
|
return with(expectedTypes) {
|
||||||
when (original) {
|
when (original) {
|
||||||
is KtLightMethod -> el<UMethod>(build(KotlinUMethod.Companion::create)) // .Companion is needed because of KT-13934
|
is KtLightMethod -> el<UMethod>(build(KotlinUMethod.Companion::create)) // .Companion is needed because of KT-13934
|
||||||
|
is UastFakeLightMethod -> el<UMethod> { KotlinUMethodWithFakeLightDelegate(original.original, original, givenParent) }
|
||||||
is KtLightClass -> when (original.kotlinOrigin) {
|
is KtLightClass -> when (original.kotlinOrigin) {
|
||||||
is KtEnumEntry -> el<UEnumConstant> {
|
is KtEnumEntry -> el<UEnumConstant> {
|
||||||
convertEnumEntry(original.kotlinOrigin as KtEnumEntry, givenParent)
|
convertEnumEntry(original.kotlinOrigin as KtEnumEntry, givenParent)
|
||||||
@@ -526,9 +528,7 @@ internal object KotlinConverter {
|
|||||||
if (lightMethod != null)
|
if (lightMethod != null)
|
||||||
convertDeclaration(lightMethod, givenParent, expectedTypes)
|
convertDeclaration(lightMethod, givenParent, expectedTypes)
|
||||||
else {
|
else {
|
||||||
val ktLightClass = original.containingClassOrObject?.toLightClass()
|
val ktLightClass = getLightClassForFakeMethod(original) ?: return null
|
||||||
?: original.containingKtFile.findFacadeClass()
|
|
||||||
?: return null
|
|
||||||
KotlinUMethodWithFakeLightDelegate(original, ktLightClass, givenParent)
|
KotlinUMethodWithFakeLightDelegate(original, ktLightClass, givenParent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -564,6 +564,10 @@ internal object KotlinConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getLightClassForFakeMethod(original: KtFunction): KtLightClass? {
|
||||||
|
if (original.isLocal) return null
|
||||||
|
return (original.containingClassOrObject?.toLightClass() ?: original.containingKtFile.findFacadeClass())
|
||||||
|
}
|
||||||
|
|
||||||
fun convertDeclarationOrElement(
|
fun convertDeclarationOrElement(
|
||||||
element: PsiElement,
|
element: PsiElement,
|
||||||
@@ -613,6 +617,9 @@ internal object KotlinConverter {
|
|||||||
alternative uParam@{
|
alternative uParam@{
|
||||||
val lightMethod = when (val ownerFunction = element.ownerFunction) {
|
val lightMethod = when (val ownerFunction = element.ownerFunction) {
|
||||||
is KtFunction -> LightClassUtil.getLightClassMethod(ownerFunction)
|
is KtFunction -> LightClassUtil.getLightClassMethod(ownerFunction)
|
||||||
|
?: getLightClassForFakeMethod(ownerFunction)
|
||||||
|
?.takeIf { !it.isAnnotationType }
|
||||||
|
?.let { UastFakeLightMethod(ownerFunction, it) }
|
||||||
is KtPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(ownerFunction)
|
is KtPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(ownerFunction)
|
||||||
else -> null
|
else -> null
|
||||||
} ?: return@uParam null
|
} ?: return@uParam null
|
||||||
|
|||||||
@@ -17,21 +17,16 @@
|
|||||||
package org.jetbrains.uast.kotlin.declarations
|
package org.jetbrains.uast.kotlin.declarations
|
||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.impl.light.LightMethodBuilder
|
|
||||||
import com.intellij.psi.impl.light.LightModifierList
|
|
||||||
import com.intellij.psi.impl.light.LightParameterListBuilder
|
|
||||||
import com.intellij.psi.impl.light.LightTypeParameterBuilder
|
|
||||||
import org.jetbrains.kotlin.asJava.elements.*
|
import org.jetbrains.kotlin.asJava.elements.*
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
||||||
import org.jetbrains.uast.kotlin.*
|
import org.jetbrains.uast.kotlin.*
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastFakeLightMethod
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||||
|
|
||||||
open class KotlinUMethod(
|
open class KotlinUMethod(
|
||||||
psi: PsiMethod,
|
psi: PsiMethod,
|
||||||
@@ -70,7 +65,13 @@ open class KotlinUMethod(
|
|||||||
override val uastParameters by lz {
|
override val uastParameters by lz {
|
||||||
val lightParams = psi.parameterList.parameters
|
val lightParams = psi.parameterList.parameters
|
||||||
val receiver = receiver ?: return@lz lightParams.map {
|
val receiver = receiver ?: return@lz lightParams.map {
|
||||||
KotlinUParameter(it, (it as? KtLightElement<*, *>)?.kotlinOrigin, this)
|
KotlinUParameter(
|
||||||
|
it, when (it) {
|
||||||
|
is KtLightElement<*, *> -> it.kotlinOrigin
|
||||||
|
is UastKotlinPsiParameter -> it.ktParameter
|
||||||
|
else -> null
|
||||||
|
}, this
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val receiverLight = lightParams.firstOrNull() ?: return@lz emptyList<UParameter>()
|
val receiverLight = lightParams.firstOrNull() ?: return@lz emptyList<UParameter>()
|
||||||
val uParameters = SmartList<UParameter>(KotlinReceiverUParameter(receiverLight, receiver, this))
|
val uParameters = SmartList<UParameter>(KotlinReceiverUParameter(receiverLight, receiver, this))
|
||||||
@@ -158,50 +159,15 @@ open class KotlinUAnnotationMethod(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UastFakeLightMethod(private val original: KtFunction, containingClass: PsiClass) : LightMethodBuilder(
|
class KotlinUMethodWithFakeLightDelegate internal constructor(
|
||||||
original.manager, original.language, original.name ?: "<no name provided>",
|
val original: KtFunction,
|
||||||
LightParameterListBuilder(original.manager, original.language),
|
fakePsi: UastFakeLightMethod,
|
||||||
LightModifierList(original.manager)
|
givenParent: UElement?
|
||||||
) {
|
) : KotlinUMethod(fakePsi, original, givenParent) {
|
||||||
|
|
||||||
init {
|
constructor(original: KtFunction, containingLightClass: PsiClass, givenParent: UElement?)
|
||||||
this.containingClass = containingClass
|
: this(original, UastFakeLightMethod(original, containingLightClass), givenParent)
|
||||||
}
|
|
||||||
|
|
||||||
private val _buildTypeParameterList by lazy {
|
|
||||||
KotlinLightTypeParameterListBuilder(this).also { paramList ->
|
|
||||||
for ((i, p) in original.typeParameters.withIndex()) {
|
|
||||||
paramList.addParameter(LightTypeParameterBuilder(p.name ?: "__no_name__", this, i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTypeParameterList(): PsiTypeParameterList? = _buildTypeParameterList
|
|
||||||
|
|
||||||
override fun getReturnType(): PsiType? {
|
|
||||||
val context = original.analyze()
|
|
||||||
val descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, original).safeAs<CallableDescriptor>() ?: return null
|
|
||||||
return descriptor.returnType?.toPsiType(this, original, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getParent(): PsiElement? = containingClass
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as UastFakeLightMethod
|
|
||||||
|
|
||||||
if (original != other.original) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = original.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
class KotlinUMethodWithFakeLightDelegate(val original: KtFunction, containingLightClass: PsiClass, givenParent: UElement?) :
|
|
||||||
KotlinUMethod(UastFakeLightMethod(original, containingLightClass), original, givenParent) {
|
|
||||||
override val annotations: List<UAnnotation>
|
override val annotations: List<UAnnotation>
|
||||||
get() = original.annotationEntries.mapNotNull { it.toUElementOfType<UAnnotation>() }
|
get() = original.annotationEntries.mapNotNull { it.toUElementOfType<UAnnotation>() }
|
||||||
|
|
||||||
|
|||||||
+16
-50
@@ -17,22 +17,17 @@
|
|||||||
package org.jetbrains.uast.kotlin.declarations
|
package org.jetbrains.uast.kotlin.declarations
|
||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.impl.light.LightMethodBuilder
|
|
||||||
import com.intellij.psi.impl.light.LightModifierList
|
|
||||||
import com.intellij.psi.impl.light.LightParameterListBuilder
|
|
||||||
import com.intellij.psi.impl.light.LightTypeParameterBuilder
|
|
||||||
import org.jetbrains.kotlin.asJava.elements.*
|
import org.jetbrains.kotlin.asJava.elements.*
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
||||||
import org.jetbrains.uast.kotlin.*
|
import org.jetbrains.uast.kotlin.*
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastFakeLightMethod
|
||||||
|
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||||
|
|
||||||
open class KotlinUMethod(
|
open class KotlinUMethod(
|
||||||
psi: PsiMethod,
|
psi: PsiMethod,
|
||||||
@@ -71,7 +66,13 @@ open class KotlinUMethod(
|
|||||||
override val uastParameters by lz {
|
override val uastParameters by lz {
|
||||||
val lightParams = psi.parameterList.parameters
|
val lightParams = psi.parameterList.parameters
|
||||||
val receiver = receiver ?: return@lz lightParams.map {
|
val receiver = receiver ?: return@lz lightParams.map {
|
||||||
KotlinUParameter(it, (it as? KtLightElement<*, *>)?.kotlinOrigin, this)
|
KotlinUParameter(
|
||||||
|
it, when (it) {
|
||||||
|
is KtLightElement<*, *> -> it.kotlinOrigin
|
||||||
|
is UastKotlinPsiParameter -> it.ktParameter
|
||||||
|
else -> null
|
||||||
|
}, this
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val receiverLight = lightParams.firstOrNull() ?: return@lz emptyList<UParameter>()
|
val receiverLight = lightParams.firstOrNull() ?: return@lz emptyList<UParameter>()
|
||||||
val uParameters = SmartList<UParameter>(KotlinReceiverUParameter(receiverLight, receiver, this))
|
val uParameters = SmartList<UParameter>(KotlinReceiverUParameter(receiverLight, receiver, this))
|
||||||
@@ -161,50 +162,15 @@ open class KotlinUAnnotationMethod(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UastFakeLightMethod(private val original: KtFunction, containingClass: PsiClass) : LightMethodBuilder(
|
class KotlinUMethodWithFakeLightDelegate internal constructor(
|
||||||
original.manager, original.language, original.name,
|
val original: KtFunction,
|
||||||
LightParameterListBuilder(original.manager, original.language),
|
fakePsi: UastFakeLightMethod,
|
||||||
LightModifierList(original.manager)
|
givenParent: UElement?
|
||||||
) {
|
) : KotlinUMethod(fakePsi, original, givenParent) {
|
||||||
|
|
||||||
init {
|
constructor(original: KtFunction, containingLightClass: PsiClass, givenParent: UElement?)
|
||||||
this.containingClass = containingClass
|
: this(original, UastFakeLightMethod(original, containingLightClass), givenParent)
|
||||||
}
|
|
||||||
|
|
||||||
private val _buildTypeParameterList by lazy {
|
|
||||||
KotlinLightTypeParameterListBuilder(this).also { paramList ->
|
|
||||||
for ((i, p) in original.typeParameters.withIndex()) {
|
|
||||||
paramList.addParameter(LightTypeParameterBuilder(p.name ?: "__no_name__", this, i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTypeParameterList(): PsiTypeParameterList? = _buildTypeParameterList
|
|
||||||
|
|
||||||
override fun getReturnType(): PsiType? {
|
|
||||||
val context = original.analyze()
|
|
||||||
val descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, original).safeAs<CallableDescriptor>() ?: return null
|
|
||||||
return descriptor.returnType?.toPsiType(this, original, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getParent(): PsiElement? = containingClass
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as UastFakeLightMethod
|
|
||||||
|
|
||||||
if (original != other.original) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = original.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
class KotlinUMethodWithFakeLightDelegate(val original: KtFunction, containingLightClass: PsiClass, givenParent: UElement?) :
|
|
||||||
KotlinUMethod(UastFakeLightMethod(original, containingLightClass), original, givenParent) {
|
|
||||||
override val annotations: List<UAnnotation>
|
override val annotations: List<UAnnotation>
|
||||||
get() = original.annotationEntries.mapNotNull { it.toUElementOfType<UAnnotation>() }
|
get() = original.annotationEntries.mapNotNull { it.toUElementOfType<UAnnotation>() }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.uast.kotlin.psi
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.impl.light.LightMethodBuilder
|
||||||
|
import com.intellij.psi.impl.light.LightModifierList
|
||||||
|
import com.intellij.psi.impl.light.LightParameterListBuilder
|
||||||
|
import com.intellij.psi.impl.light.LightTypeParameterBuilder
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KotlinLightTypeParameterListBuilder
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
|
import org.jetbrains.kotlin.psi.KtFunction
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
import org.jetbrains.uast.UastErrorType
|
||||||
|
import org.jetbrains.uast.kotlin.analyze
|
||||||
|
import org.jetbrains.uast.kotlin.getType
|
||||||
|
import org.jetbrains.uast.kotlin.toPsiType
|
||||||
|
|
||||||
|
internal class UastFakeLightMethod(internal val original: KtFunction, containingClass: PsiClass) : LightMethodBuilder(
|
||||||
|
original.manager, original.language, original.name ?: "<no name provided>",
|
||||||
|
LightParameterListBuilder(original.manager, original.language),
|
||||||
|
LightModifierList(original.manager)
|
||||||
|
) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.containingClass = containingClass
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _buildTypeParameterList by lazy {
|
||||||
|
KotlinLightTypeParameterListBuilder(this).also { paramList ->
|
||||||
|
for ((i, p) in original.typeParameters.withIndex()) {
|
||||||
|
paramList.addParameter(
|
||||||
|
LightTypeParameterBuilder(
|
||||||
|
p.name ?: "__no_name__",
|
||||||
|
this,
|
||||||
|
i
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getTypeParameterList(): PsiTypeParameterList? = _buildTypeParameterList
|
||||||
|
|
||||||
|
private val paramsList: PsiParameterList by lazy {
|
||||||
|
object : LightParameterListBuilder(original.manager, original.language) {
|
||||||
|
override fun getParent(): PsiElement = this@UastFakeLightMethod
|
||||||
|
override fun getContainingFile(): PsiFile = parent.containingFile
|
||||||
|
|
||||||
|
init {
|
||||||
|
val parameterList = this
|
||||||
|
for ((i, p) in original.valueParameters.withIndex()) {
|
||||||
|
this.addParameter(
|
||||||
|
UastKotlinPsiParameter(
|
||||||
|
p.name ?: "p$i",
|
||||||
|
p.typeReference?.getType()
|
||||||
|
?.toPsiType(this@UastFakeLightMethod, original, false)
|
||||||
|
?: UastErrorType,
|
||||||
|
parameterList, original.language, p.isVarArg, p.defaultValue, p
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getParameterList(): PsiParameterList = paramsList
|
||||||
|
|
||||||
|
override fun getReturnType(): PsiType? {
|
||||||
|
val context = original.analyze()
|
||||||
|
val descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, original).safeAs<CallableDescriptor>() ?: return null
|
||||||
|
return descriptor.returnType?.toPsiType(this, original, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getParent(): PsiElement? = containingClass
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as UastFakeLightMethod
|
||||||
|
|
||||||
|
if (original != other.original) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = original.hashCode()
|
||||||
|
}
|
||||||
@@ -19,13 +19,13 @@ import org.jetbrains.uast.kotlin.analyze
|
|||||||
import org.jetbrains.uast.kotlin.toPsiType
|
import org.jetbrains.uast.kotlin.toPsiType
|
||||||
|
|
||||||
class UastKotlinPsiParameter(
|
class UastKotlinPsiParameter(
|
||||||
name: String,
|
name: String,
|
||||||
type: PsiType,
|
type: PsiType,
|
||||||
parent: PsiElement,
|
private val parent: PsiElement,
|
||||||
language: Language,
|
language: Language,
|
||||||
isVarArgs: Boolean,
|
isVarArgs: Boolean,
|
||||||
val ktDefaultValue: KtExpression?,
|
val ktDefaultValue: KtExpression?,
|
||||||
val ktParameter: KtParameter
|
val ktParameter: KtParameter
|
||||||
) : LightParameter(name, type, parent, language, isVarArgs) {
|
) : LightParameter(name, type, parent, language, isVarArgs) {
|
||||||
companion object {
|
companion object {
|
||||||
fun create(parameter: KtParameter, parent: PsiElement, containingElement: UElement, index: Int): PsiParameter {
|
fun create(parameter: KtParameter, parent: PsiElement, containingElement: UElement, index: Int): PsiParameter {
|
||||||
@@ -42,6 +42,8 @@ class UastKotlinPsiParameter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getParent(): PsiElement = parent
|
||||||
|
|
||||||
override fun getContainingFile(): PsiFile? = ktParameter.containingFile
|
override fun getContainingFile(): PsiFile? = ktParameter.containingFile
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
inline fun <reified T> functionWithLambda(t: T, process: (T) -> Int): Int = process(t)
|
||||||
|
|
||||||
|
inline fun <reified T> functionWithVararg(i: Int?, vararg t: T): T = t[0]
|
||||||
|
|
||||||
|
inline fun <reified T> functionWithParamAnnotation(@Suppress("s") t: T): T = t
|
||||||
|
|
||||||
|
inline fun <reified T> functionUnresolved(@Suppress("s") t: Unresolved<T>): T = t
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
UFile (package = )
|
||||||
|
UClass (name = ReifiedParametersKt)
|
||||||
|
UMethod (name = functionWithLambda)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = process)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
|
||||||
|
UIdentifier (Identifier (process))
|
||||||
|
USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null)
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = functionWithVararg)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
UArrayAccessExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
ULiteralExpression (value = 0)
|
||||||
|
UMethod (name = functionWithParamAnnotation)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UAnnotation (fqName = kotlin.Suppress)
|
||||||
|
UNamedExpression (name = names)
|
||||||
|
UPolyadicExpression (operator = +)
|
||||||
|
ULiteralExpression (value = "s")
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = functionUnresolved)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UAnnotation (fqName = kotlin.Suppress)
|
||||||
|
UNamedExpression (name = names)
|
||||||
|
UPolyadicExpression (operator = +)
|
||||||
|
ULiteralExpression (value = "s")
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
public final class ReifiedParametersKt {
|
||||||
|
fun functionWithLambda(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull process: kotlin.jvm.functions.Function1<? super T,? extends java.lang.Integer>) : int {
|
||||||
|
return invoke(t)
|
||||||
|
}
|
||||||
|
fun functionWithVararg(@org.jetbrains.annotations.Nullable i: int, @org.jetbrains.annotations.Nullable t: T) : T {
|
||||||
|
return t[0]
|
||||||
|
}
|
||||||
|
fun functionWithParamAnnotation(@org.jetbrains.annotations.Nullable @kotlin.Suppress(names = "s") t: T) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun functionUnresolved(@org.jetbrains.annotations.NotNull @kotlin.Suppress(names = "s") t: <ErrorType>) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-11
@@ -1,11 +1,11 @@
|
|||||||
inline fun <T> function1(t: T) {}
|
inline fun <T> function1(t: T, i: Int, s: String) {}
|
||||||
inline fun <T> function2(t: T): T = t
|
inline fun <T> function2(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> function3(t: T) {}
|
inline fun <reified T> function3(t: T, i: Int, s: String) {}
|
||||||
inline fun <reified T> function4(t: T): T = t
|
inline fun <reified T> function4(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> function5(t: T): Int = 42
|
inline fun <reified T> function5(t: T, i: Int, s: String): Int = 42
|
||||||
inline fun <reified T : Activity> T.function6(t: T): T = t
|
inline fun <reified T : Activity> T.function6(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> function7(t: T): T = t
|
inline fun <reified T> function7(t: T, i: Int, s: String): T = t
|
||||||
private inline fun <reified T> function8(t: T): T = t
|
private inline fun <reified T> function8(t: T, i: Int, s: String): T = t
|
||||||
internal inline fun <reified T> function9(t: T): T = t
|
internal inline fun <reified T> function9(t: T, i: Int, s: String): T = t
|
||||||
public inline fun <reified T> function10(t: T): T = t
|
public inline fun <reified T> function10(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> T.function11(t: T): T = t
|
inline fun <reified T> T.function11(t: T, i: Int, s: String): T = t
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
UFile (package = )
|
||||||
|
UClass (name = ReifiedReturnTypeKt)
|
||||||
|
UMethod (name = function1)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UMethod (name = function2)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function3)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UMethod (name = function4)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function5)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
ULiteralExpression (value = 42)
|
||||||
|
UMethod (name = function6)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UParameter (name = s)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function7)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function8)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function9)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function10)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function11)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UParameter (name = i)
|
||||||
|
UParameter (name = s)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
public final class ReifiedReturnTypeKt {
|
||||||
|
public static final fun function1(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : void {
|
||||||
|
}
|
||||||
|
public static final fun function2(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function3(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : void {
|
||||||
|
}
|
||||||
|
fun function4(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function5(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : int {
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
fun function6(@org.jetbrains.annotations.Nullable t: T, i: int, s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function7(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function8(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function9(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function10(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fun function11(@org.jetbrains.annotations.Nullable t: T, i: int, s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,6 @@ class KotlinIDERenderLogTest : AbstractKotlinUastLightCodeInsightFixtureTest(),
|
|||||||
|
|
||||||
override fun check(testName: String, file: UFile) = super.check(testName, file)
|
override fun check(testName: String, file: UFile) = super.check(testName, file)
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLocalDeclarations() = doTest("LocalDeclarations")
|
fun testLocalDeclarations() = doTest("LocalDeclarations")
|
||||||
|
|
||||||
@@ -153,6 +152,12 @@ class KotlinIDERenderLogTest : AbstractKotlinUastLightCodeInsightFixtureTest(),
|
|||||||
@Test
|
@Test
|
||||||
fun testReified() = doTest("Reified")
|
fun testReified() = doTest("Reified")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReifiedReturnType() = doTest("ReifiedReturnType")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReifiedParameters() = doTest("ReifiedParameters")
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSuspend() = doTest("Suspend")
|
fun testSuspend() = doTest("Suspend")
|
||||||
|
|
||||||
|
|||||||
@@ -644,6 +644,33 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReifiedParameters() {
|
||||||
|
doTest("ReifiedParameters") { _, file ->
|
||||||
|
val methods = file.classes.flatMap { it.methods.asIterable() }
|
||||||
|
|
||||||
|
for (method in methods) {
|
||||||
|
assertNotNull("method ${method.name} should have source", method.sourcePsi)
|
||||||
|
assertEquals("method ${method.name} should be equals to converted from sourcePsi", method, method.sourcePsi.toUElement())
|
||||||
|
assertEquals("method ${method.name} should be equals to converted from javaPsi", method, method.javaPsi.toUElement())
|
||||||
|
|
||||||
|
for (parameter in method.uastParameters) {
|
||||||
|
assertNotNull("parameter ${parameter.name} should have source", parameter.sourcePsi)
|
||||||
|
assertEquals(
|
||||||
|
"parameter ${parameter.name} of method ${method.name} should be equals to converted from sourcePsi",
|
||||||
|
parameter,
|
||||||
|
parameter.sourcePsi.toUElement()
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"parameter ${parameter.name} of method ${method.name} should be equals to converted from javaPsi",
|
||||||
|
parameter,
|
||||||
|
parameter.javaPsi.toUElement()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T, R> Iterable<T>.assertedFind(value: R, transform: (T) -> R): T =
|
fun <T, R> Iterable<T>.assertedFind(value: R, transform: (T) -> R): T =
|
||||||
|
|||||||
@@ -130,6 +130,12 @@ class SimpleKotlinRenderLogTest : AbstractKotlinUastTest(), AbstractKotlinRender
|
|||||||
@Test
|
@Test
|
||||||
fun testReified() = doTest("Reified")
|
fun testReified() = doTest("Reified")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReifiedReturnType() = doTest("ReifiedReturnType")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReifiedParameters() = doTest("ReifiedParameters")
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSuspend() = doTest("Suspend")
|
fun testSuspend() = doTest("Suspend")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user