[Analysis API] render enhanced types
^KTIJ-28555 Fixed
This commit is contained in:
committed by
teamcity
parent
69fe60f494
commit
d935db9e3a
+9
@@ -23,6 +23,8 @@ public abstract class KtTypeProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public abstract fun approximateToSubPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType?
|
||||
|
||||
public abstract fun getEnhancedType(type: KtType): KtType?
|
||||
|
||||
public abstract fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType
|
||||
|
||||
public abstract fun commonSuperType(types: Collection<KtType>): KtType?
|
||||
@@ -74,6 +76,13 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtType.approximateToSuperPublicDenotableOrSelf(approximateLocalTypes: Boolean): KtType =
|
||||
withValidityAssertion { approximateToSuperPublicDenotable(approximateLocalTypes) ?: this }
|
||||
|
||||
/**
|
||||
* Returns a warning-level enhanced type for [KtType] if it is present. Otherwise, returns `null`.
|
||||
*/
|
||||
public fun KtType.getEnhancedType(): KtType? = withValidityAssertion { analysisSession.typeProvider.getEnhancedType(this) }
|
||||
|
||||
public fun KtType.getEnhancedTypeOrSelf(): KtType? = withValidityAssertion { getEnhancedType() ?: this }
|
||||
|
||||
public fun KtNamedClassOrObjectSymbol.buildSelfClassType(): KtType =
|
||||
withValidityAssertion { analysisSession.typeProvider.buildSelfClassType(this) }
|
||||
|
||||
|
||||
+2
@@ -16,6 +16,8 @@ public interface KtRendererTypeApproximator {
|
||||
public object TO_DENOTABLE : KtRendererTypeApproximator {
|
||||
context(KtAnalysisSession)
|
||||
override fun approximateType(type: KtType, position: Variance): KtType {
|
||||
type.getEnhancedType()?.let { return it }
|
||||
|
||||
return when (position) {
|
||||
Variance.INVARIANT -> type
|
||||
Variance.IN_VARIANCE -> type.approximateToSubPublicDenotableOrSelf(approximateLocalTypes = false)
|
||||
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// FILE: androidx/annotation/RecentlyNonNull.java
|
||||
package androidx.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.PARAMETER, ElementType.TYPE})
|
||||
public @interface RecentlyNonNull {
|
||||
}
|
||||
|
||||
// FILE: androidx/annotation/A.java
|
||||
package androidx.annotation;
|
||||
|
||||
public class A {
|
||||
@RecentlyNonNull
|
||||
public String bar(@RecentlyNonNull String string) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import androidx.annotation.A
|
||||
|
||||
fun test(a: A) = <expr>a.bar()</expr>
|
||||
analysis/analysis-api/testData/components/expressionTypeProvider/expressionType/javaEnhancedType.txt
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
expression: a.bar()
|
||||
type: kotlin.String
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: a.externalNotNullMethod()
|
||||
type: kotlin.String!
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// FILE: ClassWithExternalAnnotatedMembers.java
|
||||
public class ClassWithExternalAnnotatedMembers {
|
||||
public String externalNotNullMethod() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: annotations.xml
|
||||
<root>
|
||||
<item name='ClassWithExternalAnnotatedMembers java.lang.String externalNotNullMethod()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
import ClassWithExternalAnnotatedMembers
|
||||
|
||||
fun test(a: ClassWithExternalAnnotatedMembers) = <expr>a.externalNotNullMethod()</expr>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: a.externalNotNullMethod()
|
||||
type: kotlin.String
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// FILE: androidx/annotation/RecentlyNonNull.java
|
||||
package androidx.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.PARAMETER, ElementType.TYPE})
|
||||
public @interface RecentlyNonNull {
|
||||
}
|
||||
|
||||
// FILE: androidx/annotation/A.java
|
||||
package androidx.annotation;
|
||||
|
||||
public class A {
|
||||
@RecentlyNonNull
|
||||
public String bar(@RecentlyNonNull String string) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import androidx.annotation.A
|
||||
|
||||
fun test(a: A) = a.b<caret><caret_onAirContext>ar()
|
||||
+1
@@ -0,0 +1 @@
|
||||
open fun bar(string: kotlin.String): kotlin.String
|
||||
+1
@@ -0,0 +1 @@
|
||||
open fun externalNotNullMethod(): kotlin.String?
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// FILE: ClassWithExternalAnnotatedMembers.java
|
||||
public class ClassWithExternalAnnotatedMembers {
|
||||
public String externalNotNullMethod() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: annotations.xml
|
||||
<root>
|
||||
<item name='ClassWithExternalAnnotatedMembers java.lang.String externalNotNullMethod()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
import ClassWithExternalAnnotatedMembers
|
||||
|
||||
fun test(a: ClassWithExternalAnnotatedMembers) = a.e<caret><caret_onAirContext>xternalNotNullMethod()
|
||||
+1
@@ -0,0 +1 @@
|
||||
open fun externalNotNullMethod(): kotlin.String
|
||||
Reference in New Issue
Block a user