[cls] save parameter name for functional types in stub
to make it available for deserialized Fir
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
class ParameterName {
|
||||
inline fun <A, B> foo(crossinline block: (input: A, state: B) -> Unit) {}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
PsiJetFileStubImpl[package=test]
|
||||
KotlinStub$PACKAGE_DIRECTIVE
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=test]
|
||||
KotlinStub$IMPORT_LIST
|
||||
KotlinStub$CLASS[classId=test/ParameterName, fqName=test.ParameterName, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=ParameterName, superNames=[]]
|
||||
KotlinStub$MODIFIER_LIST[public final]
|
||||
KotlinStub$PRIMARY_CONSTRUCTOR[fqName=null, hasBody=false, isDelegatedCallToThis=false, isExtension=false, isTopLevel=false, name=ParameterName]
|
||||
KotlinStub$MODIFIER_LIST[public]
|
||||
KotlinStub$VALUE_PARAMETER_LIST
|
||||
KotlinStub$CLASS_BODY
|
||||
KotlinStub$FUN[fqName=test.ParameterName.foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=false, isTopLevel=false, mayHaveContract=false, name=foo]
|
||||
KotlinStub$MODIFIER_LIST[public final inline]
|
||||
KotlinStub$TYPE_PARAMETER_LIST
|
||||
KotlinStub$TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=A]
|
||||
KotlinStub$TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=B]
|
||||
KotlinStub$VALUE_PARAMETER_LIST
|
||||
KotlinStub$VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=block]
|
||||
KotlinStub$MODIFIER_LIST[crossinline]
|
||||
KotlinStub$TYPE_REFERENCE
|
||||
KotlinStub$FUNCTION_TYPE
|
||||
KotlinStub$VALUE_PARAMETER_LIST
|
||||
KotlinStub$VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] paramNameByAnnotation: input
|
||||
KotlinStub$TYPE_REFERENCE
|
||||
KotlinStub$USER_TYPE
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=A]
|
||||
KotlinStub$VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] paramNameByAnnotation: state
|
||||
KotlinStub$TYPE_REFERENCE
|
||||
KotlinStub$USER_TYPE
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=B]
|
||||
KotlinStub$TYPE_REFERENCE
|
||||
KotlinStub$USER_TYPE
|
||||
KotlinStub$USER_TYPE
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=Unit]
|
||||
KotlinStub$TYPE_REFERENCE
|
||||
KotlinStub$USER_TYPE
|
||||
KotlinStub$USER_TYPE
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
KotlinStub$REFERENCE_EXPRESSION[referencedName=Unit]
|
||||
+3
@@ -60,6 +60,9 @@ abstract class AbstractAdditionalStubInfoTest : AbstractDecompiledClassTest() {
|
||||
.append(arguments.entries.joinToString(", ", "(", ")") { "${it.key.asString()} = ${it.value}" })
|
||||
}
|
||||
}
|
||||
is KotlinParameterStubImpl -> {
|
||||
stub.functionTypeParameterName?.let { builder.append(" paramNameByAnnotation: ").append(it) }
|
||||
}
|
||||
}
|
||||
for (child in stub.childrenStubs) {
|
||||
builder.append("\n").append(" ".repeat(level))
|
||||
|
||||
+6
@@ -48,6 +48,12 @@ public class AdditionalStubInfoTestGenerated extends AbstractAdditionalStubInfoT
|
||||
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/OuterClassesWithFlexibleArgs/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ParameterName")
|
||||
public void testParameterName() throws Exception {
|
||||
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/ParameterName/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("PropertyInitializer")
|
||||
public void testPropertyInitializer() throws Exception {
|
||||
|
||||
+26
-8
@@ -7,6 +7,7 @@ import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.util.io.StringRef
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionClass
|
||||
import org.jetbrains.kotlin.constant.StringValue
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
@@ -21,7 +22,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.stubs.ConstantValueKind
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.*
|
||||
@@ -37,7 +37,8 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
fun createTypeReferenceStub(
|
||||
parent: StubElement<out PsiElement>,
|
||||
type: Type,
|
||||
additionalAnnotations: () -> List<AnnotationWithTarget> = { emptyList() }
|
||||
additionalAnnotations: () -> List<AnnotationWithTarget> = { emptyList() },
|
||||
loadTypeAnnotations: (Type) -> List<AnnotationWithArgs> = { c.components.annotationLoader.loadTypeAnnotations(it, c.nameResolver) }
|
||||
) {
|
||||
val abbreviatedType = type.abbreviatedType(c.typeTable)
|
||||
if (abbreviatedType != null) {
|
||||
@@ -46,7 +47,8 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
|
||||
val typeReference = KotlinPlaceHolderStubImpl<KtTypeReference>(parent, KtStubElementTypes.TYPE_REFERENCE)
|
||||
|
||||
val annotations = c.components.annotationLoader.loadTypeAnnotations(type, c.nameResolver).filterNot {
|
||||
val allAnnotationsInType = loadTypeAnnotations(type)
|
||||
val annotations = allAnnotationsInType.filterNot {
|
||||
val isTopLevelClass = !it.classId.isNestedClass
|
||||
isTopLevelClass && it.classId.asSingleFqName() in ANNOTATIONS_NOT_LOADED_FOR_TYPES
|
||||
}
|
||||
@@ -271,8 +273,8 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
var suspendParameterType: Type? = null
|
||||
|
||||
for ((index, argument) in typeArgumentsWithoutReceiverAndReturnType.withIndex()) {
|
||||
val parameterType = argument.type(c.typeTable)!!
|
||||
if (isSuspend && index == typeArgumentsWithoutReceiverAndReturnType.size - 1) {
|
||||
val parameterType = argument.type(c.typeTable)!!
|
||||
if (parameterType.hasClassName() && parameterType.argumentCount == 1) {
|
||||
val classId = c.nameResolver.getClassId(parameterType.className)
|
||||
val fqName = classId.asSingleFqName()
|
||||
@@ -286,11 +288,27 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
val parameter = KotlinParameterStubImpl(
|
||||
parameterList, fqName = null, name = null, isMutable = false, hasValOrVar = false, hasDefaultValue = false
|
||||
)
|
||||
val annotations = c.components.annotationLoader.loadTypeAnnotations(parameterType, c.nameResolver)
|
||||
|
||||
createTypeReferenceStub(parameter, argument.type(c.typeTable)!!)
|
||||
fun getFunctionTypeParameterName(annotations: List<AnnotationWithArgs>): String? {
|
||||
for (annotationWithArgs in annotations) {
|
||||
if (annotationWithArgs.classId.asSingleFqName() == StandardNames.FqNames.parameterName) {
|
||||
return (annotationWithArgs.args.values.firstOrNull() as? StringValue)?.value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
val parameter = KotlinParameterStubImpl(
|
||||
parameterList,
|
||||
fqName = null,
|
||||
name = null,
|
||||
isMutable = false,
|
||||
hasValOrVar = false,
|
||||
hasDefaultValue = false,
|
||||
functionTypeParameterName = getFunctionTypeParameterName(annotations)
|
||||
)
|
||||
createTypeReferenceStub(parameter, parameterType, loadTypeAnnotations = { annotations })
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user