[FIR] Add separate diagnostic tests working in light tree mode
Now we have separate raw fir builder based and light tree builder based tests. Note: one light tree test was ignored due to lack of JavaElementFinder in this mode.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// IGNORE_LIGHT_TREE
|
||||||
|
// Does not work in light tree mode due to lack of Java element finder there
|
||||||
// FILE: KotlinTypeChecker.java
|
// FILE: KotlinTypeChecker.java
|
||||||
|
|
||||||
public interface KotlinTypeChecker {
|
public interface KotlinTypeChecker {
|
||||||
|
|||||||
+22
-11
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
|||||||
import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession
|
import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession
|
||||||
import org.jetbrains.kotlin.fir.java.FirLibrarySession
|
import org.jetbrains.kotlin.fir.java.FirLibrarySession
|
||||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeDiagnostic
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.resolve.firProvider
|
import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||||
@@ -35,6 +36,7 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils
|
import org.jetbrains.kotlin.resolve.AnalyzingUtils
|
||||||
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
||||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
|
||||||
@@ -60,7 +62,7 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun analyzeAndCheckUnhandled(testDataFile: File, files: List<TestFile>) {
|
open fun analyzeAndCheckUnhandled(testDataFile: File, files: List<TestFile>, useLightTree: Boolean = false) {
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
|
|
||||||
val modules = createModules(groupedByModule)
|
val modules = createModules(groupedByModule)
|
||||||
@@ -90,21 +92,30 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() {
|
|||||||
|
|
||||||
val session = configToSession.getValue(testModule)
|
val session = configToSession.getValue(testModule)
|
||||||
|
|
||||||
|
mapKtFilesToFirFiles(session, ktFiles, firFiles, useLightTree)
|
||||||
val firBuilder = RawFirBuilder(session, false)
|
|
||||||
|
|
||||||
ktFiles.mapTo(firFiles) {
|
|
||||||
val firFile = firBuilder.buildFirFile(it)
|
|
||||||
|
|
||||||
(session.firProvider as FirProviderImpl).recordFile(firFile)
|
|
||||||
|
|
||||||
firFile
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runAnalysis(testDataFile, files, firFiles)
|
runAnalysis(testDataFile, files, firFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapKtFilesToFirFiles(session: FirSession, ktFiles: List<KtFile>, firFiles: MutableList<FirFile>, useLightTree: Boolean) {
|
||||||
|
if (useLightTree) {
|
||||||
|
val lightTreeBuilder = LightTree2Fir(session, stubMode = false)
|
||||||
|
ktFiles.mapTo(firFiles) {
|
||||||
|
val firFile = lightTreeBuilder.buildFirFile(it.text, it.name)
|
||||||
|
(session.firProvider as FirProviderImpl).recordFile(firFile)
|
||||||
|
firFile
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val firBuilder = RawFirBuilder(session, false)
|
||||||
|
ktFiles.mapTo(firFiles) {
|
||||||
|
val firFile = firBuilder.buildFirFile(it)
|
||||||
|
(session.firProvider as FirProviderImpl).recordFile(firFile)
|
||||||
|
firFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFiles: List<FirFile>)
|
protected abstract fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFiles: List<FirFile>)
|
||||||
|
|
||||||
private fun createModules(
|
private fun createModules(
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
abstract class AbstractFirDiagnosticsWithLightTreeTest : AbstractFirDiagnosticsTest(), FirDiagnosticsTestLightTreeHelper {
|
||||||
|
override fun doTest(filePath: String) {
|
||||||
|
val file = createTestFileFromPath(filePath)
|
||||||
|
val expectedText = KotlinTestUtils.doLoadFile(file)
|
||||||
|
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "// IGNORE_LIGHT_TREE")) return
|
||||||
|
|
||||||
|
super.doTest(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun analyzeAndCheck(testDataFile: File, files: List<TestFile>) {
|
||||||
|
super<FirDiagnosticsTestLightTreeHelper>.analyzeAndCheck(testDataFile, files)
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
interface FirDiagnosticsTestLightTreeHelper {
|
||||||
|
fun analyzeAndCheck(testDataFile: File, files: List<BaseDiagnosticsTest.TestFile>) {
|
||||||
|
try {
|
||||||
|
analyzeAndCheckUnhandled(testDataFile, files, useLightTree = true)
|
||||||
|
} catch (t: AssertionError) {
|
||||||
|
throw t
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
throw t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun analyzeAndCheckUnhandled(testDataFile: File, files: List<BaseDiagnosticsTest.TestFile>, useLightTree: Boolean)
|
||||||
|
}
|
||||||
Generated
+1133
File diff suppressed because it is too large
Load Diff
@@ -531,6 +531,10 @@ fun main(args: Array<String>) {
|
|||||||
model("resolve", pattern = KT_WITHOUT_DOTS_IN_NAME, excludeDirs = listOf("stdlib", "cfg", "smartcasts"))
|
model("resolve", pattern = KT_WITHOUT_DOTS_IN_NAME, excludeDirs = listOf("stdlib", "cfg", "smartcasts"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass<AbstractFirDiagnosticsWithLightTreeTest> {
|
||||||
|
model("resolve", pattern = KT_WITHOUT_DOTS_IN_NAME, excludeDirs = listOf("stdlib", "cfg", "smartcasts"))
|
||||||
|
}
|
||||||
|
|
||||||
testClass<AbstractFirDiagnosticsWithCfgTest> {
|
testClass<AbstractFirDiagnosticsWithCfgTest> {
|
||||||
model("resolve/cfg", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
model("resolve/cfg", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||||
model("resolve/smartcasts", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
model("resolve/smartcasts", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||||
|
|||||||
Reference in New Issue
Block a user