Skip to content

Commit 730f54a

Browse files
authored
Merge pull request github#9280 from tamasvajk/kotlin-map-kj-properties
Kotlin: Fix missing kotlin to java property mapping
2 parents ae56b82 + 5a54218 commit 730f54a

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.semmle.extractor.java.OdasaOutput
66
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
77
import org.jetbrains.kotlin.backend.common.ir.allOverridden
88
import org.jetbrains.kotlin.backend.common.lower.parentsWithSelf
9+
import org.jetbrains.kotlin.backend.jvm.ir.propertyIfAccessor
910
import org.jetbrains.kotlin.builtins.StandardNames
1011
import org.jetbrains.kotlin.descriptors.*
1112
import org.jetbrains.kotlin.ir.declarations.*
@@ -960,7 +961,19 @@ open class KotlinUsesExtractor(
960961
decl.name == f.name &&
961962
decl.valueParameters.size == f.valueParameters.size
962963
} ?:
963-
run {
964+
// Or check property accessors:
965+
if (f.isAccessor) {
966+
val prop = javaClass.declarations.filterIsInstance<IrProperty>().find { decl ->
967+
decl.name == (f.propertyIfAccessor as IrProperty).name
968+
}
969+
if (prop?.getter?.name == f.name)
970+
prop.getter
971+
else if (prop?.setter?.name == f.name)
972+
prop.setter
973+
else null
974+
} else {
975+
null
976+
} ?: run {
964977
val parentFqName = parentClass.fqNameWhenAvailable?.asString()
965978
if (!expectedMissingEquivalents.contains(parentFqName)) {
966979
logger.warn("Couldn't find a Java equivalent function to $parentFqName.${f.name} in ${javaClass.fqNameWhenAvailable}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
diagnostics
2+
#select
13
| Integer |
24
| Object |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
fun test(m: Map<Int, Int>) = m.getOrDefault(1, 2)
2+
3+
fun test2(s: String) = s.length
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import java
2+
import semmle.code.java.Diagnostics
23

34
from MethodAccess ma
45
select ma.getCallee().getAParameter().getType().toString()
6+
7+
query predicate diagnostics(Diagnostic d) { any() }

0 commit comments

Comments
 (0)