Test for KT-22527

This commit is contained in:
Mikhail Glukhikh
2018-04-19 13:29:49 +03:00
parent 29c16f9561
commit f179b2ba13
5 changed files with 138 additions and 4 deletions
+9
View File
@@ -0,0 +1,9 @@
class MyColor(val x: Int, val y: Int, val z: Int)
class Some {
val delegate by lazy { MyColor(0x12 /* constant = 18 */, 2, 3) }
val lambda = lazy { MyColor(1, 2, 3) }
val nonLazy = MyColor(1, 2, 3)
}
+65
View File
@@ -0,0 +1,65 @@
UFile (package = ) [public final class MyColor {...]
UClass (name = MyColor) [public final class MyColor {...}]
UField (name = x) [@org.jetbrains.annotations.NotNull private final var x: int]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UField (name = y) [@org.jetbrains.annotations.NotNull private final var y: int]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UField (name = z) [@org.jetbrains.annotations.NotNull private final var z: int]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UAnnotationMethod (name = getX) [public final fun getX() : int = UastEmptyExpression]
UAnnotationMethod (name = getY) [public final fun getY() : int = UastEmptyExpression]
UAnnotationMethod (name = getZ) [public final fun getZ() : int = UastEmptyExpression]
UAnnotationMethod (name = MyColor) [public fun MyColor(@org.jetbrains.annotations.NotNull x: int, @org.jetbrains.annotations.NotNull y: int, @org.jetbrains.annotations.NotNull z: int) = UastEmptyExpression]
UParameter (name = x) [@org.jetbrains.annotations.NotNull var x: int]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UParameter (name = y) [@org.jetbrains.annotations.NotNull var y: int]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UParameter (name = z) [@org.jetbrains.annotations.NotNull var z: int]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UClass (name = Some) [public final class Some {...}]
UField (name = delegate$delegate) [@org.jetbrains.annotations.NotNull private final var delegate$delegate: kotlin.Lazy]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [lazy({ ...})] = external lazy({
<init>(18, 2, 3)
})(Undetermined)
UIdentifier (Identifier (lazy)) [UIdentifier (Identifier (lazy))]
USimpleNameReferenceExpression (identifier = lazy) [lazy] = external lazy({
<init>(18, 2, 3)
})(Undetermined)
ULambdaExpression [{ ...}] = Undetermined
UBlockExpression [{...}] = external <init>(18, 2, 3)(18, 2, 3)
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 3)) [<init>(18, 2, 3)] = external <init>(18, 2, 3)(18, 2, 3)
UIdentifier (Identifier (MyColor)) [UIdentifier (Identifier (MyColor))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>(18, 2, 3)(18, 2, 3)
ULiteralExpression (value = 18) [18] = 18
ULiteralExpression (value = 2) [2] = 2
ULiteralExpression (value = 3) [3] = 3
UField (name = lambda) [@org.jetbrains.annotations.NotNull private final var lambda: kotlin.Lazy<MyColor> = lazy({ ...})]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [lazy({ ...})] = external lazy({
<init>(1, 2, 3)
})(Undetermined)
UIdentifier (Identifier (lazy)) [UIdentifier (Identifier (lazy))]
USimpleNameReferenceExpression (identifier = lazy) [lazy] = external lazy({
<init>(1, 2, 3)
})(Undetermined)
ULambdaExpression [{ ...}] = Undetermined
UBlockExpression [{...}] = external <init>(1, 2, 3)(1, 2, 3)
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 3)) [<init>(1, 2, 3)] = external <init>(1, 2, 3)(1, 2, 3)
UIdentifier (Identifier (MyColor)) [UIdentifier (Identifier (MyColor))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>(1, 2, 3)(1, 2, 3)
ULiteralExpression (value = 1) [1] = 1
ULiteralExpression (value = 2) [2] = 2
ULiteralExpression (value = 3) [3] = 3
UField (name = nonLazy) [@org.jetbrains.annotations.NotNull private final var nonLazy: MyColor = <init>(1, 2, 3)]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 3)) [<init>(1, 2, 3)] = external <init>(1, 2, 3)(1, 2, 3)
UIdentifier (Identifier (MyColor)) [UIdentifier (Identifier (MyColor))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>(1, 2, 3)(1, 2, 3)
ULiteralExpression (value = 1) [1] = 1
ULiteralExpression (value = 2) [2] = 2
ULiteralExpression (value = 3) [3] = 3
UAnnotationMethod (name = getDelegate) [public final fun getDelegate() : MyColor = UastEmptyExpression]
UAnnotationMethod (name = getLambda) [public final fun getLambda() : kotlin.Lazy<MyColor> = UastEmptyExpression]
UAnnotationMethod (name = getNonLazy) [public final fun getNonLazy() : MyColor = UastEmptyExpression]
UAnnotationMethod (name = Some) [public fun Some() = UastEmptyExpression]
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.uast.test.kotlin
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.UFile
import org.jetbrains.uast.evaluation.uValueOf
import org.jetbrains.uast.visitor.UastVisitor
abstract class AbstractKotlinExpressionValueTest : AbstractKotlinUastTest() {
override fun check(testName: String, file: UFile) {
var valuesFound = 0
file.accept(object : UastVisitor {
override fun visitElement(node: UElement): Boolean {
for (comment in node.comments) {
val text = comment.text.removePrefix("/* ").removeSuffix(" */")
val parts = text.split(" = ")
if (parts.size != 2) continue
when (parts[0]) {
"constant" -> {
val expectedValue = parts[1]
val actualValue =
(node as? UExpression)?.uValueOf()?.toConstant()?.toString()
?: "cannot evaluate $node of ${node.javaClass}"
assertEquals(expectedValue, actualValue)
valuesFound++
}
}
}
return false
}
})
assertTrue("No values found, add some /* constant = ... */ to the input file", valuesFound > 0)
}
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.uast.test.kotlin
import org.junit.Test
class KotlinExpressionValueTest : AbstractKotlinExpressionValueTest() {
@Test
fun testDelegate() = doTest("Delegate")
}
@@ -4,11 +4,18 @@ import org.junit.Test
class KotlinUastValuesTest : AbstractKotlinValuesTest() {
@Test fun testAssertion() = doTest("Assertion")
@Test
fun testAssertion() = doTest("Assertion")
@Test fun testIn() = doTest("In")
@Test
fun testDelegate() = doTest("Delegate")
@Test fun testLocalDeclarations() = doTest("LocalDeclarations")
@Test
fun testIn() = doTest("In")
@Test fun testSimple() = doTest("Simple")
@Test
fun testLocalDeclarations() = doTest("LocalDeclarations")
@Test
fun testSimple() = doTest("Simple")
}