Create INTERSECTION_TYPE stubs for definitely non-nullable types
^KTIJ-20802 Fixed
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
|||||||
|
class DefinitelyNotNullTypes<T>(private val x: T & Any) {
|
||||||
|
fun foo(xs: List<T & Any>): T & Any {
|
||||||
|
return if (xs.isNotEmpty()) xs[0] else x
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <R> bar(x: R & Any, action: (R & Any) -> R & Any): R & Any {
|
||||||
|
return action(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
PsiJetFileStubImpl[package=]
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
IMPORT_LIST
|
||||||
|
CLASS[classId=/DefinitelyNotNullTypes, fqName=DefinitelyNotNullTypes, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=DefinitelyNotNullTypes, superNames=[]]
|
||||||
|
MODIFIER_LIST[public final]
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=T]
|
||||||
|
PRIMARY_CONSTRUCTOR
|
||||||
|
MODIFIER_LIST[public]
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=x]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=T]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
CLASS_BODY
|
||||||
|
PROPERTY[fqName=DefinitelyNotNullTypes.x, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=x]
|
||||||
|
MODIFIER_LIST[private final]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=T]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
FUN[fqName=DefinitelyNotNullTypes.bar, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=false, isTopLevel=false, mayHaveContract=false, name=bar]
|
||||||
|
MODIFIER_LIST[public final]
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=R]
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=x]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=R]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=action]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
FUNCTION_TYPE
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=R]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=R]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=R]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
FUN[fqName=DefinitelyNotNullTypes.foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=foo]
|
||||||
|
MODIFIER_LIST[public final]
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=xs]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
USER_TYPE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||||
|
REFERENCE_EXPRESSION[referencedName=collections]
|
||||||
|
REFERENCE_EXPRESSION[referencedName=List]
|
||||||
|
TYPE_ARGUMENT_LIST
|
||||||
|
TYPE_PROJECTION[projectionKind=NONE]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=T]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
INTERSECTION_TYPE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=T]
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION[referencedName=Any]
|
||||||
+6
@@ -108,6 +108,12 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest {
|
|||||||
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DataClass/");
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DataClass/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("DefinitelyNotNullTypes")
|
||||||
|
public void testDefinitelyNotNullTypes() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DefinitelyNotNullTypes/");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("Delegation")
|
@TestMetadata("Delegation")
|
||||||
public void testDelegation() throws Exception {
|
public void testDelegation() throws Exception {
|
||||||
|
|||||||
+15
-2
@@ -70,8 +70,21 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
|||||||
|
|
||||||
private fun createTypeParameterStub(parent: KotlinStubBaseImpl<*>, type: Type, name: Name, annotations: List<ClassIdWithTarget>) {
|
private fun createTypeParameterStub(parent: KotlinStubBaseImpl<*>, type: Type, name: Name, annotations: List<ClassIdWithTarget>) {
|
||||||
createTypeAnnotationStubs(parent, type, annotations)
|
createTypeAnnotationStubs(parent, type, annotations)
|
||||||
val nullableParentWrapper = nullableTypeParent(parent, type)
|
if (Flags.DEFINITELY_NOT_NULL_TYPE.get(type.flags)) {
|
||||||
createStubForTypeName(ClassId.topLevel(FqName.topLevel(name)), nullableParentWrapper)
|
createDefinitelyNotNullTypeStub(parent, FqName.topLevel(name))
|
||||||
|
} else {
|
||||||
|
val nullableParentWrapper = nullableTypeParent(parent, type)
|
||||||
|
createStubForTypeName(ClassId.topLevel(FqName.topLevel(name)), nullableParentWrapper)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createDefinitelyNotNullTypeStub(parent: KotlinStubBaseImpl<*>, name: FqName) {
|
||||||
|
val intersectionType = KotlinPlaceHolderStubImpl<KtIntersectionType>(parent, KtStubElementTypes.INTERSECTION_TYPE)
|
||||||
|
val leftReference = KotlinPlaceHolderStubImpl<KtTypeReference>(intersectionType, KtStubElementTypes.TYPE_REFERENCE)
|
||||||
|
createStubForTypeName(ClassId.topLevel(name), leftReference)
|
||||||
|
val rightReference = KotlinPlaceHolderStubImpl<KtTypeReference>(intersectionType, KtStubElementTypes.TYPE_REFERENCE)
|
||||||
|
val userType = KotlinUserTypeStubImpl(rightReference)
|
||||||
|
KotlinNameReferenceExpressionStubImpl(userType, StandardNames.FqNames.any.shortName().ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createClassReferenceTypeStub(parent: KotlinStubBaseImpl<*>, type: Type, annotations: List<ClassIdWithTarget>) {
|
private fun createClassReferenceTypeStub(parent: KotlinStubBaseImpl<*>, type: Type, annotations: List<ClassIdWithTarget>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user