From ec26ea4e3620d7dd92e6ccf580e6168c5b0f91e2 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Thu, 28 Feb 2019 13:09:30 +0300 Subject: [PATCH] Uast: TypeReferences log test added --- .../kotlin/declarations/KotlinUVariable.kt | 1 + .../testData/TypeReferences.log.txt | 69 +++++++++++++++++++ .../testData/TypeReferences.render.txt | 22 ++++++ .../tests/SimpleKotlinRenderLogTest.kt | 3 + .../tests/SimpleKotlinRenderLogTest.kt.191 | 3 + 5 files changed, 98 insertions(+) create mode 100644 plugins/uast-kotlin/testData/TypeReferences.log.txt create mode 100644 plugins/uast-kotlin/testData/TypeReferences.render.txt diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt index c7aab9ae581..b30638861f6 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt @@ -107,6 +107,7 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?) : KotlinAbstractU // receiver param in extension function (it as? KtUserType)?.referenceExpression?.getIdentifier() ?: it } ?: sourcePsi + is KtNameReferenceExpression -> sourcePsi.getReferencedNameElement() is KtBinaryExpression, is KtCallExpression -> null // e.g. `foo("Lorem ipsum") ?: foo("dolor sit amet")` is KtDestructuringDeclaration -> sourcePsi.valOrVarKeyword else -> sourcePsi diff --git a/plugins/uast-kotlin/testData/TypeReferences.log.txt b/plugins/uast-kotlin/testData/TypeReferences.log.txt new file mode 100644 index 00000000000..56df6e6760c --- /dev/null +++ b/plugins/uast-kotlin/testData/TypeReferences.log.txt @@ -0,0 +1,69 @@ +UFile (package = ) + UClass (name = TypeReferencesKt) + UAnnotationMethod (name = foo) + UParameter (name = parameter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = varWithType) + ULiteralExpression (value = "Not Null") + UDeclarationsExpression + ULocalVariable (name = varWithoutType) + ULiteralExpression (value = "lorem ipsum") + UDeclarationsExpression + ULocalVariable (name = result) + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = varWithType) + USimpleNameReferenceExpression (identifier = varWithoutType) + UReturnExpression + USimpleNameReferenceExpression (identifier = result) + UAnnotationMethod (name = parameterizedFoo) + UParameter (name = arg) + UAnnotation (fqName = org.jetbrains.annotations.Nullable) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = a) + USimpleNameReferenceExpression (identifier = arg) + UDeclarationsExpression + ULocalVariable (name = at) + UExpressionList (elvis) + UDeclarationsExpression + ULocalVariable (name = var708e1d08) + UAnnotation (fqName = org.jetbrains.annotations.Nullable) + USimpleNameReferenceExpression (identifier = arg) + UIfExpression + UBinaryExpression (operator = !=) + USimpleNameReferenceExpression (identifier = var708e1d08) + ULiteralExpression (value = null) + USimpleNameReferenceExpression (identifier = var708e1d08) + UReturnExpression + UDeclarationsExpression + ULocalVariable (name = tl) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (listOf)) + USimpleNameReferenceExpression (identifier = listOf, resolvesTo = null) + USimpleNameReferenceExpression (identifier = at) + UDeclarationsExpression + ULocalVariable (name = tsl) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = tl) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (map)) + USimpleNameReferenceExpression (identifier = map, resolvesTo = null) + ULambdaExpression + UBlockExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = it) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = lls) + UDeclarationsExpression + ULocalVariable (name = llt) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (parameterizedFoo)) + USimpleNameReferenceExpression (identifier = parameterizedFoo, resolvesTo = null) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (emptyList)) + USimpleNameReferenceExpression (identifier = emptyList, resolvesTo = null) diff --git a/plugins/uast-kotlin/testData/TypeReferences.render.txt b/plugins/uast-kotlin/testData/TypeReferences.render.txt new file mode 100644 index 00000000000..dba88bbdea3 --- /dev/null +++ b/plugins/uast-kotlin/testData/TypeReferences.render.txt @@ -0,0 +1,22 @@ +public final class TypeReferencesKt { + public static final fun foo(@org.jetbrains.annotations.NotNull parameter: int) : java.lang.String { + var varWithType: java.lang.String = "Not Null" + var varWithoutType: java.lang.String = "lorem ipsum" + var result: java.lang.String = varWithType + varWithoutType + return result + } + public static final fun parameterizedFoo(@org.jetbrains.annotations.Nullable arg: T) : void { + var a: java.lang.Object = arg + var at: java.lang.Object = elvis { + @org.jetbrains.annotations.Nullable var var708e1d08: java.lang.Object = arg + if (var708e1d08 != null) var708e1d08 else return + } + var tl: java.util.List = listOf(at) + var tsl: java.util.List = tl.map({ + it.toString() + }) + var lls: java.util.List> + var llt: java.util.List> + parameterizedFoo(emptyList()) + } +} diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index 842dd418601..6a7e6f453da 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -85,6 +85,9 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testLambdas() = doTest("Lambdas") + @Test + fun testTypeReferences() = doTest("TypeReferences") + @Test fun testDelegate() = doTest("Delegate") diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 index 8d464f36a72..4e27b5cee53 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 @@ -91,6 +91,9 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testLambdas() = doTest("Lambdas") + @Test + fun testTypeReferences() = doTest("TypeReferences") + @Test fun testDelegate() = doTest("Delegate")