diff --git a/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinULiteralExpression.kt b/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinULiteralExpression.kt index 75b7741be10b..344938f6477c 100644 --- a/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinULiteralExpression.kt +++ b/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinULiteralExpression.kt @@ -3,6 +3,8 @@ package org.jetbrains.uast.kotlin import com.intellij.psi.PsiElement +import com.intellij.psi.PsiType +import com.intellij.psi.PsiTypes import org.jetbrains.annotations.ApiStatus import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.psi.KtConstantExpression @@ -20,6 +22,14 @@ class KotlinULiteralExpression( override val isNull: Boolean get() = sourcePsi.unwrapBlockOrParenthesis().node?.elementType == KtNodeTypes.NULL + override fun getExpressionType(): PsiType? { + // `null` of `kotlin.Nothing?` type would be mapped to `java.lang.Void` without this shortcut. + return if (isNull) + PsiTypes.nullType() + else + super.getExpressionType() + } + override val value: Any? get() = valuePart.getOrBuild { evaluate() } diff --git a/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/UastApiFixtureTestBase.kt b/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/UastApiFixtureTestBase.kt index 4318f323dce2..3530987188de 100644 --- a/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/UastApiFixtureTestBase.kt +++ b/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/UastApiFixtureTestBase.kt @@ -1153,4 +1153,27 @@ interface UastApiFixtureTestBase : UastPluginSelection { ) TestCase.assertEquals(1, count) } + + fun checkNullLiteral(myFixture: JavaCodeInsightTestFixture) { + myFixture.configureByText( + "main.kt", """ + fun test() { + val foo : Any? = null + } + """.trimIndent() + ) + val uFile = myFixture.file.toUElementOfType()!! + var count = 0 + uFile.accept( + object : AbstractUastVisitor() { + override fun visitLiteralExpression(node: ULiteralExpression): Boolean { + TestCase.assertTrue(node.isNull) + TestCase.assertEquals("null", node.getExpressionType()?.canonicalText) + count++ + return super.visitLiteralExpression(node) + } + } + ) + TestCase.assertEquals(1, count) + } } \ No newline at end of file diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirUastApiFixtureTest.kt b/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirUastApiFixtureTest.kt index ed770dc480ca..33c72196dc89 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirUastApiFixtureTest.kt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirUastApiFixtureTest.kt @@ -136,4 +136,8 @@ class FirUastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi fun testNameReferenceVisitInConstructorCall() { checkNameReferenceVisitInConstructorCall(myFixture) } + + fun testNullLiteral() { + checkNullLiteral(myFixture) + } } \ No newline at end of file diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fe10.txt index f7e653ec131f..05c4a9bd0909 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fe10.txt @@ -55,17 +55,17 @@ UFile (package = ) [public final class AnnotatedExpressionsKt {...] UIdentifier (Identifier (isBlank)) [UIdentifier (Identifier (isBlank))] UExpressionList (when_entry) [{...] UYieldExpression [yield null] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null USwitchClauseExpressionWithBody [str.isNotEmpty() != null -> {...] UBinaryExpression (operator = !=) [str.isNotEmpty() != null] : boolean UQualifiedReferenceExpression [str.isNotEmpty()] : boolean USimpleNameReferenceExpression (identifier = str) [str] : java.lang.String UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [isNotEmpty()] : boolean UIdentifier (Identifier (isNotEmpty)) [UIdentifier (Identifier (isNotEmpty))] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UExpressionList (when_entry) [{...] UYieldExpression [yield null] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null USwitchClauseExpressionWithBody [ -> {...] UExpressionList (when_entry) [{...] UYieldExpression [yield 1] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fir.txt index b2e185f2958c..865c256d43e3 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/AnnotatedExpressions.types.fir.txt @@ -55,17 +55,17 @@ UFile (package = ) [public final class AnnotatedExpressionsKt {...] UIdentifier (Identifier (isBlank)) [UIdentifier (Identifier (isBlank))] UExpressionList (when_entry) [{...] UYieldExpression [yield null] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null USwitchClauseExpressionWithBody [str.isNotEmpty() != null -> {...] UBinaryExpression (operator = !=) [str.isNotEmpty() != null] : boolean UQualifiedReferenceExpression [str.isNotEmpty()] : boolean USimpleNameReferenceExpression (identifier = str) [str] : java.lang.String UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [isNotEmpty()] : boolean UIdentifier (Identifier (isNotEmpty)) [UIdentifier (Identifier (isNotEmpty))] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UExpressionList (when_entry) [{...] UYieldExpression [yield null] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null USwitchClauseExpressionWithBody [ -> {...] UExpressionList (when_entry) [{...] UYieldExpression [yield 1] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fe10.txt index b310ea938ddd..165a2bdc1078 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fe10.txt @@ -3,7 +3,7 @@ UFile (package = ) [public final class CycleInTypeParametersKt {...] UField (name = a) [@org.jetbrains.annotations.Nullable private static final var a: Device = null as? Device] UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] UBinaryExpressionWithType [null as? Device] : Device - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UTypeReferenceExpression (name = Device) [Device] UMethod (name = getA) [public static final fun getA() : Device = UastEmptyExpression] UClass (name = Device) [public final class Device {...}] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fir.txt index a3a97dc5ecbc..9b01ad7dd2d0 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/CycleInTypeParameters.types.fir.txt @@ -3,7 +3,7 @@ UFile (package = ) [public final class CycleInTypeParametersKt {...] UField (name = a) [@org.jetbrains.annotations.Nullable private static final var a: Device = null as? Device] UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] UBinaryExpressionWithType [null as? Device] : @org.jetbrains.annotations.Nullable() Device - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UTypeReferenceExpression (name = Device) [Device] UMethod (name = getA) [public static final fun getA() : Device = UastEmptyExpression] UClass (name = Device) [public final class Device {...}] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.fir.txt deleted file mode 100644 index 138c45995463..000000000000 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.fir.txt +++ /dev/null @@ -1,10 +0,0 @@ -UFile (package = ) [public final class DefaultParameterValuesKt {...] - UClass (name = DefaultParameterValuesKt) [public final class DefaultParameterValuesKt {...}] - UMethod (name = foo) [public static final fun foo(@org.jetbrains.annotations.NotNull a: int, @org.jetbrains.annotations.Nullable foo: java.lang.String) : void {...}] - UParameter (name = a) [@org.jetbrains.annotations.NotNull var a: int = 1] - UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] - ULiteralExpression (value = 1) [1] : int - UParameter (name = foo) [@org.jetbrains.annotations.Nullable var foo: java.lang.String = null] - UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void - UBlockExpression [{...}] : void diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.txt similarity index 87% rename from plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.fe10.txt rename to plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.txt index 606d55a7a797..b28a702f7103 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/DefaultParameterValues.types.txt @@ -6,5 +6,5 @@ UFile (package = ) [public final class DefaultParameterValuesKt {...] ULiteralExpression (value = 1) [1] : int UParameter (name = foo) [@org.jetbrains.annotations.Nullable var foo: java.lang.String = null] UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] - ULiteralExpression (value = null) [null] : java.lang.Void - UBlockExpression [{...}] : void + ULiteralExpression (value = null) [null] : null + UBlockExpression [{...}] : void \ No newline at end of file diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fe10.txt index 1f4fb890ed19..0244e2f86b74 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fe10.txt @@ -5,7 +5,7 @@ UFile (package = ) [public final class ElvisKt {...] UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] UBlockExpression [{...}] UReturnExpression [return null] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UMethod (name = bar) [public static final fun bar() : int {...}] UBlockExpression [{...}] UReturnExpression [return 42] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fir.txt index f019652a8f85..0954075b8a94 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/Elvis.types.fir.txt @@ -5,7 +5,7 @@ UFile (package = ) [public final class ElvisKt {...] UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] UBlockExpression [{...}] UReturnExpression [return null] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UMethod (name = bar) [public static final fun bar() : int {...}] UBlockExpression [{...}] UReturnExpression [return 42] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fe10.txt index b8673db8a91d..b69778067542 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fe10.txt @@ -20,7 +20,7 @@ UFile (package = ) [public final enum Style {...] UEnumConstant (name = UNKNOWN) [@null UNKNOWN(null)] UAnnotation (fqName = null) [@null] USimpleNameReferenceExpression (identifier = Style) [Style] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UMethod (name = getValue) [public final fun getValue() : java.lang.String = UastEmptyExpression] UMethod (name = Style) [private fun Style(@org.jetbrains.annotations.Nullable value: java.lang.String) = UastEmptyExpression] UParameter (name = value) [@org.jetbrains.annotations.Nullable var value: java.lang.String] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fir.txt index fc715e1691d2..91efacce0480 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/EnumValuesConstructors.types.fir.txt @@ -20,7 +20,7 @@ UFile (package = ) [public final enum Style {...] UEnumConstant (name = UNKNOWN) [@null UNKNOWN(null)] UAnnotation (fqName = null) [@null] USimpleNameReferenceExpression (identifier = Style) [Style] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UMethod (name = values) [public static fun values() : Style[] = UastEmptyExpression] UMethod (name = valueOf) [public static fun valueOf(value: java.lang.String) : Style = UastEmptyExpression] UParameter (name = value) [var value: java.lang.String] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.fir.txt deleted file mode 100644 index 5ae41bd51399..000000000000 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.fir.txt +++ /dev/null @@ -1,18 +0,0 @@ -UFile (package = ) [public final class TypeAliasExpansionWithOtherAliasInArgumentKt {...] - UClass (name = TypeAliasExpansionWithOtherAliasInArgumentKt) [public final class TypeAliasExpansionWithOtherAliasInArgumentKt {...}] - UMethod (name = foo) [public static final fun foo(@org.jetbrains.annotations.NotNull $this$foo: kotlin.jvm.functions.Function1,kotlin.Unit>, @org.jetbrains.annotations.NotNull x: kotlin.jvm.functions.Function1,kotlin.Unit>) : kotlin.jvm.functions.Function1,kotlin.Unit> {...}] - UParameter (name = $this$foo) [@org.jetbrains.annotations.NotNull var $this$foo: kotlin.jvm.functions.Function1,kotlin.Unit>] - UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] - UParameter (name = x) [@org.jetbrains.annotations.NotNull var x: kotlin.jvm.functions.Function1,kotlin.Unit>] - UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] - UBlockExpression [{...}] - UReturnExpression [return null] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void - UMethod (name = bar) [public static final fun bar(@org.jetbrains.annotations.NotNull $this$bar: java.util.Map, @org.jetbrains.annotations.NotNull x: java.util.Map) : java.util.Map {...}] - UParameter (name = $this$bar) [@org.jetbrains.annotations.NotNull var $this$bar: java.util.Map] - UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] - UParameter (name = x) [@org.jetbrains.annotations.NotNull var x: java.util.Map] - UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] - UBlockExpression [{...}] - UReturnExpression [return null] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.txt similarity index 93% rename from plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.fe10.txt rename to plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.txt index 40774c78a443..2abed47d0df0 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/legacyTypes/TypeAliasExpansionWithOtherAliasInArgument.types.txt @@ -7,7 +7,7 @@ UFile (package = ) [public final class TypeAliasExpansionWithOtherAliasInArgumen UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] UBlockExpression [{...}] UReturnExpression [return null] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UMethod (name = bar) [public static final fun bar(@org.jetbrains.annotations.NotNull $this$bar: java.util.Map, @org.jetbrains.annotations.NotNull x: java.util.Map) : java.util.Map {...}] UParameter (name = $this$bar) [@org.jetbrains.annotations.NotNull var $this$bar: java.util.Map] UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] @@ -15,4 +15,4 @@ UFile (package = ) [public final class TypeAliasExpansionWithOtherAliasInArgumen UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] UBlockExpression [{...}] UReturnExpression [return null] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null \ No newline at end of file diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fe10.txt index c70f4a4debe7..4ae62463d76b 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fe10.txt @@ -34,7 +34,7 @@ UFile (package = ) [public final class ClassLiteralKt {...] UIfExpression [if (other == null) return false] : kotlin.Unit UBinaryExpression (operator = ==) [other == null] : boolean USimpleNameReferenceExpression (identifier = other) [other] : java.lang.Object - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return false] : java.lang.Void ULiteralExpression (value = false) [false] : boolean UIfExpression [if (java.lang.Object != Foo) return false] : kotlin.Unit diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fir.txt index 944924801a94..ad213ae3bfe9 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/classLiteral.types.fir.txt @@ -34,7 +34,7 @@ UFile (package = ) [public final class ClassLiteralKt {...] UIfExpression [if (other == null) return false] : @org.jetbrains.annotations.NotNull() kotlin.Unit UBinaryExpression (operator = ==) [other == null] : boolean USimpleNameReferenceExpression (identifier = other) [other] : @org.jetbrains.annotations.Nullable() java.lang.Object - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return false] : @org.jetbrains.annotations.NotNull() java.lang.Void ULiteralExpression (value = false) [false] : boolean UIfExpression [if (java.lang.Object != Foo) return false] : @org.jetbrains.annotations.NotNull() kotlin.Unit diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fe10.txt index cce6c09daf19..c973396b6c04 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fe10.txt @@ -37,7 +37,7 @@ UFile (package = test.pkg) [package test.pkg...] UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] UBlockExpression [{...}] : java.lang.Void UReturnExpression [return null] : java.lang.Void - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UClass (name = ArrayMap) [public final class ArrayMap : java.util.HashMap {...}] UMethod (name = ArrayMap) [public fun ArrayMap() {...}] UBlockExpression [{...}] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fir.txt index ebd9b9f7b4ae..4bc4a96756ec 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/nullnessInVarargs.types.fir.txt @@ -37,7 +37,7 @@ UFile (package = test.pkg) [package test.pkg...] UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] UBlockExpression [{...}] : @org.jetbrains.annotations.NotNull() java.lang.Void UReturnExpression [return null] : @org.jetbrains.annotations.NotNull() java.lang.Void - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UClass (name = ArrayMap) [public final class ArrayMap : java.util.HashMap {...}] UMethod (name = ArrayMap) [public fun ArrayMap() {...}] UBlockExpression [{...}] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fe10.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fe10.txt index 9cb88f882fac..13e269652e6c 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fe10.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fe10.txt @@ -4,13 +4,13 @@ UFile (package = ) [public final class WithGenericKt {...] UBlockExpression [{...}] UReturnExpression [return null as T] UBinaryExpressionWithType [null as T] : T - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UTypeReferenceExpression (name = T) [T] UMethod (name = test2) [public static final fun test2() : T {...}] UBlockExpression [{...}] : java.lang.Void UDeclarationsExpression [var a: java.lang.Object = null] ULocalVariable (name = a) [var a: java.lang.Object = null] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return a as T] : java.lang.Void UBinaryExpressionWithType [a as T] : T USimpleNameReferenceExpression (identifier = a) [a] : java.lang.Object @@ -19,7 +19,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBlockExpression [{...}] UReturnExpression [return null as T] UBinaryExpressionWithType [null as T] : T - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UTypeReferenceExpression (name = T) [T] UMethod (name = castToString) [public static final fun castToString(t: T) : void {...}] UParameter (name = t) [var t: T] @@ -33,7 +33,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBinaryExpression (operator = !=) [test1() != null] : boolean UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [test1()] : int UIdentifier (Identifier (test1)) [UIdentifier (Identifier (test1))] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return "fail: test1"] : java.lang.Void UPolyadicExpression (operator = +) ["fail: test1"] : java.lang.String ULiteralExpression (value = "fail: test1") ["fail: test1"] : java.lang.String @@ -41,7 +41,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBinaryExpression (operator = !=) [test2() != null] : boolean UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [test2()] : int UIdentifier (Identifier (test2)) [UIdentifier (Identifier (test2))] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return "fail: test2"] : java.lang.Void UPolyadicExpression (operator = +) ["fail: test2"] : java.lang.String ULiteralExpression (value = "fail: test2") ["fail: test2"] : java.lang.String @@ -73,7 +73,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBlockExpression [{...}] : kotlin.Unit UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [castToString(null)] : kotlin.Unit UIdentifier (Identifier (castToString)) [UIdentifier (Identifier (castToString))] - ULiteralExpression (value = null) [null] : java.lang.Void + ULiteralExpression (value = null) [null] : null UCatchClause (e) [catch (@org.jetbrains.annotations.NotNull var e: java.lang.Exception) {...}] UParameter (name = e) [@org.jetbrains.annotations.NotNull var e: java.lang.Exception] UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fir.txt b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fir.txt index a62dee116931..8b3c5687df96 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fir.txt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/testData/type/withGeneric.types.fir.txt @@ -4,13 +4,13 @@ UFile (package = ) [public final class WithGenericKt {...] UBlockExpression [{...}] UReturnExpression [return null as T] UBinaryExpressionWithType [null as T] : T - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UTypeReferenceExpression (name = T) [T] UMethod (name = test2) [public static final fun test2() : T {...}] UBlockExpression [{...}] : @org.jetbrains.annotations.NotNull() java.lang.Void UDeclarationsExpression [var a: java.lang.Object = null] ULocalVariable (name = a) [var a: java.lang.Object = null] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return a as T] : @org.jetbrains.annotations.NotNull() java.lang.Void UBinaryExpressionWithType [a as T] : T USimpleNameReferenceExpression (identifier = a) [a] : @org.jetbrains.annotations.Nullable() java.lang.Object @@ -19,7 +19,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBlockExpression [{...}] UReturnExpression [return null as T] UBinaryExpressionWithType [null as T] : @org.jetbrains.annotations.NotNull() T - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UTypeReferenceExpression (name = T) [T] UMethod (name = castToString) [public static final fun castToString(t: T) : void {...}] UParameter (name = t) [var t: T] @@ -33,7 +33,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBinaryExpression (operator = !=) [test1() != null] : boolean UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [test1()] : int UIdentifier (Identifier (test1)) [UIdentifier (Identifier (test1))] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return "fail: test1"] : @org.jetbrains.annotations.NotNull() java.lang.Void UPolyadicExpression (operator = +) ["fail: test1"] : java.lang.String ULiteralExpression (value = "fail: test1") ["fail: test1"] : java.lang.String @@ -41,7 +41,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBinaryExpression (operator = !=) [test2() != null] : boolean UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [test2()] : int UIdentifier (Identifier (test2)) [UIdentifier (Identifier (test2))] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UReturnExpression [return "fail: test2"] : @org.jetbrains.annotations.NotNull() java.lang.Void UPolyadicExpression (operator = +) ["fail: test2"] : java.lang.String ULiteralExpression (value = "fail: test2") ["fail: test2"] : java.lang.String @@ -73,7 +73,7 @@ UFile (package = ) [public final class WithGenericKt {...] UBlockExpression [{...}] : @org.jetbrains.annotations.NotNull() kotlin.Unit UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [castToString(null)] : @org.jetbrains.annotations.NotNull() kotlin.Unit UIdentifier (Identifier (castToString)) [UIdentifier (Identifier (castToString))] - ULiteralExpression (value = null) [null] : @org.jetbrains.annotations.Nullable() java.lang.Void + ULiteralExpression (value = null) [null] : null UCatchClause (e) [catch (@org.jetbrains.annotations.NotNull var e: java.lang.Exception) {...}] UParameter (name = e) [@org.jetbrains.annotations.NotNull var e: java.lang.Exception] UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] diff --git a/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1UastApiFixtureTest.kt b/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1UastApiFixtureTest.kt index cfc789400cd6..c84d67e6f670 100644 --- a/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1UastApiFixtureTest.kt +++ b/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1UastApiFixtureTest.kt @@ -134,4 +134,8 @@ class FE1UastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi fun testNameReferenceVisitInConstructorCall() { checkNameReferenceVisitInConstructorCall(myFixture) } + + fun testNullLiteral() { + checkNullLiteral(myFixture) + } } \ No newline at end of file diff --git a/plugins/kotlin/uast/uast-kotlin/tests/testData/CycleInTypeParameters.types.txt b/plugins/kotlin/uast/uast-kotlin/tests/testData/CycleInTypeParameters.types.txt index 1dad6756ecc5..32ac3da8103f 100644 --- a/plugins/kotlin/uast/uast-kotlin/tests/testData/CycleInTypeParameters.types.txt +++ b/plugins/kotlin/uast/uast-kotlin/tests/testData/CycleInTypeParameters.types.txt @@ -3,7 +3,7 @@ UFile (package = ) [public final class CycleInTypeParametersKt {...] UField (name = a) [@org.jetbrains.annotations.Nullable private static final var a: Device = null as? Device] UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable] UBinaryExpressionWithType [null as? Device] : PsiType:Device - ULiteralExpression (value = null) [null] : PsiType:Void + ULiteralExpression (value = null) [null] : PsiType:null UTypeReferenceExpression (name = Device) [Device] UMethod (name = getA) [public static final fun getA() : Device = UastEmptyExpression] UClass (name = Device) [public final class Device {...}] diff --git a/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt b/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt index 90971a123f9e..587bc723652c 100644 --- a/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt +++ b/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt @@ -276,4 +276,31 @@ class JavaUastApiTest : AbstractJavaUastTest() { ) TestCase.assertEquals(1, count) } + + @Test + fun testNullLiteral() { + val file = myFixture.configureByText( + "Test.java", + """ + class Test { + static void test() { + Object foo = null; + } + } + """.trimIndent() + ) + val uFile = file.toUElementOfType()!! + var count = 0 + uFile.accept( + object : AbstractUastVisitor() { + override fun visitLiteralExpression(node: ULiteralExpression): Boolean { + TestCase.assertTrue(node.isNull) + TestCase.assertEquals("null", node.getExpressionType()?.canonicalText) + count++ + return super.visitLiteralExpression(node) + } + } + ) + TestCase.assertEquals(1, count) + } }