From c8852f6eb0a4dc7f885caefbbf9ba2326956c608 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 5 Jul 2023 11:44:29 +0200 Subject: [PATCH] formatting --- build.gradle.kts | 1 - .../kolasu/serialization/JsonGenerator.kt | 3 +- .../kolasu/lionwebgen/LionWebGradlePlugin.kt | 42 ++++--- .../kolasu/lionwebgen/{utils.kt => Utils.kt} | 2 +- .../test/kotlin/LionWebGradlePluginTest.kt | 5 +- lionweb-gen/build.gradle | 5 +- .../kolasu/lionweb/KotlinCodeProcessor.kt | 4 +- .../kotlin/RecognizeExistingASTClassesTest.kt | 3 +- lionweb-ksp/build.gradle | 2 + .../kolasu/ksp/KolasuSymbolProcessor.kt | 27 +++-- .../ksp/KolasuSymbolProcessorProvider.kt | 2 +- .../LionWebModelImporterAndExporter.kt | 112 +++++++++--------- settings.gradle.kts | 2 +- 13 files changed, 117 insertions(+), 93 deletions(-) rename lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/{utils.kt => Utils.kt} (93%) diff --git a/build.gradle.kts b/build.gradle.kts index 0b46ac138..d0331d612 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,6 @@ allprojects { repositories { mavenLocal() mavenCentral() - maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/"} } } diff --git a/core/src/main/kotlin/com/strumenta/kolasu/serialization/JsonGenerator.kt b/core/src/main/kotlin/com/strumenta/kolasu/serialization/JsonGenerator.kt index 095eacd46..0e627cf94 100644 --- a/core/src/main/kotlin/com/strumenta/kolasu/serialization/JsonGenerator.kt +++ b/core/src/main/kotlin/com/strumenta/kolasu/serialization/JsonGenerator.kt @@ -38,8 +38,9 @@ fun jsonArray(values: Iterator): JsonArray { } private fun Any?.toJsonElement(): JsonElement { - if (this == null) + if (this == null) { return JsonNull.INSTANCE + } return when (this) { is JsonElement -> this diff --git a/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt b/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt index 428840ce0..1f078c812 100644 --- a/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt +++ b/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt @@ -32,7 +32,7 @@ class LionWebGradlePlugin : Plugin { createGenLanguagesTask(project, configuration) } - private fun createGenASTClassesTask(project: Project, configuration: LionWebGradleExtension) : Task { + private fun createGenASTClassesTask(project: Project, configuration: LionWebGradleExtension): Task { return project.tasks.create(genASTClasses) { it.group = tasksGroup it.doLast { @@ -45,9 +45,14 @@ class LionWebGradlePlugin : Plugin { val jsonser = JsonSerialization.getStandardSerialization() jsonser.nodeResolver.addTree(StarLasuLWLanguage) val language = jsonser.unserializeToNodes(FileInputStream(languageFile)).first() as Language - val existingKotlinClasses = KotlinCodeProcessor().classesDeclaredInDir(project.file("src/main/kotlin")) - - val ktFiles = ASTGenerator(configuration.importPackageNames.get()[language.name] ?: language.name, language) + val existingKotlinClasses = KotlinCodeProcessor().classesDeclaredInDir( + project.file("src/main/kotlin") + ) + + val ktFiles = ASTGenerator( + configuration.importPackageNames.get()[language.name] ?: language.name, + language + ) .generateClasses(existingKotlinClasses) ktFiles.forEach { ktFile -> val file = File(configuration.outdir.get(), ktFile.path) @@ -57,14 +62,13 @@ class LionWebGradlePlugin : Plugin { } } } - } println("LIonWeb AST Classes generation task - completed") } } } - private fun createGenLanguagesTask(project: Project, configuration: LionWebGradleExtension) : Task { + private fun createGenLanguagesTask(project: Project, configuration: LionWebGradleExtension): Task { return project.tasks.create(genLanguages) { it -> it.group = tasksGroup it.dependsOn("compileKotlin") @@ -73,7 +77,7 @@ class LionWebGradlePlugin : Plugin { configuration.exportPackages.get().forEach { packageName -> project.javaexec { jes -> jes.classpath = project.sourceSets.getByName("main").runtimeClasspath - jes.mainClass.set("${packageName}.LanguageKt") + jes.mainClass.set("$packageName.LanguageKt") jes.args = mutableListOf(lionwebLanguageFile(project, packageName).absolutePath) } } @@ -84,7 +88,7 @@ class LionWebGradlePlugin : Plugin { /** * Prepare the plugin configuration setting in place default values. */ - private fun prepareConfiguration(project: Project) : LionWebGradleExtension { + private fun prepareConfiguration(project: Project): LionWebGradleExtension { val configuration = project.extensions.create("lionweb", LionWebGradleExtension::class.java) configuration.outdir.convention(File(project.buildDir, "lionweb-gen")) val srcMainLionweb = project.file("src${File.separator}main${File.separator}lionweb") @@ -98,7 +102,7 @@ class LionWebGradlePlugin : Plugin { return configuration } - private fun lionwebLanguageFile(project: Project, packageName: String) : File { + private fun lionwebLanguageFile(project: Project, packageName: String): File { return File(project.buildDir, "lionwebgen${File.separator}$packageName.json") } @@ -133,16 +137,20 @@ class LionWebGradlePlugin : Plugin { } project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).forEach { - it.source(File(project.buildDir, "lionweb-gen"), - File(project.rootDir, "src${File.separator}main${File.separator}kotlin")) + it.source( + File(project.buildDir, "lionweb-gen"), + File(project.rootDir, "src${File.separator}main${File.separator}kotlin") + ) it.dependsOn(genASTClasses) } } private fun addDependencies(project: Project) { fun addKolasuModule(moduleName: String) { - project.dependencies.add("implementation", - "com.strumenta.kolasu:kolasu-$moduleName:${project.kolasuVersion}") + project.dependencies.add( + "implementation", + "com.strumenta.kolasu:kolasu-$moduleName:${project.kolasuVersion}" + ) } addKolasuModule("core") @@ -153,7 +161,9 @@ class LionWebGradlePlugin : Plugin { project.dependencies.add("implementation", "com.github.ajalt.clikt:clikt:3.5.0") // We need to use this one to avoid an issue with Gson - project.dependencies.add("implementation", "io.lionweb.lioncore-java:lioncore-java-core-fat:${project.lionwebVersion}") + project.dependencies.add( + "implementation", + "io.lionweb.lioncore-java:lioncore-java-core-fat:${project.lionwebVersion}" + ) } - -} \ No newline at end of file +} diff --git a/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/utils.kt b/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/Utils.kt similarity index 93% rename from lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/utils.kt rename to lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/Utils.kt index a6a2a94dc..28191e939 100644 --- a/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/utils.kt +++ b/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/Utils.kt @@ -24,4 +24,4 @@ val Project.kolasuVersion get() = project.propertyValue("kolasuVersion", BuildConfig.PLUGIN_VERSION) val Project.lionwebVersion - get() = project.propertyValue("lionwebVersion", "0.0.18") \ No newline at end of file + get() = project.propertyValue("lionwebVersion", "0.0.18") diff --git a/lionweb-gen-gradle/src/test/kotlin/LionWebGradlePluginTest.kt b/lionweb-gen-gradle/src/test/kotlin/LionWebGradlePluginTest.kt index 713f4c8a9..a2dd9eb48 100644 --- a/lionweb-gen-gradle/src/test/kotlin/LionWebGradlePluginTest.kt +++ b/lionweb-gen-gradle/src/test/kotlin/LionWebGradlePluginTest.kt @@ -4,8 +4,6 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import java.io.File import java.nio.file.Files -import kotlin.test.Ignore - class LionWebGradlePluginTest { var projectDir: File? = null @@ -60,5 +58,4 @@ class LionWebGradlePluginTest { runner.withProjectDir(projectDir) val result = runner.build() } - -} \ No newline at end of file +} diff --git a/lionweb-gen/build.gradle b/lionweb-gen/build.gradle index 13cf44ccd..a5963af96 100644 --- a/lionweb-gen/build.gradle +++ b/lionweb-gen/build.gradle @@ -41,6 +41,9 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version") } +def isReleaseVersion = !(version as String).endsWith("SNAPSHOT") + + publishing { repositories { @@ -60,7 +63,7 @@ publishing { from components.java artifactId "kolasu-" + project.name artifact sourcesJar - artifact javadocJar + artifact kdocJar suppressPomMetadataWarningsFor('cliApiElements') suppressPomMetadataWarningsFor('cliRuntimeElements') pom { diff --git a/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/KotlinCodeProcessor.kt b/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/KotlinCodeProcessor.kt index 08f33421a..83c71ee47 100644 --- a/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/KotlinCodeProcessor.kt +++ b/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/KotlinCodeProcessor.kt @@ -57,7 +57,9 @@ class KotlinCodeProcessor { val disposable = Disposer.newDisposable() try { val env = KotlinCoreEnvironment.createForProduction( - disposable, CompilerConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES + disposable, + CompilerConfiguration(), + EnvironmentConfigFiles.JVM_CONFIG_FILES ) val file = LightVirtualFile("temp.kt", KotlinFileType.INSTANCE, code) return PsiManager.getInstance(env.project).findFile(file) as KtFile diff --git a/lionweb-gen/src/test/kotlin/RecognizeExistingASTClassesTest.kt b/lionweb-gen/src/test/kotlin/RecognizeExistingASTClassesTest.kt index e0b3d2ece..b141f9e53 100644 --- a/lionweb-gen/src/test/kotlin/RecognizeExistingASTClassesTest.kt +++ b/lionweb-gen/src/test/kotlin/RecognizeExistingASTClassesTest.kt @@ -52,7 +52,8 @@ public data class Property( val existingClasses = KotlinCodeProcessor().classesDeclaredInFile(code) assertEquals( setOf( - "com.strumenta.props.PropertiesFile", "com.strumenta.props.SomeOtherClass", + "com.strumenta.props.PropertiesFile", + "com.strumenta.props.SomeOtherClass", "com.strumenta.props.Property" ), existingClasses diff --git a/lionweb-ksp/build.gradle b/lionweb-ksp/build.gradle index b0c0cbefc..419b6991e 100644 --- a/lionweb-ksp/build.gradle +++ b/lionweb-ksp/build.gradle @@ -11,6 +11,8 @@ dependencies { implementation(project(":core")) } +def isReleaseVersion = !(version as String).endsWith("SNAPSHOT") + publishing { repositories { diff --git a/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessor.kt b/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessor.kt index ab20897c4..1cdfa3db8 100644 --- a/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessor.kt +++ b/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessor.kt @@ -15,12 +15,12 @@ import java.lang.IllegalStateException class KolasuSymbolProcessor(val environment: SymbolProcessorEnvironment) : SymbolProcessor { - var generated : Boolean = false + var generated: Boolean = false class LanguageDef(val packageName: String) { val classes = mutableListOf() - fun dependencies() : Dependencies { + fun dependencies(): Dependencies { val usedFiles = this.classes.mapNotNull { it.containingFile }.toSet().toTypedArray() val dependencies = Dependencies(true, *usedFiles) return dependencies @@ -28,7 +28,8 @@ class KolasuSymbolProcessor(val environment: SymbolProcessorEnvironment) : Symbo fun write(os: OutputStream) { val buf = PrintWriter(os) - buf.println(""" + buf.println( + """ // ${classes.first().containingFile?.filePath} // ${classes.first().containingFile?.origin} package $packageName @@ -50,7 +51,8 @@ class KolasuSymbolProcessor(val environment: SymbolProcessorEnvironment) : Symbo fun main(args: Array) { LanguageGeneratorCommand(lwLanguage).main(args) } - """.trimIndent()) + """.trimIndent() + ) buf.flush() } } @@ -61,7 +63,6 @@ class KolasuSymbolProcessor(val environment: SymbolProcessorEnvironment) : Symbo } val exportPackagesStr = kspFile.readText().trim().split("=")[1] - if (exportPackagesStr.isNullOrBlank()) { // No packages to export, we are done here return emptyList() @@ -73,7 +74,9 @@ class KolasuSymbolProcessor(val environment: SymbolProcessorEnvironment) : Symbo val packageName = ksFile.packageName.asString() ksFile.declarations.forEach { ksDeclaration -> if (ksDeclaration is KSClassDeclaration) { - val isNodeDecl = ksDeclaration.getAllSuperTypes().any { it.declaration.qualifiedName?.asString() == Node::class.qualifiedName} + val isNodeDecl = ksDeclaration.getAllSuperTypes().any { + it.declaration.qualifiedName?.asString() == Node::class.qualifiedName + } if (isNodeDecl) { languagesByPackage.computeIfAbsent(packageName) { LanguageDef(packageName) @@ -85,12 +88,18 @@ class KolasuSymbolProcessor(val environment: SymbolProcessorEnvironment) : Symbo if (!generated) { languagesByPackage.values.forEach { languageDef -> - languageDef.write(environment.codeGenerator.createNewFile(languageDef.dependencies(), - languageDef.packageName, "Language", "kt")) + languageDef.write( + environment.codeGenerator.createNewFile( + languageDef.dependencies(), + languageDef.packageName, + "Language", + "kt" + ) + ) } generated = true } return emptyList() } -} \ No newline at end of file +} diff --git a/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessorProvider.kt b/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessorProvider.kt index 6831a06af..262bef52e 100644 --- a/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessorProvider.kt +++ b/lionweb-ksp/src/main/kotlin/com/strumenta/kolasu/ksp/KolasuSymbolProcessorProvider.kt @@ -8,4 +8,4 @@ class KolasuSymbolProcessorProvider : SymbolProcessorProvider { override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { return KolasuSymbolProcessor(environment) } -} \ No newline at end of file +} diff --git a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelImporterAndExporter.kt b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelImporterAndExporter.kt index 1178f77d7..34ddfb47e 100644 --- a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelImporterAndExporter.kt +++ b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelImporterAndExporter.kt @@ -146,76 +146,76 @@ class LionWebModelImporterAndExporter { } } - val params = mutableMapOf() - constructor.parameters.forEach { param -> - val feature = data.concept.getFeatureByName(param.name!!) - if (feature == null) { - TODO() - } else { - when (feature) { - is Property -> { - params[param] = data.getPropertyValue(feature) - } + val params = mutableMapOf() + constructor.parameters.forEach { param -> + val feature = data.concept.getFeatureByName(param.name!!) + if (feature == null) { + TODO() + } else { + when (feature) { + is Property -> { + params[param] = data.getPropertyValue(feature) + } - is Reference -> { - val referenceValues = data.getReferenceValues(feature) - when { - referenceValues.size > 1 -> { - throw IllegalStateException() - } + is Reference -> { + val referenceValues = data.getReferenceValues(feature) + when { + referenceValues.size > 1 -> { + throw IllegalStateException() + } - referenceValues.size == 0 -> { - params[param] = null - } + referenceValues.size == 0 -> { + params[param] = null + } - referenceValues.size == 1 -> { - val rf = referenceValues.first() - val referenceByName = ReferenceByName(rf.resolveInfo!!, null) - referencesPostponer.registerPostponedReference(referenceByName, rf.referred) - params[param] = referenceByName - } + referenceValues.size == 1 -> { + val rf = referenceValues.first() + val referenceByName = ReferenceByName(rf.resolveInfo!!, null) + referencesPostponer.registerPostponedReference(referenceByName, rf.referred) + params[param] = referenceByName } } + } - is Containment -> { - val lwChildren = data.getChildren(feature) - if (feature.isMultiple) { - val kChildren = lwChildren.map { lwToKolasuNodesMapping[it]!! } - params[param] = kChildren - } else { - // Given we navigate the tree in reverse the child should have been already - // instantiated - val lwChild: Node? = when (lwChildren.size) { - 0 -> { - null - } - - 1 -> { - lwChildren.first() - } + is Containment -> { + val lwChildren = data.getChildren(feature) + if (feature.isMultiple) { + val kChildren = lwChildren.map { lwToKolasuNodesMapping[it]!! } + params[param] = kChildren + } else { + // Given we navigate the tree in reverse the child should have been already + // instantiated + val lwChild: Node? = when (lwChildren.size) { + 0 -> { + null + } - else -> { - throw IllegalStateException() - } + 1 -> { + lwChildren.first() } - val kChild = if (lwChild == null) { - null - } else { - ( - lwToKolasuNodesMapping[lwChild] - ?: throw IllegalStateException( - "Unable to find Kolasu Node corresponding to $lwChild" - ) - ) + + else -> { + throw IllegalStateException() } - params[param] = kChild } + val kChild = if (lwChild == null) { + null + } else { + ( + lwToKolasuNodesMapping[lwChild] + ?: throw IllegalStateException( + "Unable to find Kolasu Node corresponding to $lwChild" + ) + ) + } + params[param] = kChild } - - else -> throw IllegalStateException() } + + else -> throw IllegalStateException() } } + } return constructor.callBy(params) as com.strumenta.kolasu.model.Node } diff --git a/settings.gradle.kts b/settings.gradle.kts index 70db03a53..4e62d62aa 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,4 +20,4 @@ include("kotlin-ir-plugin-gradle") include("lionweb") include("lionweb-gen") include("lionweb-ksp") -include("lionweb-gen-gradle") \ No newline at end of file +include("lionweb-gen-gradle")