Skip to content

Commit 9ced146

Browse files
committed
Kotlin: Assign container class as the owner of init block comments
1 parent d9b3726 commit 9ced146

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ open class KotlinFileExtractor(
172172
is IrEnumEntry -> return getEnumEntryLabel(element)
173173
is IrTypeAlias -> return getTypeAliasLabel(element)
174174

175+
is IrAnonymousInitializer -> {
176+
val parentClass = element.parentClassOrNull
177+
if (parentClass == null) {
178+
logger.errorElement("Parent of anonymous initializer is not a class", element)
179+
return null
180+
}
181+
// Assign the comment to the class. The content of the `init` blocks might be extracted in multiple constructors.
182+
return getClassLabel(parentClass, listOf()).classLabel
183+
}
184+
185+
175186
// Fresh entities:
176187
is IrBody -> return null
177188
is IrExpression -> return null

java/ql/test/kotlin/library-tests/comments/comments.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ commentOwners
2121
| comments.kt:37:5:37:23 | /** This is high */ | comments.kt:38:5:38:11 | High |
2222
| comments.kt:42:5:44:6 | /**\n * A variable.\n */ | comments.kt:45:5:45:13 | int a |
2323
| comments.kt:48:1:50:3 | /**\n * A type alias comment\n */ | comments.kt:51:1:51:24 | MyType |
24+
| comments.kt:54:5:56:7 | /**\n * An init block comment\n */ | comments.kt:53:1:58:1 | InitBlock |
2425
commentSections
2526
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ | Kdoc with no owner |
2627
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |

0 commit comments

Comments
 (0)