diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt index be24b6c18c5..33ba078bae1 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -197,6 +197,7 @@ internal object KotlinConverter { is KtSuperTypeList -> unwrapElements(element.parent) is KtFinallySection -> unwrapElements(element.parent) is KtAnnotatedExpression -> unwrapElements(element.parent) + is KtWhenConditionWithExpression -> unwrapElements(element.parent) else -> element } diff --git a/plugins/uast-kotlin/testData/AnnotatedExpressions.kt b/plugins/uast-kotlin/testData/AnnotatedExpressions.kt index edad5ec9b2b..c2a7655c9b2 100644 --- a/plugins/uast-kotlin/testData/AnnotatedExpressions.kt +++ b/plugins/uast-kotlin/testData/AnnotatedExpressions.kt @@ -20,4 +20,12 @@ fun foo() { val c = @Suppress a ?: b -} \ No newline at end of file +} + +fun annotatedSwitch(str: String) = + when { + @Suppress("DEPRECATION") + str.isBlank() -> null + str.isNotEmpty() != null -> null + else -> 1 + } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt b/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt index fe94409fe00..a3cfac55590 100644 --- a/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt +++ b/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt @@ -38,3 +38,38 @@ UFile (package = ) ULiteralExpression (value = null) USimpleNameReferenceExpression (identifier = varae507364) USimpleNameReferenceExpression (identifier = b) + UMethod (name = annotatedSwitch) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + USwitchExpression + UExpressionList (when) + USwitchClauseExpressionWithBody + UQualifiedReferenceExpression + UAnnotation (fqName = kotlin.Suppress) + UNamedExpression (name = names) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "DEPRECATION") + USimpleNameReferenceExpression (identifier = str) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (isBlank)) + USimpleNameReferenceExpression (identifier = isBlank, resolvesTo = null) + UExpressionList (when_entry) + UYieldExpression + ULiteralExpression (value = null) + USwitchClauseExpressionWithBody + UBinaryExpression (operator = !=) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = str) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (isNotEmpty)) + USimpleNameReferenceExpression (identifier = isNotEmpty, resolvesTo = null) + ULiteralExpression (value = null) + UExpressionList (when_entry) + UYieldExpression + ULiteralExpression (value = null) + USwitchClauseExpressionWithBody + UExpressionList (when_entry) + UYieldExpression + ULiteralExpression (value = 1) diff --git a/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt.192 b/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt.192 new file mode 100644 index 00000000000..970e077fe0a --- /dev/null +++ b/plugins/uast-kotlin/testData/AnnotatedExpressions.log.txt.192 @@ -0,0 +1,75 @@ +UFile (package = ) + UClass (name = AnnotatedExpressionsKt) + UMethod (name = foo) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UAnnotation (fqName = kotlin.Suppress) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo, resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = a) + UAnnotation (fqName = kotlin.Suppress) + ULiteralExpression (value = 1) + UDeclarationsExpression + ULocalVariable (name = b) + UAnnotation (fqName = kotlin.Suppress) + ULiteralExpression (value = 2) + UBinaryExpression (operator = =) + UAnnotation (fqName = kotlin.Suppress) + USimpleNameReferenceExpression (identifier = b) + USimpleNameReferenceExpression (identifier = a) + UIfExpression + UAnnotation (fqName = kotlin.Suppress) + UBinaryExpression (operator = >) + USimpleNameReferenceExpression (identifier = a) + ULiteralExpression (value = 2) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = b) + UDeclarationsExpression + ULocalVariable (name = c) + UExpressionList (elvis) + UDeclarationsExpression + ULocalVariable (name = varae507364) + USimpleNameReferenceExpression (identifier = a) + UAnnotation (fqName = kotlin.Suppress) + UIfExpression + UBinaryExpression (operator = !=) + USimpleNameReferenceExpression (identifier = varae507364) + ULiteralExpression (value = null) + USimpleNameReferenceExpression (identifier = varae507364) + USimpleNameReferenceExpression (identifier = b) + UMethod (name = annotatedSwitch) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + USwitchExpression + UExpressionList (when) + USwitchClauseExpressionWithBody + UQualifiedReferenceExpression + UAnnotation (fqName = kotlin.Suppress) + UNamedExpression (name = names) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "DEPRECATION") + USimpleNameReferenceExpression (identifier = str) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (isBlank)) + USimpleNameReferenceExpression (identifier = isBlank, resolvesTo = null) + UExpressionList (when_entry) + ULiteralExpression (value = null) + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UBinaryExpression (operator = !=) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = str) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (isNotEmpty)) + USimpleNameReferenceExpression (identifier = isNotEmpty, resolvesTo = null) + ULiteralExpression (value = null) + UExpressionList (when_entry) + ULiteralExpression (value = null) + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UExpressionList (when_entry) + ULiteralExpression (value = 1) + UBreakExpression (label = null) diff --git a/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt b/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt index fac12e18f9b..6ff5390c33f 100644 --- a/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt +++ b/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt @@ -10,4 +10,21 @@ public final class AnnotatedExpressionsKt { if (varae507364 != null) varae507364 else b } } + public static final fun annotatedSwitch(@org.jetbrains.annotations.NotNull str: java.lang.String) : java.lang.Integer { + return switch { + str.isBlank() -> { + yield null + } + + str.isNotEmpty() != null -> { + yield null + } + + -> { + yield 1 + } + + } + + } } diff --git a/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt.192 b/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt.192 new file mode 100644 index 00000000000..fbce5252cea --- /dev/null +++ b/plugins/uast-kotlin/testData/AnnotatedExpressions.render.txt.192 @@ -0,0 +1,33 @@ +public final class AnnotatedExpressionsKt { + public static final fun foo() : void { + foo() + @kotlin.Suppress var a: int = 1 + @kotlin.Suppress var b: int = 2 + b = a + if (a > 2) a else b + var c: int = elvis { + var varae507364: int = a + if (varae507364 != null) varae507364 else b + } + } + public static final fun annotatedSwitch(@org.jetbrains.annotations.NotNull str: java.lang.String) : java.lang.Integer { + return switch { + str.isBlank() -> { + null + break + } + + str.isNotEmpty() != null -> { + null + break + } + + -> { + 1 + break + } + + } + + } +}