Skip to content

Commit

Permalink
expose KSType.isMarkedNullable API
Browse files Browse the repository at this point in the history
  • Loading branch information
neetopia committed Sep 30, 2020
1 parent 37a1e8e commit e1c5ca1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions api/src/main/kotlin/com/google/devtools/ksp/symbol/KSType.kt
Expand Up @@ -86,6 +86,11 @@ interface KSType {
*/
fun makeNotNullable(): KSType

/**
* True if the type is explicitly marked as nullable type, i.e. has question mark in type declaration.
*/
val isMarkedNullable: Boolean

/**
* True if the type is an error type, which means the type can't be resolved by compiler.
*/
Expand Down
Expand Up @@ -40,7 +40,7 @@ open class TypeParameterReferenceProcessor: AbstractTestProcessor() {

for (i in sortedReferences) {
val r = i.resolve()
results.add("${r?.declaration?.qualifiedName?.asString()}")
results.add("${r.declaration.qualifiedName?.asString()}: ${r.isMarkedNullable}")
}
}

Expand Down
Expand Up @@ -52,6 +52,8 @@ object KSErrorType : KSType {
return this
}

override val isMarkedNullable: Boolean = false

override fun replace(arguments: List<KSTypeArgument>): KSType {
return this
}
Expand Down
Expand Up @@ -88,6 +88,8 @@ class KSTypeImpl private constructor(
private val meNotNullable: KSType by lazy { KSTypeImpl.getCached(kotlinType.makeNotNullable()) }
override fun makeNotNullable(): KSType = meNotNullable

override val isMarkedNullable: Boolean = kotlinType.isMarkedNullable

override val isError: Boolean = false

override fun equals(other: Any?): Boolean {
Expand Down
8 changes: 4 additions & 4 deletions compiler-plugin/testData/api/typeParameterReference.kt
Expand Up @@ -18,14 +18,14 @@
// WITH_RUNTIME
// TEST PROCESSOR: TypeParameterReferenceProcessor
// EXPECTED:
// Foo.T1
// Foo.bar.T2
// foo.T3
// Foo.T1: true
// Foo.bar.T2: false
// foo.T3: false
// END

class Foo<T1> {
inner class Bar {
val v: T1
val v: T1?
}

fun <T2> bar(p: T2) = 1
Expand Down

0 comments on commit e1c5ca1

Please sign in to comment.