add Initial support for comments in SIR #KT-65174 Fixed
Merge-request: KT-MR-14007 Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
This commit is contained in:
+11
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.sir.analysisapi.transformers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.sir.*
|
||||
@@ -39,6 +40,9 @@ private class AAFunction(
|
||||
AAKotlinType(name = function.returnType.toString())
|
||||
}
|
||||
|
||||
override val documentation: SirKotlinOrigin.Documentation?
|
||||
get() = originalFunction.docComment?.let { AADocumentation(it) }
|
||||
|
||||
}
|
||||
private data class AAParameter(
|
||||
override val name: String,
|
||||
@@ -48,3 +52,10 @@ private data class AAParameter(
|
||||
private data class AAKotlinType(
|
||||
override val name: String
|
||||
) : SirKotlinOrigin.Type
|
||||
|
||||
private data class AADocumentation(
|
||||
private val kdoc: KDoc
|
||||
) : SirKotlinOrigin.Documentation {
|
||||
override val content: String
|
||||
get() = kdoc.text
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Function foo description
|
||||
*
|
||||
* @param p first Integer to consume
|
||||
* @param p2 second Double to consume
|
||||
* @return Short, constant 1
|
||||
*/
|
||||
fun foo(p: Int, p2: Double): Short = 1
|
||||
@@ -0,0 +1 @@
|
||||
[foo] commented
|
||||
+6
@@ -24,6 +24,12 @@ public class SirAnalysisGeneratedTests extends AbstractKotlinSirContextTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/swift/sir-analysis-api/testData"), Pattern.compile("^(.+)\\.kt$"), null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("function_with_comment.kt")
|
||||
public void testFunction_with_comment() throws Exception {
|
||||
runTest("native/swift/sir-analysis-api/testData/function_with_comment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functions_overload.kt")
|
||||
public void testFunctions_overload() throws Exception {
|
||||
|
||||
+5
-3
@@ -43,9 +43,11 @@ abstract class AbstractKotlinSirContextTestBase : AbstractAnalysisApiBasedTest()
|
||||
val actual = buildString {
|
||||
module.declarations
|
||||
.filterIsInstance<SirForeignFunction>()
|
||||
.forEach {
|
||||
val function = it.origin as SirKotlinOrigin.Function
|
||||
appendLine("${function.path}")
|
||||
.forEach { sirForeignFunction ->
|
||||
val function = sirForeignFunction.origin as SirKotlinOrigin.Function
|
||||
val functionPath = "${function.path}"
|
||||
val isCommented = function.documentation?.let { " commented" } ?: ""
|
||||
appendLine("$functionPath$isCommented")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user