-
Notifications
You must be signed in to change notification settings - Fork 251
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 #1127 (cherry picked from commit c048c6b)
- Loading branch information
Showing
12 changed files
with
104 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
41 changes: 41 additions & 0 deletions
41
...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,41 @@ | ||
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 { | ||
val lhs = ktIntersectionType.getLeftTypeRef()?.typeElement | ||
if (lhs is KtUserType) { | ||
KSClassifierReferenceImpl.getCached(lhs) | ||
} else { | ||
throw IllegalStateException("LHS operand of definitely non null type should be a user type") | ||
} | ||
} | ||
|
||
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
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