Move FIR tests to fir modules
This commit is contained in:
committed by
Mikhail Glukhikh
parent
95af0268b8
commit
cfb446df9e
@@ -16,9 +16,27 @@ dependencies {
|
||||
compile(project(":compiler:fir:tree"))
|
||||
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core", "annotations") }
|
||||
|
||||
testRuntime(intellijDep())
|
||||
|
||||
testCompile(commonDep("junit:junit"))
|
||||
testCompileOnly(project(":kotlin-test:kotlin-test-jvm"))
|
||||
testCompileOnly(project(":kotlin-test:kotlin-test-junit"))
|
||||
testCompile(projectTests(":compiler:tests-common"))
|
||||
|
||||
testCompileOnly(project(":kotlin-reflect-api"))
|
||||
testRuntime(project(":kotlin-reflect"))
|
||||
|
||||
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" {}
|
||||
}
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
projectTest {
|
||||
workingDir = rootDir
|
||||
}
|
||||
|
||||
testsJar()
|
||||
@@ -0,0 +1,4 @@
|
||||
open class A
|
||||
|
||||
|
||||
class B : A
|
||||
@@ -0,0 +1,9 @@
|
||||
FILE: F.kt
|
||||
public? open class A {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
public? final? class B : A {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
abstract class A {
|
||||
abstract class Nested
|
||||
}
|
||||
|
||||
typealias TA = A
|
||||
|
||||
class B : TA() {
|
||||
class NestedInB : Nested()
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
FILE: NestedOfAliasedType.kt
|
||||
public? abstract class A {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
public? abstract class Nested {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public? final typealias TA = A
|
||||
public? final? class B : TA {
|
||||
public? constructor(): super<TA>()
|
||||
|
||||
public? final? class NestedInB : Nested {
|
||||
public? constructor(): super<Nested>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package p
|
||||
|
||||
abstract class My {
|
||||
abstract class NestedOne : My() {
|
||||
abstract class NestedTwo : NestedOne() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Your : My() {
|
||||
class NestedThree : NestedOne()
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
FILE: NestedSuperType.kt
|
||||
public? abstract class My {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
public? abstract class NestedOne : My {
|
||||
public? constructor(): super<My>()
|
||||
|
||||
public? abstract class NestedTwo : NestedOne {
|
||||
public? constructor(): super<NestedOne>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public? final? class Your : My {
|
||||
public? constructor(): super<My>()
|
||||
|
||||
public? final? class NestedThree : NestedOne {
|
||||
public? constructor(): super<NestedOne>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package a.b
|
||||
|
||||
class C<T, out S> {
|
||||
inner class D<R, in P> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface Test {
|
||||
val x: a.b.C<out CharSequence, *>.D<in List<*>, *>
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
FILE: complexTypes.kt
|
||||
<T, out S> public? final? class C {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
<R, in P> public? final? inner class D {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public? final? interface Test {
|
||||
public? final? property x(val): a.b.C<out CharSequence, *>.D<in List<*>, *>
|
||||
public? get(): a.b.C<out CharSequence, *>.D<in List<*>, *>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
open class Base<T>(val x: T)
|
||||
|
||||
class Derived<T : Any>(x: T) : Base<T>(x)
|
||||
|
||||
fun <T : Any> create(x: T): Derived<T> = Derived(x)
|
||||
@@ -0,0 +1,15 @@
|
||||
FILE: derivedClass.kt
|
||||
<T> public? open class Base {
|
||||
public? constructor(x: T): super<kotlin.Any>()
|
||||
|
||||
public? final? property x(val): T
|
||||
public? get(): T
|
||||
|
||||
}
|
||||
<T : Any> public? final? class Derived : Base<T> {
|
||||
public? constructor(x: T): super<Base<T>>()
|
||||
|
||||
}
|
||||
<T : Any> public? final? function create(x: T): Derived<T> {
|
||||
STUB
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import my.println
|
||||
|
||||
enum class Order {
|
||||
FIRST,
|
||||
SECOND,
|
||||
THIRD
|
||||
}
|
||||
|
||||
enum class Planet(val m: Double, internal val r: Double) {
|
||||
MERCURY(1.0, 2.0) {
|
||||
override fun sayHello() {
|
||||
println("Hello!!!")
|
||||
}
|
||||
},
|
||||
VENERA(3.0, 4.0) {
|
||||
override fun sayHello() {
|
||||
println("Ola!!!")
|
||||
}
|
||||
},
|
||||
EARTH(5.0, 6.0) {
|
||||
override fun sayHello() {
|
||||
println("Privet!!!")
|
||||
}
|
||||
};
|
||||
|
||||
val g: Double = G * m / (r * r)
|
||||
|
||||
abstract fun sayHello()
|
||||
|
||||
companion object {
|
||||
const val G = 6.67e-11
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
FILE: enums.kt
|
||||
public? final? enum class Order {
|
||||
public? constructor(): super<kotlin.Enum>()
|
||||
|
||||
public? final enum entry FIRST {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
|
||||
public? final enum entry SECOND {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
|
||||
public? final enum entry THIRD {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public? final? enum class Planet {
|
||||
public? constructor(m: Double, r: Double): super<kotlin.Enum>()
|
||||
|
||||
public? final? property m(val): Double
|
||||
public? get(): Double
|
||||
|
||||
internal final? property r(val): Double
|
||||
internal get(): Double
|
||||
|
||||
public? final enum entry MERCURY : Planet {
|
||||
public? constructor(): super<Planet>()
|
||||
|
||||
public? open? override function sayHello(): kotlin.Unit {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? final enum entry VENERA : Planet {
|
||||
public? constructor(): super<Planet>()
|
||||
|
||||
public? open? override function sayHello(): kotlin.Unit {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? final enum entry EARTH : Planet {
|
||||
public? constructor(): super<Planet>()
|
||||
|
||||
public? open? override function sayHello(): kotlin.Unit {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? final? property g(val): Double = STUB
|
||||
public? get(): Double
|
||||
|
||||
public? abstract function sayHello(): kotlin.Unit
|
||||
|
||||
public? final? companion object Companion {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
public? final? const property G(val): <implicit> = STUB
|
||||
public? get(): <implicit>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
interface Some
|
||||
|
||||
object O1 : Some
|
||||
|
||||
object O2 : Some
|
||||
|
||||
enum class SomeEnum(val x: Some) {
|
||||
FIRST(O1) {
|
||||
override fun check(y: Some): Boolean = true
|
||||
},
|
||||
SECOND(O2) {
|
||||
override fun check(y: Some): Boolean = y == O2
|
||||
};
|
||||
|
||||
abstract fun check(y: Some): Boolean
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
FILE: enums2.kt
|
||||
public? final? interface Some {
|
||||
}
|
||||
public? final? object O1 : Some {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
public? final? object O2 : Some {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
public? final? enum class SomeEnum {
|
||||
public? constructor(x: Some): super<kotlin.Enum>()
|
||||
|
||||
public? final? property x(val): Some
|
||||
public? get(): Some
|
||||
|
||||
public? final enum entry FIRST : SomeEnum {
|
||||
public? constructor(): super<SomeEnum>()
|
||||
|
||||
public? open? override function check(y: Some): Boolean {
|
||||
STUB
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? final enum entry SECOND : SomeEnum {
|
||||
public? constructor(): super<SomeEnum>()
|
||||
|
||||
public? open? override function check(y: Some): Boolean {
|
||||
STUB
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? abstract function check(y: Some): Boolean
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
expect class MyClass
|
||||
|
||||
expect fun foo(): String
|
||||
|
||||
expect val x: Int
|
||||
|
||||
actual class MyClass
|
||||
|
||||
actual fun foo() = "Hello"
|
||||
|
||||
actual val x = 42
|
||||
@@ -0,0 +1,17 @@
|
||||
FILE: expectActual.kt
|
||||
public? final? expect class MyClass {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
public? final? expect function foo(): String
|
||||
public? final? expect property x(val): Int
|
||||
public? get(): Int
|
||||
public? final? actual class MyClass {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
public? final? actual function foo(): <implicit> {
|
||||
STUB
|
||||
}
|
||||
public? final? actual property x(val): <implicit> = STUB
|
||||
public? get(): <implicit>
|
||||
@@ -0,0 +1,8 @@
|
||||
fun <T> simpleRun(f: (T) -> Unit): Unit = f()
|
||||
|
||||
fun <T, R> List<T>.simpleMap(f: (T) -> R): R {
|
||||
|
||||
}
|
||||
|
||||
fun <T> simpleWith(t: T, f: T.() -> Unit): Unit = t.f()
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
FILE: functionTypes.kt
|
||||
<T> public? final? function simpleRun(f: ( (T) -> Unit )): Unit {
|
||||
STUB
|
||||
}
|
||||
<T, R> public? final? function simpleMap List<T>.(f: ( (T) -> R )): R {
|
||||
}
|
||||
<T> public? final? function simpleWith(t: T, f: ( T.() -> Unit )): Unit {
|
||||
STUB
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
interface Any
|
||||
|
||||
inline fun <reified T : Any> Any.safeAs(): T? = this as? T
|
||||
|
||||
abstract class Summator {
|
||||
abstract fun <T> plus(first: T, second: T): T
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
FILE: genericFunctions.kt
|
||||
public? final? interface Any {
|
||||
}
|
||||
<reified T : Any> public? final? inline function safeAs Any.(): T? {
|
||||
STUB
|
||||
}
|
||||
public? abstract class Summator {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
<T> public? abstract function plus(first: T, second: T): T
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
abstract class Base(val s: String)
|
||||
|
||||
class Outer {
|
||||
class Derived(s: String) : Base(s)
|
||||
|
||||
object Obj : Base("")
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
FILE: nestedClass.kt
|
||||
public? abstract class Base {
|
||||
public? constructor(s: String): super<kotlin.Any>()
|
||||
|
||||
public? final? property s(val): String
|
||||
public? get(): String
|
||||
|
||||
}
|
||||
public? final? class Outer {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
public? final? class Derived : Base {
|
||||
public? constructor(s: String): super<Base>()
|
||||
|
||||
}
|
||||
|
||||
public? final? object Obj : Base {
|
||||
public? constructor(): super<Base>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class NoPrimary {
|
||||
val x: String
|
||||
|
||||
constructor(x: String) {
|
||||
this.x = x
|
||||
}
|
||||
|
||||
constructor(): this("")
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
FILE: noPrimaryConstructor.kt
|
||||
public? final? class NoPrimary {
|
||||
public? final? property x(val): String
|
||||
public? get(): String
|
||||
|
||||
public? constructor(x: String): super<kotlin.Any>() {
|
||||
}
|
||||
|
||||
public? constructor(): this<NoPrimary>()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
interface SomeInterface {
|
||||
fun foo(x: Int, y: String): String
|
||||
|
||||
val bar: Boolean
|
||||
}
|
||||
|
||||
class SomeClass : SomeInterface {
|
||||
private val baz = 42
|
||||
|
||||
override fun foo(x: Int, y: String): String {
|
||||
return y + x + baz
|
||||
}
|
||||
|
||||
override var bar: Boolean
|
||||
get() = true
|
||||
set(value) {}
|
||||
|
||||
lateinit var fau: Double
|
||||
}
|
||||
|
||||
inline class InlineClass
|
||||
@@ -0,0 +1,33 @@
|
||||
FILE: simpleClass.kt
|
||||
public? final? interface SomeInterface {
|
||||
public? final? function foo(x: Int, y: String): String
|
||||
|
||||
public? final? property bar(val): Boolean
|
||||
public? get(): Boolean
|
||||
|
||||
}
|
||||
public? final? class SomeClass : SomeInterface {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
private final? property baz(val): <implicit> = STUB
|
||||
private get(): <implicit>
|
||||
|
||||
public? open? override function foo(x: Int, y: String): String {
|
||||
}
|
||||
|
||||
public? open? override property bar(var): Boolean
|
||||
public? get(): Boolean {
|
||||
STUB
|
||||
}
|
||||
public? set(value: Boolean): kotlin.Unit {
|
||||
}
|
||||
|
||||
public? final? lateinit property fau(var): Double
|
||||
public? get(): Double
|
||||
public? set(value: Double): kotlin.Unit
|
||||
|
||||
}
|
||||
public? final? inline class InlineClass {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,3 @@
|
||||
FILE: simpleFun.kt
|
||||
public? final? function foo(): kotlin.Unit {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
interface B
|
||||
|
||||
typealias C = B
|
||||
|
||||
class D : C
|
||||
@@ -0,0 +1,8 @@
|
||||
FILE: simpleTypeAlias.kt
|
||||
public? final? interface B {
|
||||
}
|
||||
public? final typealias C = B
|
||||
public? final? class D : C {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
open class A
|
||||
|
||||
interface B<S, T : A>
|
||||
|
||||
typealias C<T> = B<T, A>
|
||||
|
||||
class D : C<A>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
FILE: typeAliasWithGeneric.kt
|
||||
public? open class A {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
<S, T : A> public? final? interface B {
|
||||
}
|
||||
<T> public? final typealias C = B<T, A>
|
||||
public? final? class D : C<A> {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
interface Some
|
||||
|
||||
abstract class My<T : Some> {
|
||||
inner class T
|
||||
|
||||
abstract val x: T
|
||||
|
||||
abstract fun foo(arg: T)
|
||||
|
||||
abstract val y: My.T
|
||||
|
||||
abstract val z: test.My.T
|
||||
|
||||
class Some : T()
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
FILE: typeParameterVsNested.kt
|
||||
public? final? interface Some {
|
||||
}
|
||||
<T : Some> public? abstract class My {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
public? final? inner class T {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
|
||||
public? abstract property x(val): T
|
||||
public? get(): T
|
||||
|
||||
public? abstract function foo(arg: T): kotlin.Unit
|
||||
|
||||
public? abstract property y(val): My.T
|
||||
public? get(): My.T
|
||||
|
||||
public? abstract property z(val): test.My.T
|
||||
public? get(): test.My.T
|
||||
|
||||
public? final? class Some : T {
|
||||
public? constructor(): super<T>()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
interface List<out T : Any> {
|
||||
operator fun get(index: Int): T
|
||||
|
||||
infix fun concat(other: List<T>): List<T>
|
||||
}
|
||||
|
||||
typealias StringList = List<out String>
|
||||
typealias AnyList = List<*>
|
||||
|
||||
abstract class AbstractList<out T : Any> : List<T>
|
||||
|
||||
class SomeList : AbstractList<Int>() {
|
||||
override fun get(index: Int): Int = 42
|
||||
|
||||
override fun concat(other: List<Int>): List<Int> = this
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
FILE: typeParameters.kt
|
||||
<out T : Any> public? final? interface List {
|
||||
public? final? operator function get(index: Int): T
|
||||
|
||||
public? final? infix function concat(other: List<T>): List<T>
|
||||
|
||||
}
|
||||
public? final typealias StringList = List<out String>
|
||||
public? final typealias AnyList = List<*>
|
||||
<out T : Any> public? abstract class AbstractList : List<T> {
|
||||
public? constructor(): super<kotlin.Any>()
|
||||
|
||||
}
|
||||
public? final? class SomeList : AbstractList<Int> {
|
||||
public? constructor(): super<AbstractList<Int>>()
|
||||
|
||||
public? open? override function get(index: Int): Int {
|
||||
STUB
|
||||
}
|
||||
|
||||
public? open? override function concat(other: List<Int>): List<Int> {
|
||||
STUB
|
||||
}
|
||||
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* 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.kotlin.fir.builder
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry
|
||||
import com.intellij.openapi.util.Getter
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.cli.common.script.CliScriptDefinitionProvider
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.FirSessionBase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.script.ScriptDefinitionProvider
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.testFramework.KtParsingTestCase
|
||||
import java.io.File
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
||||
abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase(
|
||||
"",
|
||||
"kt",
|
||||
KotlinParserDefinition()
|
||||
) {
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
project.registerService(ScriptDefinitionProvider::class.java, CliScriptDefinitionProvider::class.java)
|
||||
}
|
||||
|
||||
override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory()
|
||||
|
||||
private fun createFile(filePath: String, fileType: IElementType): PsiFile {
|
||||
val psiFactory = KtPsiFactory(myProject)
|
||||
return when (fileType) {
|
||||
KtNodeTypes.EXPRESSION_CODE_FRAGMENT ->
|
||||
psiFactory.createExpressionCodeFragment(loadFile(filePath), null)
|
||||
KtNodeTypes.BLOCK_CODE_FRAGMENT ->
|
||||
psiFactory.createBlockCodeFragment(loadFile(filePath), null)
|
||||
else ->
|
||||
createPsiFile(FileUtil.getNameWithoutExtension(PathUtil.getFileName(filePath)), loadFile(filePath))
|
||||
}
|
||||
}
|
||||
|
||||
protected fun doRawFirTest(filePath: String) {
|
||||
val file = createKtFile(filePath)
|
||||
val firFile = file.toFirFile()
|
||||
val firFileDump = StringBuilder().also { FirRenderer(it).visitFile(firFile) }.toString()
|
||||
val expectedPath = filePath.replace(".kt", ".txt")
|
||||
KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump)
|
||||
}
|
||||
|
||||
protected fun createKtFile(filePath: String): KtFile {
|
||||
myFileExt = FileUtilRt.getExtension(PathUtil.getFileName(filePath))
|
||||
return (createFile(filePath, KtNodeTypes.KT_FILE) as KtFile).apply {
|
||||
myFile = this
|
||||
}
|
||||
}
|
||||
|
||||
protected fun KtFile.toFirFile(): FirFile =
|
||||
RawFirBuilder(object : FirSessionBase() {}).buildFirFile(this)
|
||||
|
||||
private fun FirElement.traverseChildren(result: MutableSet<FirElement> = hashSetOf()): MutableSet<FirElement> {
|
||||
if (!result.add(this)) {
|
||||
return result
|
||||
}
|
||||
for (property in this::class.memberProperties) {
|
||||
val childElement = property.getter.call(this) as? FirElement ?: continue
|
||||
childElement.traverseChildren(result)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun FirFile.visitChildren(): Set<FirElement> =
|
||||
ConsistencyVisitor().let {
|
||||
this@visitChildren.accept(it)
|
||||
it.result
|
||||
}
|
||||
|
||||
private fun FirFile.transformChildren(): Set<FirElement> =
|
||||
ConsistencyTransformer().let {
|
||||
this@transformChildren.accept(it, Unit)
|
||||
it.result
|
||||
}
|
||||
|
||||
protected fun FirFile.checkChildren() {
|
||||
val children = traverseChildren()
|
||||
val visitedChildren = visitChildren()
|
||||
children.removeAll(visitedChildren)
|
||||
if (children.isNotEmpty()) {
|
||||
val element = children.first()
|
||||
val elementDump = StringBuilder().also { element.accept(FirRenderer(it)) }.toString()
|
||||
throw AssertionError("FirElement ${element.javaClass} is not visited: $elementDump")
|
||||
}
|
||||
}
|
||||
|
||||
protected fun FirFile.checkTransformedChildren() {
|
||||
val children = traverseChildren()
|
||||
val transformedChildren = transformChildren()
|
||||
children.removeAll(transformedChildren)
|
||||
if (children.isNotEmpty()) {
|
||||
val element = children.first()
|
||||
val elementDump = StringBuilder().also { element.accept(FirRenderer(it)) }.toString()
|
||||
throw AssertionError("FirElement ${element.javaClass} is not transformed: $elementDump")
|
||||
}
|
||||
}
|
||||
|
||||
private class ConsistencyVisitor : FirVisitorVoid() {
|
||||
var result = hashSetOf<FirElement>()
|
||||
|
||||
override fun visitElement(element: FirElement) {
|
||||
// NB: types are reused sometimes (e.g. in accessors)
|
||||
if (!result.add(element)) {
|
||||
if (element !is FirType) {
|
||||
val elementDump = StringBuilder().also { element.accept(FirRenderer(it)) }.toString()
|
||||
throw AssertionError("FirElement ${element.javaClass} is visited twice: $elementDump")
|
||||
}
|
||||
} else {
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ConsistencyTransformer : FirTransformer<Unit>() {
|
||||
var result = hashSetOf<FirElement>()
|
||||
|
||||
override fun <E : FirElement> transformElement(element: E, data: Unit): CompositeTransformResult<E> {
|
||||
if (!result.add(element)) {
|
||||
if (element !is FirType) {
|
||||
val elementDump = StringBuilder().also { element.accept(FirRenderer(it)) }.toString()
|
||||
throw AssertionError("FirElement ${element.javaClass} is visited twice: $elementDump")
|
||||
}
|
||||
} else {
|
||||
element.acceptChildren(this, Unit)
|
||||
}
|
||||
return CompositeTransformResult(element)
|
||||
}
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
super.tearDown()
|
||||
FileTypeRegistry.ourInstanceGetter = Getter<FileTypeRegistry> { FileTypeManager.getInstance() }
|
||||
}
|
||||
|
||||
}
|
||||
Generated
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.kotlin.fir.builder;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCase {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doRawFirTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInRawBuilder() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder/declarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Declarations extends AbstractRawFirBuilderTestCase {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doRawFirTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInDeclarations() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexTypes.kt")
|
||||
public void testComplexTypes() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/complexTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("derivedClass.kt")
|
||||
public void testDerivedClass() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enums.kt")
|
||||
public void testEnums() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enums2.kt")
|
||||
public void testEnums2() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expectActual.kt")
|
||||
public void testExpectActual() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("F.kt")
|
||||
public void testF() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/F.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionTypes.kt")
|
||||
public void testFunctionTypes() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericFunctions.kt")
|
||||
public void testGenericFunctions() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedOfAliasedType.kt")
|
||||
public void testNestedOfAliasedType() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/NestedOfAliasedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedSuperType.kt")
|
||||
public void testNestedSuperType() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/NestedSuperType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noPrimaryConstructor.kt")
|
||||
public void testNoPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFun.kt")
|
||||
public void testSimpleFun() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleTypeAlias.kt")
|
||||
public void testSimpleTypeAlias() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleTypeAlias.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasWithGeneric.kt")
|
||||
public void testTypeAliasWithGeneric() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeAliasWithGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameterVsNested.kt")
|
||||
public void testTypeParameterVsNested() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameterVsNested.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameters.kt")
|
||||
public void testTypeParameters() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.kotlin.fir.builder
|
||||
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
import kotlin.system.measureNanoTime
|
||||
|
||||
@TestDataPath("\$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() {
|
||||
|
||||
fun testTotalKotlin() {
|
||||
val root = File(testDataPath)
|
||||
var counter = 0
|
||||
var time = 0L
|
||||
var totalLength = 0
|
||||
println("BASE PATH: $testDataPath")
|
||||
for (file in root.walkTopDown()) {
|
||||
if (file.isDirectory) continue
|
||||
if (file.path.contains("testData") || file.path.contains("resources")) continue
|
||||
if (file.extension != "kt") continue
|
||||
try {
|
||||
val ktFile = createKtFile(file.toRelativeString(root))
|
||||
var firFile: FirFile? = null
|
||||
time += measureNanoTime {
|
||||
firFile = ktFile.toFirFile()
|
||||
}
|
||||
totalLength += StringBuilder().also { FirRenderer(it).visitFile(firFile!!) }.length
|
||||
counter++
|
||||
} catch (e: Exception) {
|
||||
println("TIME PER FILE: ${(time / counter) * 1e-6} ms, COUNTER: $counter")
|
||||
println("EXCEPTION in: " + file.toRelativeString(root))
|
||||
throw e
|
||||
}
|
||||
}
|
||||
println("SUCCESS!")
|
||||
println("TOTAL LENGTH: $totalLength")
|
||||
println("TIME PER FILE: ${(time / counter) * 1e-6} ms, COUNTER: $counter")
|
||||
}
|
||||
|
||||
fun testVisitConsistency() {
|
||||
val root = File(testDataPath)
|
||||
for (file in root.walkTopDown()) {
|
||||
if (file.isDirectory) continue
|
||||
if (file.path.contains("testData") || file.path.contains("resources")) continue
|
||||
if (file.extension != "kt") continue
|
||||
val ktFile = createKtFile(file.toRelativeString(root))
|
||||
val firFile = ktFile.toFirFile()
|
||||
try {
|
||||
firFile.checkChildren()
|
||||
} catch (e: Throwable) {
|
||||
println("EXCEPTION in: " + file.toRelativeString(root))
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testTransformConsistency() {
|
||||
val root = File(testDataPath)
|
||||
for (file in root.walkTopDown()) {
|
||||
if (file.isDirectory) continue
|
||||
if (file.path.contains("testData") || file.path.contains("resources")) continue
|
||||
if (file.extension != "kt") continue
|
||||
val ktFile = createKtFile(file.toRelativeString(root))
|
||||
val firFile = ktFile.toFirFile()
|
||||
try {
|
||||
firFile.checkTransformedChildren()
|
||||
} catch (e: Throwable) {
|
||||
println("EXCEPTION in: " + file.toRelativeString(root))
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user