-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup compiler plugin project with tests
- Loading branch information
Showing
102 changed files
with
3,104 additions
and
711 deletions.
There are no files selected for viewing
This file contains 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 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
10 changes: 10 additions & 0 deletions
10
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/bridges.kt
This file contains 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,10 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin | ||
|
||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.api.cast | ||
import org.jetbrains.kotlinx.dataframe.io.readJson | ||
import org.jetbrains.kotlinx.dataframe.plugin.model.Bridge | ||
|
||
val bridges by lazy { DataFrame.readJson("/bridges.json".resource()).cast<Bridge>(verify = true) } | ||
|
||
fun String.resource() = object {}.javaClass.getResource(this)!! |
3 changes: 2 additions & 1 deletion
3
.../main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/codeGen/generateDfFunctionTestStub.kt
This file contains 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
88 changes: 88 additions & 0 deletions
88
.../src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/codeGen/generateSchemaTestStub.kt
This file contains 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,88 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.codeGen | ||
|
||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.KotlinTypeFacade | ||
import org.jetbrains.kotlinx.dataframe.api.column | ||
import org.jetbrains.kotlinx.dataframe.api.first | ||
import org.jetbrains.kotlinx.dataframe.plugin.PluginDataFrameSchema | ||
import org.jetbrains.kotlinx.dataframe.plugin.bridges | ||
import org.jetbrains.kotlinx.dataframe.plugin.generateSchemaDeclaration | ||
import org.jetbrains.kotlinx.dataframe.plugin.generateTestCode | ||
import org.jetbrains.kotlinx.dataframe.plugin.model.name | ||
import org.jetbrains.kotlinx.dataframe.plugin.model.type | ||
import org.jetbrains.kotlinx.dataframe.plugin.pluginSchema | ||
import java.util.* | ||
|
||
fun KotlinTypeFacade.generateSchemaTestStub(name: String, expression: () -> DataFrame<*>): PluginDataFrameSchema { | ||
val approximation by column<String>() | ||
fun writeInterpreter(s: String) { | ||
// val root = File("/home/nikitak/IdeaProjects/dataframe/core/src/main") | ||
// val schemaRender = File(root, "kotlin/org/jetbrains/kotlinx/dataframe/plugin/testing/schemaRender").also { it.mkdirs() } | ||
// File(schemaRender, "$name.kt").writeText(s) | ||
println(s) | ||
} | ||
|
||
fun writeTestStub(s: String) { | ||
// val root = File("/home/nikitak/Downloads/kotlin/plugins/kotlin-dataframe") | ||
// val schemaRender = File(root, "testData/diagnostics/schemaRender").also { it.mkdirs() } | ||
// File(schemaRender, "$name.kt") | ||
println(s) | ||
} | ||
|
||
val capitalizedName = name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } | ||
|
||
// val repl = object : JupyterReplTestCase() { | ||
// } | ||
val df = expression() | ||
// val df = repl.execRaw("val df = $expression; df") as DataFrame<*> | ||
val declaration = df.generateSchemaDeclaration(capitalizedName) | ||
val schemaTestCode = df.generateTestCode() | ||
//repl.exec(schemaTestCode) | ||
|
||
val pluginSchema = df.pluginSchema() | ||
//val jsonString = pluginSchema.toJson() | ||
|
||
|
||
bridges.first { it.type.name == "DataFrame<T>" }.run { | ||
writeInterpreter(""" | ||
package org.jetbrains.kotlinx.dataframe.plugin.testing.schemaRender | ||
import kotlinx.serialization.decodeFromString | ||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.annotations.AbstractInterpreter | ||
import org.jetbrains.kotlinx.dataframe.annotations.Arguments | ||
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable | ||
import org.jetbrains.kotlinx.dataframe.plugin.* | ||
@Interpretable(${capitalizedName}::class) | ||
public fun $name(): DataFrame<*> { | ||
return TODO("won't run") | ||
} | ||
public class ${capitalizedName} : AbstractInterpreter<$approximation>() { | ||
override fun Arguments.interpret(): $approximation { | ||
return SchemaData.$name() | ||
} | ||
} | ||
""".trimIndent()) | ||
} | ||
val schemaDeclaration = declaration.lineSequence().joinToString("\n|") | ||
writeTestStub(""" | ||
|import org.jetbrains.kotlinx.dataframe.* | ||
|import org.jetbrains.kotlinx.dataframe.api.* | ||
|import org.jetbrains.kotlinx.dataframe.annotations.* | ||
|import org.jetbrains.kotlinx.dataframe.plugin.testing.* | ||
|import org.jetbrains.kotlinx.dataframe.plugin.testing.schemaRender.* | ||
| | ||
|/* | ||
|$schemaDeclaration | ||
|*/ | ||
| | ||
|internal fun schemaTest() { | ||
| val df = $name() | ||
| ${schemaTestCode} | ||
|} | ||
""".trimMargin()) | ||
|
||
return pluginSchema | ||
} |
11 changes: 11 additions & 0 deletions
11
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/Bridge.kt
This file contains 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,11 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.api.DataRowSchema | ||
|
||
@DataSchema | ||
class Bridge(val type: Type, | ||
val approximation: String, | ||
val converter: String, | ||
val lens: String, | ||
val supported: Boolean = false) : DataRowSchema |
15 changes: 15 additions & 0 deletions
15
...enerator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/ClassDeclaration.kt
This file contains 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,15 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.annotations.GenerateConstructor | ||
import org.jetbrains.kotlinx.dataframe.api.DataRowSchema | ||
import org.jetbrains.kotlinx.dataframe.plugin.model.Parameter | ||
|
||
@DataSchema | ||
interface ClassDeclaration : DataRowSchema { | ||
val name: String | ||
val parameters: List<Parameter> | ||
|
||
@GenerateConstructor | ||
companion object | ||
} |
13 changes: 13 additions & 0 deletions
13
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/Function.kt
This file contains 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,13 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.api.DataRowSchema | ||
|
||
@DataSchema | ||
class Function( | ||
val receiverType: String, | ||
val function: String, | ||
val functionReturnType: Type, | ||
val parameters: List<Parameter> | ||
) : DataRowSchema { | ||
} |
11 changes: 11 additions & 0 deletions
11
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/Parameter.kt
This file contains 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,11 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.api.DataRowSchema | ||
|
||
@DataSchema | ||
class Parameter( | ||
val name: String, | ||
val returnType: Type, | ||
val defaultValue: String?, | ||
) : DataRowSchema |
13 changes: 13 additions & 0 deletions
13
...generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/RefinedFunction.kt
This file contains 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,13 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.api.DataRowSchema | ||
|
||
@DataSchema | ||
class RefinedFunction( | ||
val receiverType: String, | ||
val function: String, | ||
val functionReturnType: Type, | ||
val parameters: List<Parameter>, | ||
val startingSchema: Parameter | ||
) : DataRowSchema |
14 changes: 14 additions & 0 deletions
14
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/TestCase.kt
This file contains 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,14 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.annotations.GenerateConstructor | ||
import org.jetbrains.kotlinx.dataframe.api.DataRowSchema | ||
|
||
@DataSchema | ||
interface TestCase : DataRowSchema { | ||
val dfExpression: String | ||
val functionCalls: List<String> | ||
|
||
@GenerateConstructor | ||
companion object | ||
} |
6 changes: 6 additions & 0 deletions
6
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/model/Type.kt
This file contains 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,6 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.model | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
|
||
@DataSchema | ||
data class Type(val name: String, val vararg: Boolean) |
29 changes: 29 additions & 0 deletions
29
bridge-generator/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/schema.kt
This file contains 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,29 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin | ||
|
||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.KotlinTypeFacade | ||
import org.jetbrains.kotlinx.dataframe.api.columnOf | ||
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf | ||
import org.jetbrains.kotlinx.dataframe.io.readJson | ||
import org.jetbrains.kotlinx.dataframe.plugin.codeGen.generateSchemaTestStub | ||
|
||
object SchemaData { | ||
fun KotlinTypeFacade.schema1(): PluginDataFrameSchema = generateSchemaTestStub( | ||
name = "schema1" | ||
) { | ||
DataFrame.readJson("/functions.json".resource()) | ||
} | ||
|
||
fun KotlinTypeFacade.schema2(): PluginDataFrameSchema = generateSchemaTestStub( | ||
name = "schema2" | ||
) { | ||
val name by columnOf("name") | ||
val returnType by columnOf("") | ||
val df = dataFrameOf(name, returnType) | ||
val functions by columnOf(df) | ||
val function by columnOf(name, returnType) | ||
val nestedGroup by columnOf(name) | ||
val group by columnOf(nestedGroup) | ||
dataFrameOf(name, functions, function, group) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
...or/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/testing/schemaRender/Schema1.kt
This file contains 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,21 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.testing.schemaRender | ||
|
||
import kotlinx.serialization.decodeFromString | ||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.annotations.AbstractInterpreter | ||
import org.jetbrains.kotlinx.dataframe.annotations.Arguments | ||
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable | ||
import org.jetbrains.kotlinx.dataframe.plugin.PluginDataFrameSchema | ||
import org.jetbrains.kotlinx.dataframe.plugin.SchemaData.schema1 | ||
import org.jetbrains.kotlinx.dataframe.plugin.pluginJsonFormat | ||
|
||
@Interpretable(Schema1::class) | ||
public fun schema1(): DataFrame<*> { | ||
return TODO("won't run") | ||
} | ||
|
||
public class Schema1 : AbstractInterpreter<PluginDataFrameSchema>() { | ||
override fun Arguments.interpret(): PluginDataFrameSchema { | ||
return schema1() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...or/src/main/kotlin/org/jetbrains/kotlinx/dataframe/plugin/testing/schemaRender/Schema2.kt
This file contains 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,20 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.testing.schemaRender | ||
|
||
import kotlinx.serialization.decodeFromString | ||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.annotations.AbstractInterpreter | ||
import org.jetbrains.kotlinx.dataframe.annotations.Arguments | ||
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable | ||
import org.jetbrains.kotlinx.dataframe.plugin.* | ||
import org.jetbrains.kotlinx.dataframe.plugin.SchemaData.schema2 | ||
|
||
@Interpretable(Schema2::class) | ||
public fun schema2(): DataFrame<*> { | ||
return TODO("won't run") | ||
} | ||
|
||
public class Schema2 : AbstractInterpreter<PluginDataFrameSchema>() { | ||
override fun Arguments.interpret(): PluginDataFrameSchema { | ||
return schema2() | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.