Analysis API: add test for annotations on types
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.FrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.expressionMarkerProvider
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.indented
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.test.framework.AbstractHLApiSingleFileTest
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.DebugSymbolRenderer
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
|
||||
abstract class AbstractAnalysisApiAnnotationsOnTypesTest(
|
||||
configurator: FrontendApiTestConfiguratorService
|
||||
) : AbstractHLApiSingleFileTest(configurator) {
|
||||
|
||||
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
||||
val ktTypeReference = testServices.expressionMarkerProvider
|
||||
.getElementOfTypAtCaret<KtTypeReference>(ktFile)
|
||||
val actual = analyseForTest(ktFile) {
|
||||
val ktType = ktTypeReference.getKtType()
|
||||
val annotations = ktType.annotations
|
||||
buildString {
|
||||
appendLine("KtTypeReference: ${ktTypeReference.text}")
|
||||
appendLine("annotations: [")
|
||||
for (annotation in annotations) {
|
||||
appendLine(DebugSymbolRenderer.renderAnnotationApplication(annotation).indented(indent = 2))
|
||||
}
|
||||
appendLine("]")
|
||||
}
|
||||
}
|
||||
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -40,4 +40,9 @@ fun KtSymbol.getNameWithPositionString(): String {
|
||||
null -> "null"
|
||||
else -> psi::class.simpleName
|
||||
} + "@" + psi.position()
|
||||
}
|
||||
|
||||
fun String.indented(indent: Int): String {
|
||||
val indentString = " ".repeat(indent)
|
||||
return indentString + replace("\n", "\n$indentString")
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.test.services.TestServices
|
||||
|
||||
abstract class AbstractHLApiSingleFileTest(configurator: FrontendApiTestConfiguratorService) : AbstractHLApiSingleModuleTest(configurator) {
|
||||
final override fun doTestByFileStructure(ktFiles: List<KtFile>, module: TestModule, testServices: TestServices) {
|
||||
val singleFile = ktFiles.single()
|
||||
val singleFile = ktFiles.singleOrNull() ?: ktFiles.first { it.name == "main.kt" }
|
||||
doTestByFileStructure(singleFile, module, testServices)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user