forked from google/ksp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Definitely non null type language feature.
* Add api for definitely non null type element. * Implement definitely non null type element for FE1.0. fixes google#1127
- Loading branch information
Showing
11 changed files
with
94 additions
and
13 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
13 changes: 13 additions & 0 deletions
13
api/src/main/kotlin/com/google/devtools/ksp/symbol/KSDefNonNullReference.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,13 @@ | ||
package com.google.devtools.ksp.symbol | ||
|
||
interface KSDefNonNullReference : KSReferenceElement { | ||
/** | ||
* Enclosed reference element of the Definitely non null type. | ||
* For a reference of `T & Any`, this returns `T`. | ||
*/ | ||
val enclosedType: KSClassifierReference | ||
|
||
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R { | ||
return visitor.visitDefNonNullReference(this, data) | ||
} | ||
} |
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
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
36 changes: 36 additions & 0 deletions
36
...n/src/main/kotlin/com/google/devtools/ksp/symbol/impl/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,36 @@ | ||
package com.google.devtools.ksp.symbol.impl.kotlin | ||
|
||
import com.google.devtools.ksp.KSObjectCache | ||
import com.google.devtools.ksp.findParentOfType | ||
import com.google.devtools.ksp.symbol.* | ||
import com.google.devtools.ksp.symbol.impl.toLocation | ||
import org.jetbrains.kotlin.psi.KtIntersectionType | ||
import org.jetbrains.kotlin.psi.KtTypeReference | ||
import org.jetbrains.kotlin.psi.KtUserType | ||
|
||
class KSDefNonNullReferenceImpl private constructor(val ktIntersectionType: KtIntersectionType) : | ||
KSDefNonNullReference { | ||
companion object : KSObjectCache<KtIntersectionType, KSDefNonNullReferenceImpl>() { | ||
fun getCached(ktIntersectionType: KtIntersectionType) = KSDefNonNullReferenceImpl | ||
.cache.getOrPut(ktIntersectionType) { KSDefNonNullReferenceImpl(ktIntersectionType) } | ||
} | ||
|
||
override val enclosedType: KSClassifierReference by lazy { | ||
(ktIntersectionType.getLeftTypeRef()?.typeElement as KtUserType).let { KSClassifierReferenceImpl.getCached(it) } | ||
} | ||
|
||
override val typeArguments: List<KSTypeArgument> | ||
get() = emptyList() | ||
|
||
override val origin: Origin | ||
get() = Origin.KOTLIN | ||
|
||
override val location: Location | ||
get() = ktIntersectionType.toLocation() | ||
|
||
override val parent: KSNode? by lazy { | ||
ktIntersectionType.findParentOfType<KtTypeReference>()?.let { KSTypeReferenceImpl.getCached(it) } | ||
} | ||
|
||
override fun toString() = "${enclosedType.referencedName()} & Any" | ||
} |
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