-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* merge upstream changes for qualifiers from KtClassType. * support KSDefNonNullReference
- Loading branch information
Showing
6 changed files
with
101 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 53 additions & 13 deletions
66
...i/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSClassifierReferenceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,77 @@ | ||
package com.google.devtools.ksp.impl.symbol.kotlin | ||
|
||
import com.google.devtools.ksp.IdKeyPair | ||
import com.google.devtools.ksp.IdKeyTriple | ||
import com.google.devtools.ksp.KSObjectCache | ||
import com.google.devtools.ksp.symbol.* | ||
import org.jetbrains.kotlin.analysis.api.components.buildClassType | ||
import org.jetbrains.kotlin.analysis.api.types.KtUsualClassType | ||
import org.jetbrains.kotlin.analysis.api.types.KtClassType | ||
import org.jetbrains.kotlin.analysis.api.types.KtClassTypeQualifier | ||
import org.jetbrains.kotlin.analysis.api.types.KtTypeParameterType | ||
|
||
class KSClassifierReferenceImpl private constructor( | ||
internal val ktType: KtUsualClassType, | ||
internal val ktType: KtClassType, | ||
internal val index: Int, | ||
override val parent: KSTypeReference? | ||
) : KSClassifierReference { | ||
companion object : KSObjectCache<IdKeyPair<KtUsualClassType, KSTypeReference?>, KSClassifierReferenceImpl>() { | ||
fun getCached(ktType: KtUsualClassType, parent: KSTypeReference?) = | ||
cache.getOrPut(IdKeyPair(ktType, parent)) { KSClassifierReferenceImpl(ktType, parent) } | ||
companion object : KSObjectCache<IdKeyTriple<KtClassType, Int, KSTypeReference?>, KSClassifierReferenceImpl>() { | ||
fun getCached(ktType: KtClassType, index: Int, parent: KSTypeReference?) = | ||
cache.getOrPut(IdKeyTriple(ktType, index, parent)) { KSClassifierReferenceImpl(ktType, index, parent) } | ||
} | ||
|
||
private val classifierReference: KtClassTypeQualifier | ||
get() = ktType.qualifiers[index] | ||
|
||
override val qualifier: KSClassifierReference? by lazy { | ||
ktType.classId.outerClassId?.let { | ||
analyze { | ||
buildClassType(it) | ||
} | ||
}?.let { getCached(it as KtUsualClassType, parent) } | ||
if (index == 0) { | ||
null | ||
} else { | ||
getCached(ktType, index - 1, parent) | ||
} | ||
} | ||
|
||
override fun referencedName(): String { | ||
return ktType.classId.asFqNameString() | ||
return classifierReference.name.asString() | ||
} | ||
|
||
override val typeArguments: List<KSTypeArgument> by lazy { | ||
ktType.typeArguments().map { KSTypeArgumentImpl.getCached(it, this) } | ||
classifierReference.typeArguments.map { KSTypeArgumentImpl.getCached(it, this) } | ||
} | ||
|
||
override val origin: Origin = parent?.origin ?: Origin.SYNTHETIC | ||
|
||
override val location: Location | ||
get() = parent?.location ?: NonExistLocation | ||
|
||
override fun toString(): String { | ||
return referencedName() | ||
} | ||
} | ||
|
||
class KSClassifierParameterImpl private constructor( | ||
internal val ktType: KtTypeParameterType, | ||
override val parent: KSTypeReference? | ||
) : KSClassifierReference { | ||
companion object : KSObjectCache<IdKeyPair<KtTypeParameterType, KSTypeReference?>, KSClassifierParameterImpl>() { | ||
fun getCached(ktType: KtTypeParameterType, parent: KSTypeReference?) = | ||
KSClassifierParameterImpl.cache.getOrPut(IdKeyPair(ktType, parent)) { | ||
KSClassifierParameterImpl(ktType, parent) | ||
} | ||
} | ||
|
||
override val qualifier: KSClassifierReference? = null | ||
|
||
override fun referencedName(): String { | ||
return ktType.name.asString() | ||
} | ||
|
||
override val typeArguments: List<KSTypeArgument> | ||
get() = emptyList() | ||
override val origin: Origin | ||
get() = parent?.origin ?: Origin.SYNTHETIC | ||
override val location: Location | ||
get() = parent?.location ?: NonExistLocation | ||
|
||
override fun toString(): String { | ||
return referencedName() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...i/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSDefNonNullReferenceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.google.devtools.ksp.impl.symbol.kotlin | ||
|
||
import com.google.devtools.ksp.IdKeyPair | ||
import com.google.devtools.ksp.KSObjectCache | ||
import com.google.devtools.ksp.symbol.* | ||
import org.jetbrains.kotlin.analysis.api.types.KtDefinitelyNotNullType | ||
|
||
class KSDefNonNullReferenceImpl private constructor( | ||
val ktDefinitelyNotNullType: KtDefinitelyNotNullType, | ||
override val parent: KSTypeReference? | ||
) : KSDefNonNullReference { | ||
companion object : KSObjectCache<IdKeyPair<KtDefinitelyNotNullType, KSTypeReference?>, KSDefNonNullReference>() { | ||
fun getCached(ktType: KtDefinitelyNotNullType, parent: KSTypeReference?) = | ||
KSDefNonNullReferenceImpl.cache | ||
.getOrPut(IdKeyPair(ktType, parent)) { KSDefNonNullReferenceImpl(ktType, parent) } | ||
} | ||
override val enclosedType: KSClassifierReference by lazy { | ||
ktDefinitelyNotNullType.original.toClassifierReference(parent) as KSClassifierReference | ||
} | ||
override val typeArguments: List<KSTypeArgument> | ||
get() = emptyList() | ||
|
||
override val origin: Origin = Origin.KOTLIN | ||
|
||
override val location: Location | ||
get() = parent?.location ?: NonExistLocation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters