Analysis API: add test for KtDeclaration.getReturnKtType
FE1.0 always return kotlin.Unit as return type for constructors while FIR returns the constructed class type. I am not sure which is more desirable. Also, I am not sure how to make FE1.0 behave the same way.
This commit is contained in:
committed by
Ilya Kirillov
parent
0e93931e24
commit
f1d0791f15
+6
-1
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.analyse
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils.offsetToLineAndColumn
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
@@ -45,4 +46,8 @@ fun KtSymbol.getNameWithPositionString(): String {
|
||||
fun String.indented(indent: Int): String {
|
||||
val indentString = " ".repeat(indent)
|
||||
return indentString + replace("\n", "\n$indentString")
|
||||
}
|
||||
}
|
||||
|
||||
fun KtDeclaration.getNameWithPositionString(): String {
|
||||
return (presentation?.presentableText ?: name ?: this::class.simpleName) + "@" + position()
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.analysis.api.impl.base.test.components.expressionTypeProvider
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.FrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.getNameWithPositionString
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.test.framework.AbstractHLApiSingleFileTest
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
|
||||
abstract class AbstractDeclarationReturnTypeTest(
|
||||
configurator: FrontendApiTestConfiguratorService
|
||||
) : AbstractHLApiSingleFileTest(configurator) {
|
||||
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
||||
val actual = buildString {
|
||||
ktFile.accept(object : KtTreeVisitor<Int>() {
|
||||
override fun visitDeclaration(dcl: KtDeclaration, data: Int): Void? {
|
||||
if (dcl is KtTypeParameter) return null
|
||||
append(" ".repeat(data))
|
||||
if (dcl is KtClassLikeDeclaration) {
|
||||
appendLine(dcl.getNameWithPositionString())
|
||||
} else {
|
||||
analyseForTest(dcl) {
|
||||
val returnType = dcl.getReturnKtType()
|
||||
append(dcl.getNameWithPositionString())
|
||||
append(" : ")
|
||||
appendLine(returnType.render())
|
||||
}
|
||||
}
|
||||
return super.visitDeclaration(dcl, data + 2)
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user