Commit 70e5761
Kotlin: attribute enum-entry and init-block KDoc owners under K2/FIR
Under the K2/FIR frontend the lighter-AST comment extractor finds a KDoc's
owner by walking the IR and, for each element that carries FIR metadata,
checking whether that metadata's source node has a KDOC child. Enum
entries (`IrEnumEntry`) and anonymous initializers
(`IrAnonymousInitializer`) carry no FIR metadata, so the search could
never reach them: their KDoc comments were recorded with no owner, whereas
the PSI frontend attributes them (an enum entry to itself, an init block
to its enclosing class).
These IR declarations do retain valid source offsets, however. This adds a
supplementary pass that walks the file's lighter AST, finds the
`ENUM_ENTRY` and `CLASS_INITIALIZER` nodes that carry a KDOC child, and
matches each to the metadata-less IR declaration whose source offset lies
within the node's range. Matching is fail-closed: a node is only
attributed when exactly one candidate declaration falls inside it, so
ambiguous or unexpected shapes leave the comment ownerless rather than
guessing.
Offset containment is used rather than per-kind heuristics (matching enum
entries by name, initializers by order) because it is uniform across both
node kinds and does not depend on names being unique or declaration order
being stable.
Only the K2 expectations change: the `test-kotlin2` `comments` enum-entry
and init-block KDoc owners now match `test-kotlin1` exactly. The one
remaining owner difference in that test is a KDoc on an anonymous function
passed as a call argument, which the PSI frontend attributes to the
enclosing property via its owner walk-up and the FIR frontend does not;
that discrepancy is left as-is (see the updated TODO).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent f495cf6 commit 70e5761
2 files changed
Lines changed: 79 additions & 8 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta
- ql/test-kotlin2/library-tests/comments
Lines changed: 76 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | | - | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
113 | 181 | | |
114 | 182 | | |
115 | 183 | | |
116 | | - | |
| 184 | + | |
117 | 185 | | |
118 | 186 | | |
119 | 187 | | |
| |||
124 | 192 | | |
125 | 193 | | |
126 | 194 | | |
127 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
128 | 199 | | |
129 | 200 | | |
130 | 201 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
35 | | - | |
36 | 37 | | |
37 | | - | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
0 commit comments