-
Notifications
You must be signed in to change notification settings - Fork 73
Improve codegen for stdlib <-> df interop workflow #763
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6cda884
Improve toString for the debugger
koperagen e6f744f
Make the assertion message easier to work with
koperagen 4d31ef7
Render FrameColumn<T> as List<T> in generated code to enhance listOf(…
koperagen 52f28a1
Add generateDataClasses for df.toListOf<generated classes> workflow
koperagen 432c94a
[Breaking] Move generateCode from org.jetbrains.kotlinx.dataframe.cod…
koperagen e2e336c
Add an utility to print generated code
koperagen c09c774
Swap default for generateDataClasses extensionProperties
koperagen 9296544
Add field name normalization to generateDataClasses
koperagen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/generateCode.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.jetbrains.kotlinx.dataframe.api | ||
|
||
import org.jetbrains.dataframe.impl.codeGen.CodeGenerator | ||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.codeGen.MarkerVisibility | ||
import org.jetbrains.kotlinx.dataframe.codeGen.NameNormalizer | ||
import org.jetbrains.kotlinx.dataframe.impl.codeGen.from | ||
|
||
public inline fun <reified T> DataFrame<T>.generateCode( | ||
fields: Boolean = true, | ||
extensionProperties: Boolean = true, | ||
): CodeString { | ||
val name = markerName<T>() | ||
return generateCode(name, fields, extensionProperties) | ||
} | ||
|
||
public fun <T> DataFrame<T>.generateCode( | ||
markerName: String, | ||
fields: Boolean = true, | ||
extensionProperties: Boolean = true, | ||
visibility: MarkerVisibility = MarkerVisibility.IMPLICIT_PUBLIC, | ||
): CodeString { | ||
val codeGen = CodeGenerator.create() | ||
return codeGen.generate( | ||
schema = schema(), | ||
name = markerName, | ||
fields = fields, | ||
extensionProperties = extensionProperties, | ||
isOpen = true, | ||
visibility = visibility, | ||
).code.declarations.toCodeString() | ||
} | ||
|
||
public inline fun <reified T> DataFrame<T>.generateInterfaces(): CodeString = generateCode( | ||
fields = true, | ||
extensionProperties = false | ||
) | ||
|
||
public inline fun <reified T> DataFrame<T>.generateDataClasses( | ||
markerName: String? = null, | ||
extensionProperties: Boolean = false, | ||
visibility: MarkerVisibility = MarkerVisibility.IMPLICIT_PUBLIC, | ||
useFqNames: Boolean = false, | ||
nameNormalizer: NameNormalizer = NameNormalizer.default, | ||
): CodeString { | ||
val name = markerName ?: markerName<T>() | ||
val codeGen = CodeGenerator.create(useFqNames) | ||
return codeGen.generate( | ||
schema = schema(), | ||
name = name, | ||
fields = true, | ||
extensionProperties = extensionProperties, | ||
isOpen = false, | ||
visibility = visibility, | ||
asDataClass = true, | ||
fieldNameNormalizer = nameNormalizer | ||
).code.declarations.toCodeString() | ||
} | ||
|
||
@PublishedApi | ||
internal inline fun <reified T> markerName(): String = if (T::class.isAbstract) { | ||
T::class.simpleName!! | ||
} else "DataEntry" | ||
|
||
public fun <T> DataFrame<T>.generateInterfaces(markerName: String): CodeString = generateCode( | ||
markerName = markerName, | ||
fields = true, | ||
extensionProperties = false | ||
) | ||
|
||
/** | ||
* Converts delimited 'my_name', 'my name', etc., String to camelCase 'myName' | ||
*/ | ||
public val NameNormalizer.Companion.default: NameNormalizer get() = NameNormalizer.from(setOf('\t', ' ', '_')) | ||
|
||
@JvmInline | ||
public value class CodeString(public val value: String) { | ||
override fun toString(): String = value | ||
} | ||
|
||
@PublishedApi | ||
internal fun String.toCodeString(): CodeString = CodeString(this) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/generateCode.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.