Commit 6a1ac1b
authored
Kotlin: remap builtins on Java-origin method/field types (#7428)
* Kotlin: remap builtins on method parameter, return, and variable types
`KotlinTypeMapping` applied `remapKotlinBuiltin` to supertypes,
interfaces, generic bounds, and annotations in #7364, but not to
method parameter types, return types, receiver types, or field
types. A Kotlin `IllegalArgumentException("msg", cause)` therefore
produced a constructor whose parameter types were `kotlin.String` /
`kotlin.Throwable`, so a `MethodMatcher` written against the Java
FQNs (`java.lang.String` / `java.lang.Throwable`) failed to match on
Kotlin sources even though the bytecode signature is identical.
Wire `remapKotlinBuiltin` through both `methodDeclarationType` and
`methodInvocationType` (parameter types, return type, receiver) and
through `variableType` (field/property type).
* Scope Kotlin builtin remap to Java-origin classes
Following review on #7428, only remap kotlin.* parameter/return/field
types when the declaring class is a FirJavaClass (third-party Java
libraries on the classpath). Kotlin-declared signatures —
`kotlin.io.ConsoleKt.println(kotlin.Any)`, user properties of type
`String`, etc. — keep their author-intended Kotlin builtin names.
The motivating case (#7427) is Jackson's JsonGenerationException,
which is FirJavaClass; the test now uses that directly. JDK classes
go through Kotlin's classfile loader as something other than
FirJavaClass and are out of scope here — recipes that target JDK
signatures over Kotlin code need a Kotlin-aware MethodMatcher.
* Use reduce() to assign found in new test1 parent 0b1667c commit 6a1ac1b
2 files changed
Lines changed: 85 additions & 8 deletions
File tree
- rewrite-kotlin/src
- main/kotlin/org/openrewrite/kotlin
- test/java/org/openrewrite/kotlin
Lines changed: 47 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
702 | 703 | | |
703 | 704 | | |
704 | 705 | | |
705 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
706 | 715 | | |
707 | 716 | | |
708 | 717 | | |
| |||
719 | 728 | | |
720 | 729 | | |
721 | 730 | | |
722 | | - | |
| 731 | + | |
| 732 | + | |
723 | 733 | | |
724 | 734 | | |
725 | 735 | | |
726 | 736 | | |
727 | 737 | | |
728 | | - | |
| 738 | + | |
729 | 739 | | |
730 | 740 | | |
731 | 741 | | |
| |||
971 | 981 | | |
972 | 982 | | |
973 | 983 | | |
974 | | - | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
975 | 994 | | |
976 | 995 | | |
977 | | - | |
| 996 | + | |
| 997 | + | |
978 | 998 | | |
979 | 999 | | |
980 | 1000 | | |
| |||
991 | 1011 | | |
992 | 1012 | | |
993 | 1013 | | |
994 | | - | |
| 1014 | + | |
| 1015 | + | |
995 | 1016 | | |
996 | 1017 | | |
997 | 1018 | | |
998 | 1019 | | |
999 | | - | |
| 1020 | + | |
1000 | 1021 | | |
1001 | 1022 | | |
1002 | 1023 | | |
| |||
1112 | 1133 | | |
1113 | 1134 | | |
1114 | 1135 | | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1115 | 1148 | | |
1116 | 1149 | | |
1117 | 1150 | | |
| |||
1277 | 1310 | | |
1278 | 1311 | | |
1279 | 1312 | | |
1280 | | - | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
1281 | 1320 | | |
1282 | 1321 | | |
1283 | 1322 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
550 | 588 | | |
551 | 589 | | |
552 | 590 | | |
| |||
0 commit comments