Skip to content

Commit

Permalink
chore: move optin to class level
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed Sep 10, 2024
1 parent 17bb36b commit 1d66083
Show file tree
Hide file tree
Showing 33 changed files with 58 additions and 42 deletions.
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
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 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
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
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
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class)

package io.toolisticon.kotlin.generation

Expand All @@ -18,6 +17,7 @@ import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
internal class KotlinCodeGenerationTest {

@Nested
Expand Down
2 changes: 1 addition & 1 deletion kotlin-code-generation/src/test/kotlin/TestFixtures.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class)

package io.toolisticon.kotlin.generation

Expand All @@ -21,6 +20,7 @@ import java.time.Instant
import java.util.*
import kotlin.reflect.KClass

@OptIn(ExperimentalKotlinPoetApi::class)
object TestFixtures {

// a fixed instant to be used in test with
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._test

Expand All @@ -10,6 +9,7 @@ import io.toolisticon.kotlin.generation.spi.processor.KotlinCodeGenerationProces
import io.toolisticon.kotlin.generation.spi.strategy.KotlinCodeGenerationStrategyList
import kotlin.reflect.KClass

@OptIn(ExperimentalKotlinPoetApi::class)
class MutableSpiRegistry(
val strategyList: MutableList<UnboundKotlinCodeGenerationStrategy> = mutableListOf(),
val processorList: MutableList<UnboundKotlinCodeGenerationProcessor> = mutableListOf(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@file:OptIn(ExperimentalKotlinPoetApi::class)

package io.toolisticon.kotlin.generation._test

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContext

@OptIn(ExperimentalKotlinPoetApi::class)
class TestContext(
val rootClassName: ClassName,
override val registry: MutableSpiRegistry
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._test

Expand All @@ -8,6 +7,7 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFile
import io.toolisticon.kotlin.generation.spec.KotlinFileSpec
import io.toolisticon.kotlin.generation.spi.strategy.KotlinFileSpecStrategy

@OptIn(ExperimentalKotlinPoetApi::class)
class TestDeclarationFileStrategy : KotlinFileSpecStrategy<TestContext, TestDeclaration>(
contextType = TestContext::class, TestDeclaration::class
) {
Expand Down
2 changes: 1 addition & 1 deletion kotlin-code-generation/src/test/kotlin/poet/KDocTest.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(ExperimentalKotlinPoetApi::class)

package io.toolisticon.kotlin.generation.poet

Expand All @@ -7,6 +6,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test


@OptIn(ExperimentalKotlinPoetApi::class)
internal class KDocTest {

@Test
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.poet

Expand All @@ -10,6 +9,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test


@OptIn(ExperimentalKotlinPoetApi::class)
internal class TypeSpecBuilderTest {

@Test
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.spec

Expand All @@ -8,6 +7,7 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildAnnotationClas
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
internal class KotlinAnnotationClassTest {

@Test
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.spec

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
Expand All @@ -11,6 +9,7 @@ import org.junit.jupiter.api.Test
import kotlin.reflect.KClass


@OptIn(ExperimentalKotlinPoetApi::class)
internal class KotlinAnnotationTest {

annotation class Foo(
Expand All @@ -29,13 +28,13 @@ internal class KotlinAnnotationTest {
assertThat(annotation.code).isEqualTo("""@io.toolisticon.kotlin.generation.TestFixtures.MyAnnotation(name = "foo", type = kotlin.String::class)""");
}


@Test
fun `create Foo annotation`() {
fun `create Foo annotation - multiline`() {
val spec = KotlinAnnotationSpecBuilder.builder(Foo::class)
.addMember("bar = %S", "hello world")
.addStringMember("x", "foo")
.addKClassMember("type", Long::class)
.multiLine()
.build()

assertThat(spec.code).isEqualTo("""@io.toolisticon.kotlin.generation.spec.KotlinAnnotationTest.Foo(bar = "hello world", x = "foo", type = kotlin.Long::class)""")
Expand All @@ -52,6 +51,28 @@ internal class KotlinAnnotationTest {
)
}

@Test
fun `create Foo annotation - singleline`() {
val spec = KotlinAnnotationSpecBuilder.builder(Foo::class)
.addMember("bar = %S", "hello world")
.addStringMember("x", "foo")
.addKClassMember("type", Long::class)
.build()

assertThat(spec.code).isEqualTo("""@io.toolisticon.kotlin.generation.spec.KotlinAnnotationTest.Foo(bar = "hello world", x = "foo", type = kotlin.Long::class)""")
assertThat(spec.members).hasSize(1)

assertThat(spec).hasToString(
"KotlinAnnotationSpec(" +
"typeName=io.toolisticon.kotlin.generation.spec.KotlinAnnotationTest.Foo, " +
"members=[" +
"bar = \"hello world\", " +
"x = \"foo\", " +
"type = kotlin.Long::class]" +
")"
)
}

@Test
fun `use toBuilder to add members`() {
var spec = KotlinAnnotationSpecBuilder.builder(Foo::class)
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.spec

Expand All @@ -8,6 +7,7 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFun
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
internal class KotlinAnonymousClassTest {
@Test
fun build() {
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.spec

Expand All @@ -10,6 +9,7 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.format.FORMAT_STRIN
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
internal class KotlinCompanionObjectTest {

@Test
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.spec

Expand All @@ -8,6 +7,7 @@ import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinConstructorPropertyTest {
@Test
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.spec

import com.squareup.kotlinpoet.ClassName
Expand All @@ -11,6 +9,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test


@OptIn(ExperimentalKotlinPoetApi::class)
internal class KotlinDataClassTest {

@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinEnumClassTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinFileTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinFunTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinInterfaceTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinObjectTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinParameterTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinPropertyTest {
@Test
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.spec

Expand All @@ -7,6 +6,7 @@ import io.toolisticon.kotlin.generation.TestFixtures.notDeprecated
import org.junit.jupiter.api.Assumptions.assumeFalse
import org.junit.jupiter.api.Test

@OptIn(ExperimentalKotlinPoetApi::class)
@Deprecated("not implemented yet")
internal class KotlinTypeAliasTest {
@Test
Expand Down
Loading

0 comments on commit 1d66083

Please sign in to comment.