[uast] Make light parameter type building lazy in K2

Computing the type can be slow, and clients might not even need to access the type.

GitOrigin-RevId: 22df309ed18d77f07ae7d2dd2dcc994c79541f0b
This commit is contained in:
Bart van Helvert
2024-09-21 16:50:02 +00:00
committed by intellij-monorepo-bot
parent d3bf2e0e20
commit cf770b3acf
13 changed files with 181 additions and 178 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.light;
import com.intellij.lang.Language;
@@ -6,6 +6,8 @@ import com.intellij.psi.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public class LightParameter extends LightVariableBuilder<LightVariableBuilder<?>> implements PsiParameter {
private final PsiElement myDeclarationScope;
private final boolean myVarArgs;
@@ -29,6 +31,18 @@ public class LightParameter extends LightVariableBuilder<LightVariableBuilder<?>
myVarArgs = isVarArgs;
}
public LightParameter(
@NonNls @NotNull String name,
@NotNull PsiElement declarationScope,
@NotNull Supplier<? extends @NotNull PsiType> typeSupplier,
@NotNull Language language,
boolean isVarArgs
) {
super(declarationScope.getManager(), name, typeSupplier, language, new LightModifierList(declarationScope.getManager()));
myDeclarationScope = declarationScope;
myVarArgs = isVarArgs;
}
@Override
public @NotNull PsiElement getDeclarationScope() {
return myDeclarationScope;
@@ -15,10 +15,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.function.Supplier;
public class LightVariableBuilder<T extends LightVariableBuilder<?>> extends LightElement implements PsiVariable, NavigationItem, OriginInfoAwareElement {
private final String myName;
private final PsiType myType;
private final Supplier<? extends PsiType> myTypeSupplier;
private volatile LightModifierList myModifierList;
private volatile Icon myBaseIcon = IconManager.getInstance().getPlatformIcon(PlatformIcons.Variable);
private String myOriginInfo;
@@ -40,7 +41,19 @@ public class LightVariableBuilder<T extends LightVariableBuilder<?>> extends Lig
@NotNull Language language, @NotNull LightModifierList modifierList) {
super(manager, language);
myName = name;
myType = type;
myTypeSupplier = () -> type;
myModifierList = modifierList;
}
protected LightVariableBuilder(PsiManager manager,
@NotNull String name,
@NotNull Supplier<? extends @NotNull PsiType> typeSupplier,
@NotNull Language language,
@NotNull LightModifierList modifierList
) {
super(manager, language);
myName = name;
myTypeSupplier = typeSupplier;
myModifierList = modifierList;
}
@@ -60,7 +73,7 @@ public class LightVariableBuilder<T extends LightVariableBuilder<?>> extends Lig
@Override
public @NotNull PsiType getType() {
return myType;
return myTypeSupplier.get();
}
@Override
@@ -1,10 +1,12 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.psi.*
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiParameterList
import com.intellij.psi.impl.light.LightParameterListBuilder
import org.jetbrains.kotlin.psi.KtPropertyAccessor
import org.jetbrains.uast.UastErrorType
import org.jetbrains.uast.UastLazyPart
import org.jetbrains.uast.getOrBuild
@@ -29,18 +31,10 @@ internal class UastFakeSourceLightAccessor(
val parameterList = this
for ((i, p) in original.valueParameters.withIndex()) {
val type = baseResolveProviderService.getType(p, this@UastFakeSourceLightAccessor, isForFake = true)
?: UastErrorType
val adjustedType = if (p.isVarArg && type is PsiArrayType)
PsiEllipsisType(type.componentType, type.annotationProvider)
else type
this.addParameter(
addParameter(
UastKotlinPsiParameter(
baseResolveProviderService,
p.name ?: "p$i",
adjustedType,
parameterList,
original.language,
p.isVarArg,
p.defaultValue,
p
@@ -1,10 +1,12 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.psi.*
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiParameterList
import com.intellij.psi.impl.light.LightParameterListBuilder
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.uast.UastErrorType
import org.jetbrains.uast.UastLazyPart
import org.jetbrains.uast.getOrBuild
@@ -30,16 +32,8 @@ internal class UastFakeSourceLightDefaultAccessor(
val parameterList = this
if (isSetter) {
val type =
baseResolveProviderService.getType(
original,
this@UastFakeSourceLightDefaultAccessor,
isForFake = true
) ?: UastErrorType
val nullability = baseResolveProviderService.nullability(original)
this.addParameter(
UastKotlinPsiSetterParameter(type, parameterList, original, nullability)
)
addParameter(UastKotlinPsiSetterParameter(parameterList, original, nullability))
}
}
}
@@ -5,7 +5,6 @@ import com.intellij.psi.*
import com.intellij.psi.impl.light.LightParameterListBuilder
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.uast.UastErrorType
import org.jetbrains.uast.UastLazyPart
import org.jetbrains.uast.getOrBuild
@@ -27,16 +26,8 @@ internal class UastFakeSourceLightDefaultAccessorForConstructorParameter(
val parameterList = this
if (isSetter) {
val type =
baseResolveProviderService.getType(
original,
this@UastFakeSourceLightDefaultAccessorForConstructorParameter,
isForFake = true
) ?: UastErrorType
val nullability = baseResolveProviderService.nullability(original)
this.addParameter(
UastKotlinPsiSetterParameter(type, parameterList, original, nullability)
)
addParameter(UastKotlinPsiSetterParameter(parameterList, original, nullability))
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
@@ -8,7 +8,7 @@ import com.intellij.psi.impl.light.LightReferenceListBuilder
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.asJava.elements.KotlinLightTypeParameterBuilder
import org.jetbrains.kotlin.asJava.elements.KotlinLightTypeParameterListBuilder
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.uast.UastErrorType
import org.jetbrains.uast.UastLazyPart
import org.jetbrains.uast.getOrBuild
@@ -65,30 +65,24 @@ open class UastFakeSourceLightMethod(
val parameterList = this
original.receiverTypeReference?.let { receiver ->
this.addParameter(
addParameter(
UastKotlinPsiParameterBase(
"\$this\$${original.name}",
baseResolveProviderService.resolveToType(receiver, this@UastFakeSourceLightMethod)
?: UastErrorType,
parameterList,
receiver
)
receiver,
false,
null,
) {
baseResolveProviderService.resolveToType(receiver, this@UastFakeSourceLightMethod) ?: UastErrorType
}
)
}
for ((i, p) in original.valueParameters.withIndex()) {
val type = baseResolveProviderService.getType(p, this@UastFakeSourceLightMethod, isForFake = true)
?: UastErrorType
val adjustedType = if (p.isVarArg && type is PsiArrayType)
PsiEllipsisType(type.componentType, type.annotationProvider)
else type
this.addParameter(
addParameter(
UastKotlinPsiParameter(
baseResolveProviderService,
p.name ?: "p$i",
adjustedType,
parameterList,
original.language,
p.isVarArg,
p.defaultValue,
p
@@ -97,9 +91,7 @@ open class UastFakeSourceLightMethod(
}
if (isSuspendFunction()) {
this.addParameter(
UastKotlinPsiSuspendContinuationParameter.create(this@UastFakeSourceLightMethod, original)
)
addParameter(UastKotlinPsiSuspendContinuationParameter(this@UastFakeSourceLightMethod, original))
}
}
}
@@ -1,53 +1,51 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.lang.Language
import com.intellij.openapi.application.ApplicationManager
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiParameter
import com.intellij.psi.PsiType
import com.intellij.psi.*
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.asJava.elements.KtLightAnnotationForSourceEntry
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.uast.*
import org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService
/**
* Kotlin PSI parameter that can be used when the parameter doesn't exist in light classes.
*/
@ApiStatus.Internal
class UastKotlinPsiParameter internal constructor(
private val baseResolveProviderService: BaseKotlinUastResolveProviderService,
name: String,
type: PsiType,
parent: PsiElement,
language: Language,
isVarArgs: Boolean,
ktDefaultValue: KtExpression?,
ktParameter: KtParameter
) : UastKotlinPsiParameterBase<KtParameter>(name, type, parent, ktParameter, language, isVarArgs, ktDefaultValue) {
val ktParameter: KtParameter
) : UastKotlinPsiParameterBase<KtParameter>(name, parent, ktParameter, isVarArgs, ktDefaultValue, {
val containing = (if (parent is PsiParameterList) parent.parent else parent) as? PsiModifierListOwner
val baseResolveService = ApplicationManager.getApplication()
.getService(BaseKotlinUastResolveProviderService::class.java)
val type = baseResolveService.getType(ktParameter, containing, isForFake = true) ?: UastErrorType
if (isVarArgs && type is PsiArrayType) PsiEllipsisType(type.componentType, type.annotationProvider) else type
}) {
private val annotationsPart = UastLazyPart<Array<PsiAnnotation>>()
override val _annotations: Array<PsiAnnotation>
get() = annotationsPart.getOrBuild {
val annotations = SmartList<PsiAnnotation>()
val hasInheritedGenericType = baseResolveProviderService.hasInheritedGenericType(ktParameter)
override fun getAnnotations(): Array<PsiAnnotation> {
return annotationsPart.getOrBuild {
val annotations = mutableListOf<PsiAnnotation>()
val baseResolveService = ApplicationManager.getApplication()
.getService(BaseKotlinUastResolveProviderService::class.java)
val hasInheritedGenericType = baseResolveService.hasInheritedGenericType(ktParameter)
if (!hasInheritedGenericType) {
val nullability = baseResolveProviderService.nullability(ktParameter)
val nullability = baseResolveService.nullability(ktParameter)
if (nullability != null && nullability != KaTypeNullability.UNKNOWN) {
annotations.add(
UastFakeLightNullabilityAnnotation(nullability, this)
)
annotations.add(UastFakeLightNullabilityAnnotation(nullability, this))
}
}
ktParameter.annotationEntries.mapTo(annotations) { entry ->
KtLightAnnotationForSourceEntry(
name = entry.shortName?.identifier,
lazyQualifiedName = { baseResolveProviderService.qualifiedAnnotationName(entry) },
lazyQualifiedName = { baseResolveService.qualifiedAnnotationName(entry) },
kotlinOrigin = entry,
parent = ktParameter,
)
@@ -55,29 +53,23 @@ class UastKotlinPsiParameter internal constructor(
annotations.toTypedArray()
}
}
companion object {
fun create(
internal fun create(
parameter: KtParameter,
parent: PsiElement,
containingElement: UElement,
index: Int
): PsiParameter {
val service = ApplicationManager.getApplication().getService(BaseKotlinUastResolveProviderService::class.java)
val psiParent = containingElement.getParentOfType<UDeclaration>()?.javaPsi ?: parent
return UastKotlinPsiParameter(
service,
parameter.name ?: "p$index",
service.getType(parameter, containingElement) ?: UastErrorType,
psiParent,
KotlinLanguage.INSTANCE,
parameter.isVarArg,
parameter.defaultValue,
parameter
)
}
}
val ktParameter: KtParameter get() = ktOrigin
}
@@ -1,41 +1,40 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.lang.Language
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiType
import com.intellij.psi.impl.light.LightParameter
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.uast.UastLazyPart
import org.jetbrains.uast.getOrBuild
@ApiStatus.Internal
open class UastKotlinPsiParameterBase<T : KtElement>(
name: String,
type: PsiType,
private val parent: PsiElement,
val ktOrigin: T,
language: Language = ktOrigin.language,
isVarArgs: Boolean = false,
val ktDefaultValue: KtExpression? = null,
) : LightParameter(name, type, parent, language, isVarArgs) {
typeProvider: () -> PsiType,
) : LightParameter(name, parent, typeProvider, KotlinLanguage.INSTANCE, isVarArgs) {
protected val typePart = UastLazyPart<PsiType>()
protected open val _annotations: Array<PsiAnnotation> = arrayOf()
override fun getAnnotations(): Array<PsiAnnotation> {
return _annotations
}
override fun hasAnnotation(fqn: String): Boolean {
return _annotations.find { it.hasQualifiedName(fqn) } != null
override fun getType(): PsiType {
return typePart.getOrBuild { super.type }
}
override fun getParent(): PsiElement = parent
override fun getContainingFile(): PsiFile? = ktOrigin.containingFile
override fun hasAnnotation(fqn: String): Boolean {
return annotations.any { annotation -> annotation.qualifiedName == fqn }
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class.java != this::class.java) return false
@@ -1,40 +1,45 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.openapi.application.ApplicationManager
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiType
import com.intellij.psi.PsiModifierListOwner
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.uast.UastErrorType
import org.jetbrains.uast.UastLazyPart
import org.jetbrains.uast.getOrBuild
import org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService
@ApiStatus.Internal
class UastKotlinPsiSetterParameter<T : KtCallableDeclaration> internal constructor(
parameterType: PsiType,
parent: PsiElement,
ktOrigin: T,
private val nullability: KaTypeNullability?,
) : UastKotlinPsiParameterBase<T>(
name = SpecialNames.IMPLICIT_SET_PARAMETER.asString(),
type = parameterType,
parent = parent,
ktOrigin = ktOrigin,
language = ktOrigin.language,
isVarArgs = false,
ktDefaultValue = null
ktDefaultValue = null,
typeProvider = {
val baseResolveService = ApplicationManager.getApplication()
.getService(BaseKotlinUastResolveProviderService::class.java)
baseResolveService.getType(ktOrigin, parent.parent as PsiModifierListOwner, isForFake = true) ?: UastErrorType
}
) {
private val annotationsPart = UastLazyPart<Array<PsiAnnotation>>()
override val _annotations: Array<PsiAnnotation>
get() = annotationsPart.getOrBuild {
override fun getAnnotations(): Array<PsiAnnotation> {
return annotationsPart.getOrBuild {
if (nullability != null) {
arrayOf(UastFakeLightNullabilityAnnotation(nullability, this))
} else {
arrayOf()
}
}
}
}
@@ -1,8 +1,10 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.openapi.application.ApplicationManager
import com.intellij.psi.*
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierListOwner
import com.intellij.psi.PsiTypes
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME
@@ -12,36 +14,26 @@ import org.jetbrains.uast.getOrBuild
import org.jetbrains.uast.kotlin.BaseKotlinUastResolveProviderService
@ApiStatus.Internal
class UastKotlinPsiSuspendContinuationParameter private constructor(
parameterType: PsiType,
parent: PsiElement,
class UastKotlinPsiSuspendContinuationParameter internal constructor(
private val parent: PsiModifierListOwner,
suspendFunction: KtFunction,
) : UastKotlinPsiParameterBase<KtFunction>(
name = SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME,
type = parameterType,
parent = parent,
ktOrigin = suspendFunction,
language = suspendFunction.language,
isVarArgs = false,
ktDefaultValue = null
ktDefaultValue = null,
{
val service = ApplicationManager.getApplication()
.getService(BaseKotlinUastResolveProviderService::class.java)
service.getSuspendContinuationType(suspendFunction, parent) ?: PsiTypes.nullType()
}
) {
private val annotationsPart = UastLazyPart<Array<PsiAnnotation>>()
override val _annotations: Array<PsiAnnotation>
get() = annotationsPart.getOrBuild {
arrayOf(
UastFakeLightNullabilityAnnotation(KaTypeNullability.NON_NULLABLE, this)
)
}
companion object {
fun create(
parent: PsiModifierListOwner,
suspendFunction: KtFunction,
): PsiParameter {
val service = ApplicationManager.getApplication().getService(BaseKotlinUastResolveProviderService::class.java)
val parameterType = service.getSuspendContinuationType(suspendFunction, parent) ?: PsiTypes.nullType()
return UastKotlinPsiSuspendContinuationParameter(parameterType, parent, suspendFunction)
override fun getAnnotations(): Array<PsiAnnotation> {
return annotationsPart.getOrBuild {
arrayOf(UastFakeLightNullabilityAnnotation(KaTypeNullability.NON_NULLABLE, this))
}
}
}
@@ -133,47 +133,51 @@ interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderSer
): List<KotlinUParameter> {
analyzeForUast(ktLambdaExpression) {
val anonymousFunctionSymbol = ktLambdaExpression.functionLiteral.symbol
val anonymousFunctionSymbolPtr = anonymousFunctionSymbol.createPointer()
val parameters = mutableListOf<KotlinUParameter>()
if (includeExplicitParameters && anonymousFunctionSymbol.receiverParameter != null) {
val lambdaImplicitReceiverType = anonymousFunctionSymbol.receiverParameter!!.type.asPsiType(
ktLambdaExpression,
allowErrorTypes = false,
KaTypeMappingMode.DEFAULT_UAST,
isAnnotationMethod = false
) ?: UastErrorType
parameters.add(
KotlinUParameter(
UastKotlinPsiParameterBase(
name = LAMBDA_THIS_PARAMETER_NAME,
type = lambdaImplicitReceiverType,
parent = ktLambdaExpression,
ktOrigin = ktLambdaExpression,
language = ktLambdaExpression.language,
isVarArgs = false,
ktDefaultValue = null
),
) {
analyzeForUast(ktLambdaExpression) {
anonymousFunctionSymbolPtr.restoreSymbol()?.receiverParameter?.returnType?.asPsiType(
ktLambdaExpression,
allowErrorTypes = false,
KaTypeMappingMode.DEFAULT_UAST,
isAnnotationMethod = false
) ?: UastErrorType
}
},
sourcePsi = null,
parent
)
)
}
anonymousFunctionSymbol.valueParameters.mapTo(parameters) { p ->
val psiType = p.returnType.asPsiType(
ktLambdaExpression,
allowErrorTypes = false,
KaTypeMappingMode.DEFAULT_UAST,
isAnnotationMethod = false
) ?: UastErrorType
anonymousFunctionSymbol.valueParameters.mapTo(parameters) { paramSymbol ->
val paramSymbolPtr = paramSymbol.createPointer()
KotlinUParameter(
UastKotlinPsiParameterBase(
name = p.name.asString(),
type = psiType,
name = paramSymbol.name.asString(),
parent = ktLambdaExpression,
ktOrigin = ktLambdaExpression,
language = ktLambdaExpression.language,
isVarArgs = p.isVararg,
isVarArgs = paramSymbol.isVararg,
ktDefaultValue = null
),
) {
analyzeForUast(ktLambdaExpression) {
paramSymbolPtr.restoreSymbol()?.returnType?.asPsiType(
ktLambdaExpression,
allowErrorTypes = false,
KaTypeMappingMode.DEFAULT_UAST,
isAnnotationMethod = false
) ?: UastErrorType
}
},
null,
parent
)
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin.psi
import com.intellij.psi.*
@@ -159,29 +159,43 @@ constructor(
analyzeForUast(context) l@{
val functionSymbol = original.restoreSymbol() ?: return@l
val functionSymbolPtr = functionSymbol.createPointer()
(functionSymbol.receiverParameter?.psi as? KtTypeReference)?.let { receiver ->
parameterList.addParameter(
UastKotlinPsiParameterBase(
"\$this\$$name",
functionSymbol.receiverType?.asPsiType(context, allowErrorTypes = true) ?: UastErrorType,
parameterList,
receiver
)
isVarArgs = false,
ktDefaultValue = null,
ktOrigin = receiver
) {
analyzeForUast(context) {
functionSymbolPtr.restoreSymbol()
?.receiverType
?.asPsiType(context, allowErrorTypes = true)
?: UastErrorType
}
}
)
}
for (p in functionSymbol.valueParameters) {
val type = p.returnType.asPsiType(context, allowErrorTypes = true) ?: UastErrorType
val adjustedType = if (p.isVararg && type is PsiArrayType)
PsiEllipsisType(type.componentType, type.annotationProvider)
else type
for (valueParamSymbol in functionSymbol.valueParameters) {
val valueParamSymbolPtr = valueParamSymbol.createPointer()
parameterList.addParameter(
UastKotlinPsiParameterBase(
p.name.identifier,
adjustedType,
valueParamSymbol.name.identifier,
parameterList,
(p.psi as? KtElement) ?: context
)
isVarArgs = false,
ktDefaultValue = null,
ktOrigin = (valueParamSymbol.psi as? KtElement) ?: context
) {
analyzeForUast(context) {
valueParamSymbolPtr.restoreSymbol()
?.returnType
?.asPsiType(context, allowErrorTypes = true)
?: UastErrorType
}
}
)
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.uast.kotlin
@@ -149,17 +149,16 @@ interface KotlinUastResolveProviderService : BaseKotlinUastResolveProviderServic
val parameters = if (includeExplicitParameters) functionDescriptor.explicitParameters else functionDescriptor.valueParameters
return parameters.map { p ->
return parameters.map { param ->
val type = param.type.toPsiType(parent, ktLambdaExpression, PsiTypeConversionConfiguration.create(ktLambdaExpression))
KotlinUParameter(
UastKotlinPsiParameterBase(
name = p.name.asString(),
type = p.type.toPsiType(parent, ktLambdaExpression, PsiTypeConversionConfiguration.create(ktLambdaExpression)),
name = param.name.asString(),
parent = ktLambdaExpression,
ktOrigin = ktLambdaExpression,
language = ktLambdaExpression.language,
isVarArgs = p.isVararg,
ktDefaultValue = null
),
isVarArgs = param.isVararg,
ktDefaultValue = null,
ktOrigin = ktLambdaExpression
) { type },
null,
parent
)