com.zeoflow.depot.compiler.processing.ksp.KspExecutableParameterElement.kt Maven / Gradle / Ivy
/*
* Copyright (C) 2021 ZeoFlow SRL
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zeoflow.depot.compiler.processing.ksp
import com.zeoflow.depot.compiler.processing.XAnnotated
import com.zeoflow.depot.compiler.processing.XExecutableParameterElement
import com.zeoflow.depot.compiler.processing.XType
import com.zeoflow.depot.compiler.processing.ksp.KspAnnotated.UseSiteFilter.Companion.NO_USE_SITE_OR_METHOD_PARAMETER
import com.google.devtools.ksp.symbol.KSValueParameter
internal class KspExecutableParameterElement(
env: KspProcessingEnv,
val method: KspExecutableElement,
val parameter: KSValueParameter
) : KspElement(env, parameter),
XExecutableParameterElement,
XAnnotated by KspAnnotated.create(env, parameter, NO_USE_SITE_OR_METHOD_PARAMETER) {
override val equalityItems: Array
get() = arrayOf(method, parameter)
override val name: String
get() = parameter.name?.asString() ?: "_no_param_name"
override val type: KspType by lazy {
parameter.typeAsMemberOf(
functionDeclaration = method.declaration,
ksType = method.containing.type?.ksType
).let {
env.wrap(
originatingReference = parameter.type,
ksType = it
)
}
}
override val fallbackLocationText: String
get() = "$name in ${method.fallbackLocationText}"
override fun asMemberOf(other: XType): KspType {
if (method.containing.type?.isSameType(other) != false) {
return type
}
check(other is KspType)
return parameter.typeAsMemberOf(
functionDeclaration = method.declaration,
ksType = other.ksType
).let {
env.wrap(
originatingReference = parameter.type,
ksType = it
)
}
}
override fun kindName(): String {
return "function parameter"
}
}