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.java
19 
20 import com.google.devtools.ksp.KSObjectCache
21 import com.google.devtools.ksp.memoized
22 import com.google.devtools.ksp.processing.impl.KSNameImpl
23 import com.google.devtools.ksp.symbol.*
24 import com.google.devtools.ksp.symbol.impl.findParentDeclaration
25 import com.google.devtools.ksp.symbol.impl.kotlin.KSExpectActualNoImpl
26 import com.google.devtools.ksp.symbol.impl.toLocation
27 import com.intellij.psi.PsiJavaFile
28 import com.intellij.psi.PsiTypeParameter
29 
30 class KSTypeParameterJavaImpl private constructor(val psi: PsiTypeParameter) :
31     KSTypeParameter,
32     KSDeclarationJavaImpl(psi),
33     KSExpectActual by KSExpectActualNoImpl() {
34     companion object : KSObjectCache<PsiTypeParameter, KSTypeParameterJavaImpl>() {
<lambda>null35         fun getCached(psi: PsiTypeParameter) = cache.getOrPut(psi) { KSTypeParameterJavaImpl(psi) }
36     }
37 
38     override val origin = Origin.JAVA
39 
<lambda>null40     override val location: Location by lazy {
41         psi.toLocation()
42     }
43 
<lambda>null44     override val annotations: Sequence<KSAnnotation> by lazy {
45         psi.annotations.asSequence().map { KSAnnotationJavaImpl.getCached(it) }.memoized()
46     }
47 
<lambda>null48     override val bounds: Sequence<KSTypeReference> by lazy {
49         psi.extendsListTypes.asSequence().map { KSTypeReferenceJavaImpl.getCached(it, this) }.memoized()
50     }
<lambda>null51     override val simpleName: KSName by lazy {
52         KSNameImpl.getCached(psi.name ?: "_")
53     }
54 
<lambda>null55     override val qualifiedName: KSName? by lazy {
56         KSNameImpl.getCached(parentDeclaration?.qualifiedName?.asString() ?: "" + "." + simpleName.asString())
57     }
58 
59     override val typeParameters: List<KSTypeParameter> = emptyList()
60 
<lambda>null61     override val parentDeclaration: KSDeclaration? by lazy {
62         psi.findParentDeclaration()
63     }
64 
<lambda>null65     override val containingFile: KSFile? by lazy {
66         KSFileJavaImpl.getCached(psi.containingFile as PsiJavaFile)
67     }
68 
69     override val modifiers: Set<Modifier> = emptySet()
70 
71     override val isReified: Boolean = false
72 
<lambda>null73     override val name: KSName by lazy {
74         KSNameImpl.getCached(psi.name!!)
75     }
76 
77     override val variance: Variance = Variance.INVARIANT
78 
acceptnull79     override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
80         return visitor.visitTypeParameter(this, data)
81     }
82 }
83