172: Uast-revert: reverting to previous rebase state
This commit is contained in:
committed by
Nikolay Krasko
parent
c6bb0ad712
commit
a15d48c444
@@ -1,12 +1,10 @@
|
||||
package org.jetbrains.uast.test.kotlin
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiModifier
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.asJava.toLightAnnotation
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getValueParameterList
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.uast.*
|
||||
@@ -109,14 +107,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun testConvertTypeInAnnotation() {
|
||||
doTest("TypeInAnnotation") { _, file ->
|
||||
val index = file.psi.text.indexOf("Test")
|
||||
val element = file.psi.findElementAt(index)!!.getParentOfType<KtUserType>(false)!!
|
||||
assertNotNull(element.getUastParentOfType(UAnnotation::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun testElvisType() {
|
||||
doTest("ElvisType") { _, file ->
|
||||
val elvisExpression = file.findElementByText<UExpression>("text ?: return")
|
||||
@@ -195,68 +185,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleAnnotated() {
|
||||
doTest("SimpleAnnotated") { _, file ->
|
||||
file.findElementByTextFromPsi<UField>("@SinceKotlin(\"1.0\")\n val property: String = \"Mary\"").let { field ->
|
||||
val annotation = field.annotations.assertedFind("kotlin.SinceKotlin") { it.qualifiedName }
|
||||
Assert.assertEquals(annotation.findDeclaredAttributeValue("version")?.evaluateString(), "1.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun UFile.checkUastSuperTypes(refText: String, superTypes: List<String>) {
|
||||
findElementByTextFromPsi<UClass>(refText, false).let {
|
||||
assertEquals("base classes", superTypes, it.uastSuperTypes.map { it.getQualifiedName() })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testSuperTypes() {
|
||||
doTest("SuperCalls") { _, file ->
|
||||
file.checkUastSuperTypes("B", listOf("A"))
|
||||
file.checkUastSuperTypes("O", listOf("A"))
|
||||
file.checkUastSuperTypes("innerObject ", listOf("A"))
|
||||
file.checkUastSuperTypes("InnerClass", listOf("A"))
|
||||
file.checkUastSuperTypes("object : A(\"textForAnon\")", listOf("A"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnonymousSuperTypes() {
|
||||
doTest("Anonymous") { _, file ->
|
||||
file.checkUastSuperTypes("object : Runnable { override fun run() {} }", listOf("java.lang.Runnable"))
|
||||
file.checkUastSuperTypes(
|
||||
"object : Runnable, Closeable { override fun close() {} override fun run() {} }",
|
||||
listOf("java.lang.Runnable", "java.io.Closeable")
|
||||
)
|
||||
file.checkUastSuperTypes(
|
||||
"object : InputStream(), Runnable { override fun read(): Int = 0; override fun run() {} }",
|
||||
listOf("java.io.InputStream", "java.lang.Runnable")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLiteralArraysTypes() {
|
||||
doTest("AnnotationParameters") { _, file ->
|
||||
file.findElementByTextFromPsi<UCallExpression>("intArrayOf(1, 2, 3)").let { field ->
|
||||
Assert.assertEquals("PsiType:int[]", field.returnType.toString())
|
||||
}
|
||||
file.findElementByTextFromPsi<UCallExpression>("[1, 2, 3]").let { field ->
|
||||
Assert.assertEquals("PsiType:int[]", field.returnType.toString())
|
||||
Assert.assertEquals("PsiType:int", field.typeArguments.single().toString())
|
||||
}
|
||||
file.findElementByTextFromPsi<UCallExpression>("[\"a\", \"b\", \"c\"]").let { field ->
|
||||
Assert.assertEquals("PsiType:String[]", field.returnType.toString())
|
||||
Assert.assertEquals("PsiType:String", field.typeArguments.single().toString())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTypeAliases() {
|
||||
doTest("TypeAliases") { _, file ->
|
||||
@@ -266,26 +194,4 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
Assert.assertTrue((originalTypeParameters.declarations.single() as UParameter).type.isValid)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNestedAnnotation() = doTest("AnnotationComplex") { _, file ->
|
||||
file.findElementByTextFromPsi<UElement>("@AnnotationArray(value = Annotation())")
|
||||
.findElementByTextFromPsi<UElement>("Annotation()")
|
||||
.sourcePsiElement
|
||||
.let { referenceExpression ->
|
||||
val convertedUAnnotation = referenceExpression
|
||||
.cast<KtReferenceExpression>()
|
||||
.toUElementOfType<UAnnotation>()
|
||||
?: throw AssertionError("haven't got annotation from $referenceExpression(${referenceExpression?.javaClass})")
|
||||
|
||||
assertEquals("Annotation", convertedUAnnotation.qualifiedName)
|
||||
val lightAnnotation = convertedUAnnotation.getAsJavaPsiElement(PsiAnnotation::class.java)
|
||||
?: throw AssertionError("can't get lightAnnotation from $convertedUAnnotation")
|
||||
assertEquals("Annotation", lightAnnotation.qualifiedName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun <T, R> Iterable<T>.assertedFind(value: R, transform: (T) -> R): T = find { transform(it) == value } ?: throw AssertionError("'$value' not found, only ${this.joinToString { transform(it).toString() }}")
|
||||
|
||||
@@ -47,11 +47,9 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() {
|
||||
|
||||
@Test fun testParametersWithDefaultValues() = doTest("ParametersWithDefaultValues")
|
||||
|
||||
@Test
|
||||
fun testUnexpectedContainer() = doTest("UnexpectedContainerException")
|
||||
@Test fun testUnexpectedContainer() = doTest("UnexpectedContainerException") { testName, file -> check(testName, file, false) }
|
||||
|
||||
@Test
|
||||
fun testWhenStringLiteral() = doTest("WhenStringLiteral")
|
||||
@Test fun testWhenStringLiteral() = doTest("WhenStringLiteral") { testName, file -> check(testName, file, false) }
|
||||
|
||||
@Test
|
||||
fun testWhenAndDestructing() = doTest("WhenAndDestructing") { testName, file -> check(testName, file, false) }
|
||||
@@ -61,16 +59,4 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() {
|
||||
|
||||
@Test
|
||||
fun testConstructors() = doTest("Constructors")
|
||||
|
||||
@Test
|
||||
fun testClassAnnotation() = doTest("ClassAnnotation")
|
||||
|
||||
@Test
|
||||
fun testReceiverFun() = doTest("ReceiverFun")
|
||||
|
||||
@Test
|
||||
fun testAnonymous() = doTest("Anonymous")
|
||||
|
||||
@Test
|
||||
fun testAnnotationComplex() = doTest("AnnotationComplex")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user