FIR IDE: make smartcast API return unstable smartcasts
This commit is contained in:
committed by
Ilya Kirillov
parent
6462642988
commit
197079c85c
+8
-3
@@ -10,13 +10,18 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
|
||||
public abstract class KtSmartCastProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun getSmartCastedToType(expression: KtExpression): KtType?
|
||||
public abstract fun getSmartCastedInfo(expression: KtExpression): SmartCastInfo?
|
||||
public abstract fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<ImplicitReceiverSmartCast>
|
||||
}
|
||||
|
||||
public class SmartCastInfo(public val smartCastType: KtType, public val isStable: Boolean)
|
||||
|
||||
public interface KtSmartCastProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtExpression.getSmartCast(): KtType? =
|
||||
analysisSession.smartCastProvider.getSmartCastedToType(this)
|
||||
/**
|
||||
* Gets the smart-cast information of the given expression or null if the expression is not smart casted.
|
||||
*/
|
||||
public fun KtExpression.getSmartCastInfo(): SmartCastInfo? =
|
||||
analysisSession.smartCastProvider.getSmartCastedInfo(this)
|
||||
|
||||
public fun KtExpression.getImplicitReceiverSmartCast(): Collection<ImplicitReceiverSmartCast> =
|
||||
analysisSession.smartCastProvider.getImplicitReceiverSmartCast(this)
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
interface A
|
||||
interface B
|
||||
|
||||
fun <T> T.foo() where T: A, T: B {}
|
||||
|
||||
fun test(a: Any) {
|
||||
if (a is A && a is B) {
|
||||
<expr>a</expr>.foo()
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: true
|
||||
smartCastType: (A&B)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
interface A
|
||||
interface B
|
||||
|
||||
fun <T> T.foo() where T: A, T: B {}
|
||||
|
||||
var a: Any = 1
|
||||
fun test() {
|
||||
if (a is A && a is B) {
|
||||
<expr>a</expr>.foo()
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: false
|
||||
smartCastType: (A&B)
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
interface A
|
||||
interface B
|
||||
|
||||
fun test(a: Any) {
|
||||
if (a is A && a is B) {
|
||||
<expr>a</expr>
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: true
|
||||
smartCastType: (A&B)
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface A
|
||||
interface B
|
||||
|
||||
var a: Any = 1
|
||||
fun test() {
|
||||
if (a is A && a is B) {
|
||||
<expr>a</expr>
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: false
|
||||
smartCastType: (A&B)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test(a: Any) {
|
||||
if (a is String) {
|
||||
<expr>a</expr>.length
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: true
|
||||
smartCastType: kotlin.String
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
var a: Any = 1
|
||||
fun test() {
|
||||
if (a is String) {
|
||||
<expr>a</expr>.length
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test(a: Any) {
|
||||
if (a is String) {
|
||||
<expr>a</expr>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: true
|
||||
smartCastType: kotlin.String
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: null
|
||||
smartCastType: null
|
||||
@@ -0,0 +1,6 @@
|
||||
var a: Any = 1
|
||||
fun test() {
|
||||
if (a is String) {
|
||||
<expr>a</expr>
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expression: a
|
||||
isStable: false
|
||||
smartCastType: kotlin.String
|
||||
Reference in New Issue
Block a user