Skip to content

[Compiler plugin] Fix toDataFrame for different visibilities #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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