Skip to content

Commit

Permalink
Merge branch 'release/0.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed Sep 11, 2024
2 parents 09d4ea3 + 1ceb459 commit 94db706
Show file tree
Hide file tree
Showing 101 changed files with 1,461 additions and 418 deletions.
2 changes: 1 addition & 1 deletion _build/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-root</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion _build/report-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-parent</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion _itest/builder-itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-itest-root</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
</parent>

<groupId>io.toolisticon.kotlin.generation.itest</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class)

package io.toolisticon.kotlin.generation.itest

Expand All @@ -9,6 +8,7 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFile
import io.toolisticon.kotlin.generation.itest.KotlinCodeGenerationITestConfig.ROOT_PACKAGE


@OptIn(ExperimentalKotlinPoetApi::class)
object MyCustomAnnotationSpec {
val name = ClassName(ROOT_PACKAGE, "MyCustomAnnotation")

Expand Down
41 changes: 41 additions & 0 deletions _itest/builder-itest/src/test/kotlin/DelegateStringListITest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.toolisticon.kotlin.generation.itest

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import com.tschuchort.compiletesting.KotlinCompilation
import io.toolisticon.kotlin.generation.KotlinCodeGeneration
import io.toolisticon.kotlin.generation.itest.KotlinCodeGenerationITestConfig.ROOT_PACKAGE
import io.toolisticon.kotlin.generation.spec.toFileSpec
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest
import io.toolisticon.kotlin.generation.test.model.KotlinCompilationCommand
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test
import kotlin.reflect.KClass
import kotlin.reflect.full.primaryConstructor
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.assertThat as compileAssertThat

@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class DelegateStringListITest {

@Test
fun `create and use string list`() {
val list = KotlinCodeGeneration.buildDelegateListValueClass(ROOT_PACKAGE, "StringList", String::class) {
propertyName("list")
}.toFileSpec()

val result = KotlinCodeGenerationTest.compile(KotlinCompilationCommand(list))


compileAssertThat(result).errorMessages().isEmpty()
compileAssertThat(result).hasExitCode(KotlinCompilation.ExitCode.OK)

val klass: KClass<out Any> = result.loadClass(list.className)

val values = listOf("a", "b", "c")

val instance: List<String> = klass.primaryConstructor!!.call(values) as List<String>

assertThat(instance).hasToString("StringList(list=[a, b, c])")
}
}
44 changes: 44 additions & 0 deletions _itest/builder-itest/src/test/kotlin/DelegateStringLongMapITest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.toolisticon.kotlin.generation.itest

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import com.squareup.kotlinpoet.asTypeName
import com.tschuchort.compiletesting.KotlinCompilation
import io.toolisticon.kotlin.generation.KotlinCodeGeneration
import io.toolisticon.kotlin.generation.itest.KotlinCodeGenerationITestConfig.ROOT_PACKAGE
import io.toolisticon.kotlin.generation.spec.toFileSpec
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest
import io.toolisticon.kotlin.generation.test.model.KotlinCompilationCommand
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test
import kotlin.reflect.KClass
import kotlin.reflect.full.primaryConstructor
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.assertThat as compileAssertThat

@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class DelegateStringLongMapITest {

@Test
fun `create and use string long map`() {
val map = KotlinCodeGeneration.buildDelegateMapValueClass(
packageName = ROOT_PACKAGE,
simpleName = "StringLongMap",
valueType = Long::class.asTypeName()
) {
propertyName("map")
}.toFileSpec()

val result = KotlinCodeGenerationTest.compile(KotlinCompilationCommand(map))
compileAssertThat(result).errorMessages().isEmpty()
compileAssertThat(result).hasExitCode(KotlinCompilation.ExitCode.OK)

val klass: KClass<out Any> = result.loadClass(map.className)

val values = mapOf("a" to 1, "b" to 2, "c" to 3)

val instance: Map<String, Long> = klass.primaryConstructor!!.call(values) as Map<String, Long>

assertThat(instance).hasToString("StringLongMap(map={a=1, b=2, c=3})")
}
}
52 changes: 52 additions & 0 deletions _itest/builder-itest/src/test/kotlin/DummyExceptionITest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.toolisticon.kotlin.generation.itest

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import com.tschuchort.compiletesting.KotlinCompilation
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildRuntimeExceptionClass
import io.toolisticon.kotlin.generation.itest.KotlinCodeGenerationITestConfig.ROOT_PACKAGE
import io.toolisticon.kotlin.generation.spec.toFileSpec
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest
import io.toolisticon.kotlin.generation.test.model.KotlinCompilationCommand
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.memberProperties
import kotlin.reflect.full.primaryConstructor
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.assertThat as compileAssertThat

@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class DummyExceptionITest {

@Test
fun `generate and create dummy exception`() {
val exceptionFile = buildRuntimeExceptionClass(ROOT_PACKAGE, "DummyException") {
messageTemplate("Dummy exception: expected: \$expected, actual: '\$actual'.")
addConstructorProperty("expected", Boolean::class)
addParameter("actual", String::class)
includeCause()
}.toFileSpec()


val result = KotlinCodeGenerationTest.compile(KotlinCompilationCommand(exceptionFile))

compileAssertThat(result).errorMessages().isEmpty()
compileAssertThat(result).hasExitCode(KotlinCompilation.ExitCode.OK)

val c: KClass<out Any> = result.loadClass(exceptionFile.className)

val cause = IllegalStateException("foo")
val e: RuntimeException = c.primaryConstructor!!.call(true, "false", cause) as RuntimeException

assertThat(e.localizedMessage).isEqualTo("Dummy exception: expected: true, actual: 'false'.")

// TODO try to get value via pure kotlin without falling back to java
val expectedProperty: KProperty1<out Any, *> = c.memberProperties.single { it.name == "expected" }
val field = c.java.getDeclaredField("expected").apply { isAccessible = true }

val expectedValue = field.get(e) as Boolean

assertThat(expectedValue).isTrue()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)

package io.toolisticon.kotlin.generation.itest

Expand All @@ -14,6 +13,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class HelloWorldExampleITest {

@Test
Expand All @@ -34,7 +34,6 @@ internal class HelloWorldExampleITest {
val file = buildFile(name) {
addType(type)
}
println(file.code)

assertThat(file.packageName).isEqualTo("foo.bar")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
package io.toolisticon.kotlin.generation.itest

import com.squareup.kotlinpoet.ClassName
Expand All @@ -8,6 +7,7 @@ import io.toolisticon.kotlin.generation.builder.KotlinFileSpecBuilder
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class KotlinFileSpecITest {

@Target(AnnotationTarget.FILE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)

package io.toolisticon.kotlin.generation.itest

Expand All @@ -17,6 +16,7 @@ import org.junit.jupiter.api.Test
import kotlin.reflect.KClass
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.assertThat as assertThatCompilation

@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class MyCustomAnnotationSpecITest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)

package io.toolisticon.kotlin.generation.itest.support

Expand All @@ -12,6 +11,7 @@ import io.toolisticon.kotlin.generation.test.model.KotlinCompilationResult
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class GeneratedAnnotationITest {

@Test
Expand Down
2 changes: 1 addition & 1 deletion _itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-parent</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<relativePath>../_build/parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion _itest/spi-itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-itest-root</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
</parent>

<groupId>io.toolisticon.kotlin.generation.itest</groupId>
Expand Down
3 changes: 1 addition & 2 deletions _itest/spi-itest/src/test/kotlin/SpiITest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)

package io.toolisticon.kotlin.generation.itest.spi

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
Expand All @@ -15,6 +13,7 @@ import org.assertj.core.api.Assertions.assertThatThrownBy
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class, ExperimentalCompilerApi::class)
internal class SpiITest {

@Test
Expand Down
2 changes: 1 addition & 1 deletion kotlin-code-generation-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-root</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
</parent>

<groupId>io.toolisticon.kotlin.generation</groupId>
Expand Down
2 changes: 1 addition & 1 deletion kotlin-code-generation-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-parent</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<relativePath>../_build/parent/pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class)

package io.toolisticon.kotlin.generation.test

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
Expand Down Expand Up @@ -34,6 +32,7 @@ import java.io.ByteArrayOutputStream
* ```
*/
@ExperimentalCompilerApi
@ExperimentalKotlinPoetApi
object KotlinCodeGenerationTest {

fun assertThat(actual: KotlinCompilationResult): KotlinCompilationAssert = KotlinCompilationAssert(actual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.toolisticon.kotlin.generation.test.model
import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import com.tschuchort.compiletesting.SourceFile
import io.toolisticon.kotlin.generation.spec.KotlinFileSpec
import io.toolisticon.kotlin.generation.spec.KotlinFileSpecs
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.sourceFile
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi

Expand All @@ -12,10 +13,10 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
@ExperimentalKotlinPoetApi
@ExperimentalCompilerApi
data class KotlinCompilationCommand(
val fileSpecs: List<KotlinFileSpec>
val fileSpecs: KotlinFileSpecs
) {

constructor(fileSpec: KotlinFileSpec) : this(listOf(fileSpec))
constructor(fileSpec: KotlinFileSpec) : this(KotlinFileSpecs(fileSpec))

operator fun plus(fileSpec: KotlinFileSpec) = copy(fileSpecs = fileSpecs + fileSpec)

Expand Down
2 changes: 1 addition & 1 deletion kotlin-code-generation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.toolisticon.kotlin.generation._</groupId>
<artifactId>kotlin-code-generation-parent</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<relativePath>../_build/parent/pom.xml</relativePath>
</parent>

Expand Down
Loading

0 comments on commit 94db706

Please sign in to comment.