Skip to content

Commit 371d15d

Browse files
committed
add KSTypeAliasDescriptorImpl
1 parent ef09196 commit 371d15d

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ class ResolverImpl(
478478
when (descriptor) {
479479
is ClassDescriptor -> KSClassDeclarationDescriptorImpl.getCached(descriptor)
480480
is TypeParameterDescriptor -> KSTypeParameterDescriptorImpl.getCached(descriptor)
481+
is TypeAliasDescriptor -> KSTypeAliasDescriptorImpl.getCached(descriptor)
481482
null -> throw IllegalStateException("Failed to resolve descriptor for $kotlinType")
482483
else -> throw IllegalStateException("Unexpected descriptor type: ${descriptor.javaClass}, $ExceptionMessage")
483484
}

compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/AnnotationArgumentProcessor.kt

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class AnnotationArgumentProcessor : AbstractTestProcessor() {
3636

3737
val C = resolver.getClassDeclarationByName("C")!!
3838
C.annotations.first().arguments.map { results.add(it.value.toString()) }
39+
val ThrowsClass = resolver.getClassDeclarationByName("ThrowsClass")!!
40+
ThrowsClass.declarations.map { it.annotations.single().annotationType.resolve().declaration.let { results.add(it.toString()) } }
3941
}
4042

4143
override fun toResult(): List<String> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.google.devtools.ksp.symbol.impl.binary
2+
3+
import com.google.devtools.ksp.symbol.*
4+
import com.google.devtools.ksp.symbol.impl.KSObjectCache
5+
import com.google.devtools.ksp.symbol.impl.kotlin.KSNameImpl
6+
import com.google.devtools.ksp.symbol.impl.toKSModifiers
7+
import org.jetbrains.kotlin.descriptors.ClassKind
8+
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
9+
import org.jetbrains.kotlin.descriptors.MemberDescriptor
10+
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
11+
import org.jetbrains.kotlin.types.KotlinType
12+
13+
class KSTypeAliasDescriptorImpl(descriptor: TypeAliasDescriptor) : KSTypeAlias,
14+
KSDeclarationDescriptorImpl(descriptor),
15+
KSExpectActual by KSExpectActualDescriptorImpl(descriptor) {
16+
companion object : KSObjectCache<TypeAliasDescriptor, KSTypeAliasDescriptorImpl>() {
17+
fun getCached(descriptor: TypeAliasDescriptor) = KSTypeAliasDescriptorImpl.cache.getOrPut(descriptor) { KSTypeAliasDescriptorImpl(descriptor) }
18+
}
19+
20+
override val name: KSName by lazy {
21+
KSNameImpl.getCached(descriptor.name.asString())
22+
}
23+
24+
override val modifiers: Set<Modifier> by lazy {
25+
val modifiers = mutableSetOf<Modifier>()
26+
modifiers.addAll(descriptor.toKSModifiers())
27+
modifiers
28+
}
29+
30+
override val typeParameters: List<KSTypeParameter> by lazy {
31+
descriptor.declaredTypeParameters.map { KSTypeParameterDescriptorImpl.getCached(it) }
32+
}
33+
34+
override val type: KSTypeReference by lazy {
35+
KSTypeReferenceDescriptorImpl.getCached(descriptor.underlyingType)
36+
}
37+
38+
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
39+
return visitor.visitTypeAlias(this, data)
40+
}
41+
42+
}

compiler-plugin/testData/api/annotationValue.kt

+7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@
3737
// G
3838
// 31
3939
// [warning1, warning 2]
40+
// Throws
4041
// END
4142
// FILE: a.kt
4243

4344
enum class RGB {
4445
R, G, B
4546
}
4647

48+
class ThrowsClass {
49+
@Throws(Exception::class)
50+
protected open fun throwsException() {
51+
}
52+
}
53+
4754
annotation class Foo(val s: Int)
4855

4956
annotation class Bar(

0 commit comments

Comments
 (0)