1 /* 2 * Copyright 2020 Google LLC 3 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.google.devtools.ksp.symbol.impl.binary 19 20 import com.google.devtools.ksp.IdKeyTriple 21 import com.google.devtools.ksp.KSObjectCache 22 import com.google.devtools.ksp.symbol.KSAnnotation 23 import com.google.devtools.ksp.symbol.KSNode 24 import com.google.devtools.ksp.symbol.KSTypeReference 25 import com.google.devtools.ksp.symbol.Location 26 import com.google.devtools.ksp.symbol.NonExistLocation 27 import com.google.devtools.ksp.symbol.Origin 28 import com.google.devtools.ksp.symbol.Variance 29 import com.google.devtools.ksp.symbol.impl.kotlin.KSTypeArgumentImpl 30 import org.jetbrains.kotlin.types.TypeProjection 31 32 class KSTypeArgumentDescriptorImpl private constructor( 33 val descriptor: TypeProjection, 34 override val origin: Origin, 35 override val parent: KSNode? 36 ) : KSTypeArgumentImpl() { 37 companion object : KSObjectCache<IdKeyTriple<TypeProjection, Origin, KSNode?>, KSTypeArgumentDescriptorImpl>() { getCachednull38 fun getCached(descriptor: TypeProjection, origin: Origin, parent: KSNode?) = cache 39 .getOrPut(IdKeyTriple(descriptor, origin, parent)) { 40 KSTypeArgumentDescriptorImpl(descriptor, origin, parent) 41 } 42 } 43 44 override val location: Location = NonExistLocation 45 <lambda>null46 override val type: KSTypeReference by lazy { 47 KSTypeReferenceDescriptorImpl.getCached(descriptor.type, origin, if (parent != null) this else null) 48 } 49 <lambda>null50 override val variance: Variance by lazy { 51 if (descriptor.isStarProjection) 52 Variance.STAR 53 else { 54 when (descriptor.projectionKind) { 55 org.jetbrains.kotlin.types.Variance.IN_VARIANCE -> Variance.CONTRAVARIANT 56 org.jetbrains.kotlin.types.Variance.OUT_VARIANCE -> Variance.COVARIANT 57 else -> Variance.INVARIANT 58 } 59 } 60 } 61 <lambda>null62 override val annotations: Sequence<KSAnnotation> by lazy { 63 descriptor.type.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this) } 64 } 65 } 66