1 package com.google.devtools.ksp.symbol.impl.synthetic 2 3 import com.google.devtools.ksp.ExceptionMessage 4 import com.google.devtools.ksp.KSObjectCache 5 import com.google.devtools.ksp.processing.impl.KSNameImpl 6 import com.google.devtools.ksp.processing.impl.findAnnotationFromUseSiteTarget 7 import com.google.devtools.ksp.symbol.KSAnnotated 8 import com.google.devtools.ksp.symbol.KSAnnotation 9 import com.google.devtools.ksp.symbol.KSName 10 import com.google.devtools.ksp.symbol.KSNode 11 import com.google.devtools.ksp.symbol.KSTypeReference 12 import com.google.devtools.ksp.symbol.KSValueParameter 13 import com.google.devtools.ksp.symbol.KSVisitor 14 import com.google.devtools.ksp.symbol.Location 15 import com.google.devtools.ksp.symbol.NonExistLocation 16 import com.google.devtools.ksp.symbol.Origin 17 import com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl 18 import com.google.devtools.ksp.symbol.impl.binary.KSTypeReferenceDescriptorImpl 19 import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor 20 import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue 21 import org.jetbrains.kotlin.resolve.calls.components.isVararg 22 23 class KSValueParameterSyntheticImpl(val owner: KSAnnotated?, resolve: () -> ValueParameterDescriptor?) : 24 KSValueParameter { 25 26 companion object : 27 KSObjectCache<Pair<KSAnnotated?, () -> ValueParameterDescriptor?>, KSValueParameterSyntheticImpl>() { getCachednull28 fun getCached(owner: KSAnnotated? = null, resolve: () -> ValueParameterDescriptor?) = 29 KSValueParameterSyntheticImpl.cache.getOrPut(Pair(owner, resolve)) { 30 KSValueParameterSyntheticImpl(owner, resolve) 31 } 32 } 33 <lambda>null34 private val descriptor by lazy { 35 resolve() ?: throw IllegalStateException("Failed to resolve for synthetic value parameter, $ExceptionMessage") 36 } 37 <lambda>null38 override val name: KSName? by lazy { 39 KSNameImpl.getCached(descriptor.name.asString()) 40 } 41 <lambda>null42 override val type: KSTypeReference by lazy { 43 KSTypeReferenceDescriptorImpl.getCached(descriptor.type, origin, this) 44 } 45 46 override val isVararg: Boolean = descriptor.isVararg 47 48 override val isNoInline: Boolean = descriptor.isNoinline 49 50 override val isCrossInline: Boolean = descriptor.isCrossinline 51 52 override val isVal: Boolean = !descriptor.isVar 53 54 override val isVar: Boolean = descriptor.isVar 55 56 override val hasDefault: Boolean = descriptor.hasDefaultValue() 57 <lambda>null58 override val annotations: Sequence<KSAnnotation> by lazy { 59 descriptor.annotations.asSequence() 60 .map { KSAnnotationDescriptorImpl.getCached(it, this) }.plus(this.findAnnotationFromUseSiteTarget()) 61 } 62 63 override val origin: Origin = Origin.SYNTHETIC 64 65 override val location: Location = NonExistLocation 66 67 override val parent: KSNode? = owner 68 acceptnull69 override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R { 70 return visitor.visitValueParameter(this, data) 71 } 72 toStringnull73 override fun toString(): String { 74 return name?.asString() ?: "_" 75 } 76 } 77