Skip to content

Commit

Permalink
[Compiler plugin] Fix toDataFrame for different visibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
koperagen committed Jan 30, 2025
1 parent bddf7bf commit f681ae4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.jetbrains.kotlinx.dataframe.plugin.impl.api

import org.jetbrains.kotlin.descriptors.EffectiveVisibility
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlinx.dataframe.plugin.classId
import org.jetbrains.kotlinx.dataframe.plugin.utils.Names
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
import org.jetbrains.kotlin.fir.declarations.utils.isEnumClass
import org.jetbrains.kotlin.fir.declarations.utils.isStatic
import org.jetbrains.kotlin.fir.declarations.utils.visibility
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
Expand Down Expand Up @@ -256,7 +256,7 @@ internal fun KotlinTypeFacade.toDataFrame(
return declarations
.filterNot { excludes.contains(it.first) }
.filterNot { excludedClasses.contains(it.first.resolvedReturnType) }
.filter { it.first.effectiveVisibility == EffectiveVisibility.Public }
.filter { it.first.visibility == Visibilities.Public }
.map { (it, name) ->
var returnType = it.fir.returnTypeRef.resolveIfJavaType(session, JavaTypeParameterStack.EMPTY, null)
.coneType.upperBoundIfFlexible()
Expand Down
20 changes: 20 additions & 0 deletions plugins/kotlin-dataframe/testData/box/toDataFrame_local_class.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import org.jetbrains.kotlinx.dataframe.*
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.api.*
import org.jetbrains.kotlinx.dataframe.io.*

fun box(): String {
data class Name(val firstName: String, val lastName: String)

data class Score(val subject: String, val value: Int)

data class Student(val name: Name, val age: Int, val scores: List<Score>)

val students = listOf(
Student(Name("Alice", "Cooper"), 15, listOf(Score("math", 4), Score("biology", 3))),
Student(Name("Bob", "Marley"), 20, listOf(Score("music", 5))),
).toDataFrame()

students.compareSchemas(strict = true)
return "OK"
}
20 changes: 20 additions & 0 deletions plugins/kotlin-dataframe/testData/box/toDataFrame_private_class.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import org.jetbrains.kotlinx.dataframe.*
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.api.*
import org.jetbrains.kotlinx.dataframe.io.*

private data class Name(val firstName: String, val lastName: String)

private data class Score(val subject: String, val value: Int)

private data class Student(val name: Name, val age: Int, val scores: List<Score>)

fun box(): String {
val students = listOf(
Student(Name("Alice", "Cooper"), 15, listOf(Score("math", 4), Score("biology", 3))),
Student(Name("Bob", "Marley"), 20, listOf(Score("music", 5))),
).toDataFrame()

students.compareSchemas(strict = true)
return "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import org.jetbrains.kotlinx.dataframe.*
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.api.*
import org.jetbrains.kotlinx.dataframe.io.*

data class Name(val firstName: String, val lastName: String)

data class Score(val subject: String, val value: Int)

data class Student(private val name: Name, private val age: Int, val scores: List<Score>)

fun box(): String {
val students = listOf(
Student(Name("Alice", "Cooper"), 15, listOf(Score("math", 4), Score("biology", 3))),
Student(Name("Bob", "Marley"), 20, listOf(Score("music", 5))),
).toDataFrame()

students.compareSchemas(strict = true)
return "OK"
}
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ public void testToDataFrame_from() {
runTest("testData/box/toDataFrame_from.kt");
}

@Test
@TestMetadata("toDataFrame_local_class.kt")
public void testToDataFrame_local_class() {
runTest("testData/box/toDataFrame_local_class.kt");
}

@Test
@TestMetadata("toDataFrame_nested.kt")
public void testToDataFrame_nested() {
Expand All @@ -532,6 +538,18 @@ public void testToDataFrame_nullableSubtree() {
runTest("testData/box/toDataFrame_nullableSubtree.kt");
}

@Test
@TestMetadata("toDataFrame_private_class.kt")
public void testToDataFrame_private_class() {
runTest("testData/box/toDataFrame_private_class.kt");
}

@Test
@TestMetadata("toDataFrame_private_properties.kt")
public void testToDataFrame_private_properties() {
runTest("testData/box/toDataFrame_private_properties.kt");
}

@Test
@TestMetadata("toDataFrame_superType.kt")
public void testToDataFrame_superType() {
Expand Down

0 comments on commit f681ae4

Please sign in to comment.