Commit b766d5b
kotlin-extractor: PSI-backed source locations for expression-level nodes
K1 and K2 IR backends compute source locations differently. K1 uses the IR
node's synthetic startOffset/endOffset, while K2 reconstructs source positions
from PSI. For expression-level nodes this causes location differences across
the two language modes.
Introduce PSI-backed location lookup as the preferred source for spans wherever
PSI is available:
getPsiBasedLocation(element) ?: tw.getLocation(element)
getPsiBasedLocation() resolves the PSI element for the IR node via
psi2Ir.findPsiElement() and builds a location from its startOffset..endOffset.
currentIrFile is tracked in extractFileContents so the PSI lookup has the
file context it needs.
Applied to expression-level nodes (both K1 and K2 modes):
- local variable declarations (extractVariable, extractVariableExpr)
- IrLocalDelegatedProperty blocks
- IrWhen expressions and when-branches
- IrGetValue (varaccess) expressions
- IrFunctionExpression (lambda) nodes
- Block statements (extractBlock)
- this/super access expressions (extractThisAccess)
- String literals
Declaration-level nodes (class, function, property) are guarded with
if (usesK2) to avoid a regression in K1 mode where the PSI lookup causes
parameterised type instantiations to appear as fromSource(), inflating
generic-type query results. The K1 IR frontend does not map all declaration
nodes cleanly to source PSI elements; for these nodes we keep the original
IR-based location in K1 mode.
Expected output changes (both suites):
- controlflow/basic/bbStmts, bbStrictDominance, bbSuccessor, getASuccessor,
strictDominance: when-branch and varaccess location improvements
- java-kotlin-collection-type-generic-methods/test: new stdlib entries from
JDK update (AbstractCollection<Runnable> methods)
- annotation_classes/PrintAst: variable access location improvement in K1
- classes/genericExprTypes: location improvement in K1
- compilation-units/cus: removed two internal JDK inner-class entries (stdlib
version change)
- reflection/reflection: removed a few external-class entries (stdlib version)
Verified: all 285 tests pass for both test-kotlin1 (kotlinc 2.3.20 / K1) and
test-kotlin2 (kotlinc 2.4.0 / K2).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent c1e8d4a commit b766d5b
8 files changed
Lines changed: 59 additions & 34 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin
- ql/test-kotlin1/library-tests
- annotation_classes
- classes
- controlflow/basic
Lines changed: 41 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
111 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
112 | 118 | | |
113 | 119 | | |
114 | 120 | | |
| |||
158 | 164 | | |
159 | 165 | | |
160 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
161 | 170 | | |
162 | 171 | | |
163 | 172 | | |
| |||
672 | 681 | | |
673 | 682 | | |
674 | 683 | | |
675 | | - | |
| 684 | + | |
| 685 | + | |
676 | 686 | | |
677 | 687 | | |
678 | 688 | | |
| |||
691 | 701 | | |
692 | 702 | | |
693 | 703 | | |
694 | | - | |
| 704 | + | |
| 705 | + | |
695 | 706 | | |
696 | 707 | | |
697 | 708 | | |
| |||
954 | 965 | | |
955 | 966 | | |
956 | 967 | | |
957 | | - | |
| 968 | + | |
| 969 | + | |
958 | 970 | | |
959 | 971 | | |
960 | 972 | | |
| |||
2435 | 2447 | | |
2436 | 2448 | | |
2437 | 2449 | | |
| 2450 | + | |
2438 | 2451 | | |
2439 | 2452 | | |
2440 | 2453 | | |
| |||
2644 | 2657 | | |
2645 | 2658 | | |
2646 | 2659 | | |
2647 | | - | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
2648 | 2663 | | |
2649 | 2664 | | |
2650 | 2665 | | |
| |||
2874 | 2889 | | |
2875 | 2890 | | |
2876 | 2891 | | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
2877 | 2902 | | |
2878 | 2903 | | |
2879 | 2904 | | |
| |||
2882 | 2907 | | |
2883 | 2908 | | |
2884 | 2909 | | |
2885 | | - | |
| 2910 | + | |
2886 | 2911 | | |
2887 | 2912 | | |
2888 | 2913 | | |
| |||
2900 | 2925 | | |
2901 | 2926 | | |
2902 | 2927 | | |
2903 | | - | |
| 2928 | + | |
2904 | 2929 | | |
2905 | 2930 | | |
2906 | 2931 | | |
| |||
2972 | 2997 | | |
2973 | 2998 | | |
2974 | 2999 | | |
2975 | | - | |
| 3000 | + | |
2976 | 3001 | | |
2977 | 3002 | | |
2978 | 3003 | | |
| |||
6087 | 6112 | | |
6088 | 6113 | | |
6089 | 6114 | | |
6090 | | - | |
| 6115 | + | |
6091 | 6116 | | |
6092 | 6117 | | |
6093 | 6118 | | |
| |||
6301 | 6326 | | |
6302 | 6327 | | |
6303 | 6328 | | |
6304 | | - | |
| 6329 | + | |
6305 | 6330 | | |
6306 | 6331 | | |
6307 | 6332 | | |
| |||
6329 | 6354 | | |
6330 | 6355 | | |
6331 | 6356 | | |
6332 | | - | |
| 6357 | + | |
6333 | 6358 | | |
6334 | 6359 | | |
6335 | 6360 | | |
| |||
6343 | 6368 | | |
6344 | 6369 | | |
6345 | 6370 | | |
6346 | | - | |
| 6371 | + | |
6347 | 6372 | | |
6348 | 6373 | | |
6349 | 6374 | | |
| |||
6450 | 6475 | | |
6451 | 6476 | | |
6452 | 6477 | | |
6453 | | - | |
| 6478 | + | |
6454 | 6479 | | |
6455 | 6480 | | |
6456 | 6481 | | |
| |||
6571 | 6596 | | |
6572 | 6597 | | |
6573 | 6598 | | |
6574 | | - | |
| 6599 | + | |
6575 | 6600 | | |
6576 | 6601 | | |
6577 | 6602 | | |
| |||
6635 | 6660 | | |
6636 | 6661 | | |
6637 | 6662 | | |
6638 | | - | |
| 6663 | + | |
6639 | 6664 | | |
6640 | 6665 | | |
6641 | 6666 | | |
| |||
7002 | 7027 | | |
7003 | 7028 | | |
7004 | 7029 | | |
7005 | | - | |
| 7030 | + | |
7006 | 7031 | | |
7007 | 7032 | | |
7008 | 7033 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
| 318 | + | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | | - | |
46 | | - | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | | - | |
| 499 | + | |
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
| 508 | + | |
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| |||
515 | 515 | | |
516 | 516 | | |
517 | 517 | | |
518 | | - | |
| 518 | + | |
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
524 | 524 | | |
525 | | - | |
| 525 | + | |
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
530 | | - | |
| 530 | + | |
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
535 | | - | |
| 534 | + | |
| 535 | + | |
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| |||
0 commit comments