Write test to compare FIR from light tree with FIR from PSI
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9dbacb5380
commit
45faf76b4a
@@ -69,7 +69,7 @@ class Converter(
|
||||
for (kid in kidsArray) {
|
||||
if (kid == null) continue
|
||||
val tokenType = kid.tokenType
|
||||
if (COMMENTS.contains(tokenType) || tokenType == WHITE_SPACE || tokenType == SEMICOLON || tokenType == COLON) continue
|
||||
if (COMMENTS.contains(tokenType) || tokenType == WHITE_SPACE || tokenType == SEMICOLON) continue
|
||||
f(kid)
|
||||
}
|
||||
}
|
||||
@@ -641,11 +641,12 @@ class Converter(
|
||||
is KtNodeType,
|
||||
is KtConstantExpressionElementType,
|
||||
is KtDotQualifiedExpressionElementType,
|
||||
is KtStringTemplateExpressionElementType -> firExpression = visitExpression(it) //TODO implement
|
||||
is KtStringTemplateExpressionElementType,
|
||||
REFERENCE_EXPRESSION -> firExpression = visitExpression(it) //TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
returnType = if (firBlock != null || modifiers.inheritanceModifier == InheritanceModifier.ABSTRACT) {
|
||||
returnType = if (firBlock != null || (firBlock == null && firExpression == null)) {
|
||||
returnType ?: implicitUnitType
|
||||
} else {
|
||||
returnType ?: implicitType
|
||||
@@ -714,7 +715,8 @@ class Converter(
|
||||
is KtNodeType,
|
||||
is KtConstantExpressionElementType,
|
||||
is KtDotQualifiedExpressionElementType,
|
||||
is KtStringTemplateExpressionElementType -> firExpression = visitExpression(it) //TODO implement
|
||||
is KtStringTemplateExpressionElementType,
|
||||
REFERENCE_EXPRESSION -> firExpression = visitExpression(it) //TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,7 +820,7 @@ class Converter(
|
||||
COLON -> isReturnType = true
|
||||
TYPE_REFERENCE -> if (isReturnType) returnType = convertType(it) else receiverType = convertType(it)
|
||||
TYPE_CONSTRAINT_LIST -> typeConstraints += convertTypeConstraints(it)
|
||||
BY_KEYWORD -> isDelegate = true
|
||||
PROPERTY_DELEGATE -> isDelegate = true
|
||||
VAR_KEYWORD -> isVar = true
|
||||
PROPERTY_ACCESSOR ->
|
||||
if (it.toString().contains("get")) //TODO make it better
|
||||
@@ -828,7 +830,8 @@ class Converter(
|
||||
is KtNodeType,
|
||||
is KtConstantExpressionElementType,
|
||||
is KtDotQualifiedExpressionElementType,
|
||||
is KtStringTemplateExpressionElementType -> firExpression = visitExpression(it) //TODO implement
|
||||
is KtStringTemplateExpressionElementType,
|
||||
REFERENCE_EXPRESSION -> firExpression = visitExpression(it) //TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,7 +904,8 @@ class Converter(
|
||||
is KtNodeType,
|
||||
is KtConstantExpressionElementType,
|
||||
is KtDotQualifiedExpressionElementType,
|
||||
is KtStringTemplateExpressionElementType -> firExpression = visitExpression(it) //TODO implement
|
||||
is KtStringTemplateExpressionElementType,
|
||||
REFERENCE_EXPRESSION -> firExpression = visitExpression(it) //TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
@@ -936,7 +940,8 @@ class Converter(
|
||||
is KtNodeType,
|
||||
is KtConstantExpressionElementType,
|
||||
is KtDotQualifiedExpressionElementType,
|
||||
is KtStringTemplateExpressionElementType -> firExpression = visitExpression(it) //TODO implement
|
||||
is KtStringTemplateExpressionElementType,
|
||||
REFERENCE_EXPRESSION -> firExpression = visitExpression(it) //TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1360,12 +1365,15 @@ class Converter(
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget?
|
||||
): FirAnnotationCall {
|
||||
//TODO not implemented
|
||||
val pair = convertConstructorInvocation(unescapedAnnotation)
|
||||
return FirAnnotationCallImpl(
|
||||
session,
|
||||
null,
|
||||
annotationUseSiteTarget,
|
||||
FirErrorTypeRefImpl(session, null, "not implemented") //TODO not implemented
|
||||
)
|
||||
pair.first
|
||||
).apply {
|
||||
arguments += pair.second
|
||||
}
|
||||
}
|
||||
|
||||
private fun visitExpression(expression: LighterASTNode): FirExpression {
|
||||
|
||||
-6
@@ -5,19 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.lightTree
|
||||
|
||||
import com.intellij.lang.impl.PsiBuilderFactoryImpl
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.impl.DebugUtil
|
||||
import com.intellij.psi.impl.PsiManagerEx
|
||||
import com.intellij.testFramework.LightVirtualFile
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.parsing.KotlinParser
|
||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.lightTree
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import com.intellij.util.PathUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
|
||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
|
||||
@TestDataPath("\$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
class TreesCompareTest: AbstractRawFirBuilderTestCase() {
|
||||
fun testCompare() {
|
||||
val path = System.getProperty("user.dir")
|
||||
val root = File(path)
|
||||
var counter = 0
|
||||
var errorCounter = 0
|
||||
|
||||
val parserDefinition = KotlinParserDefinition()
|
||||
val lexer = parserDefinition.createLexer(myProject)
|
||||
val lightTreeConverter = LightTree2Fir(true, parserDefinition, lexer)
|
||||
|
||||
println("BASE PATH: $path")
|
||||
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 text = FileUtil.loadFile(file, CharsetToolkit.UTF8, true).trim()
|
||||
|
||||
//light tree
|
||||
val firFileFromLightTree = lightTreeConverter.buildFirFile(text, file.name)
|
||||
val treeFromLightTree = StringBuilder().also { FirRenderer(it).visitFile(firFileFromLightTree) }.toString()
|
||||
|
||||
//psi
|
||||
val ktFile = createPsiFile(FileUtil.getNameWithoutExtension(PathUtil.getFileName(file.path)), text) as KtFile
|
||||
val firFileFromPsi = ktFile.toFirFile(stubMode = true)
|
||||
val treeFromPsi = StringBuilder().also { FirRenderer(it).visitFile(firFileFromPsi) }.toString()
|
||||
|
||||
if (treeFromLightTree != treeFromPsi){
|
||||
errorCounter++;
|
||||
//TestCase.assertEquals(treeFromPsi, treeFromLightTree)
|
||||
}
|
||||
counter++
|
||||
}
|
||||
println("All scanned files: $counter")
|
||||
println("Files that aren't equal to FIR: $errorCounter")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user