Skip to content

Commit e54c37f

Browse files
committed
Merge branch 'release/0.0.10'
2 parents 5b57711 + 61dfa61 commit e54c37f

File tree

11 files changed

+50
-12
lines changed

11 files changed

+50
-12
lines changed

_build/parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-root</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
<relativePath>../../pom.xml</relativePath>
1010
</parent>
1111

_build/report-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-parent</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
<relativePath>../parent/pom.xml</relativePath>
1010
</parent>
1111

_itest/builder-itest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-itest-root</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
</parent>
1010

1111
<groupId>io.toolisticon.kotlin.generation.itest</groupId>

_itest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-parent</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
<relativePath>../_build/parent/pom.xml</relativePath>
1010
</parent>
1111

_itest/spi-itest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-itest-root</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
</parent>
1010

1111
<groupId>io.toolisticon.kotlin.generation.itest</groupId>

kotlin-code-generation-bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-root</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
</parent>
1010

1111
<groupId>io.toolisticon.kotlin.generation</groupId>

kotlin-code-generation-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-parent</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
<relativePath>../_build/parent/pom.xml</relativePath>
1010
</parent>
1111

kotlin-code-generation/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.toolisticon.kotlin.generation._</groupId>
77
<artifactId>kotlin-code-generation-parent</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
<relativePath>../_build/parent/pom.xml</relativePath>
1010
</parent>
1111

kotlin-code-generation/src/main/kotlin/spi/processor/KotlinFileSpecProcessor.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ abstract class KotlinFileSpecProcessor<CONTEXT : KotlinCodeGenerationContext<CON
2929

3030
/**
3131
* Used to implement a [io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationProcessor]
32-
* that will visit/modify a [KotlinFileSpecBuilder] but do not work on a loop variable.
32+
* that will visit/modify a [KotlinFileSpecBuilder] but do not work on a loop variable/input type.
3333
*/
3434
@ExperimentalKotlinPoetApi
3535
abstract class KotlinFileSpecEmptyInputProcessor<CONTEXT : KotlinCodeGenerationContext<CONTEXT>>(
3636
contextType: KClass<CONTEXT>,
3737
order: Int = KotlinCodeGenerationSpi.DEFAULT_ORDER
38-
) : KotlinCodeGenerationProcessorBase<CONTEXT, EmptyInput, KotlinFileSpecBuilder>(
38+
) : KotlinFileSpecProcessor<CONTEXT, EmptyInput>(
3939
contextType = contextType,
4040
inputType = EmptyInput::class,
41-
builderType = KotlinFileSpecBuilder::class,
4241
order = order
4342
) {
4443
/**
@@ -54,4 +53,10 @@ abstract class KotlinFileSpecEmptyInputProcessor<CONTEXT : KotlinCodeGenerationC
5453
fun test(context: CONTEXT): Boolean = context::class.isSubclassOf(contextType)
5554

5655
override fun test(context: CONTEXT, input: Any): Boolean = super.test(context, input) && test(context)
56+
57+
/**
58+
* Execute only based on context.
59+
*/
60+
fun execute(context: CONTEXT, builder: KotlinFileSpecBuilder): KotlinFileSpecBuilder = super.execute(context, EmptyInput, builder)
61+
5762
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.toolisticon.kotlin.generation.spi.processor
2+
3+
import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
4+
import io.toolisticon.kotlin.generation.KotlinCodeGeneration
5+
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.builder.fileBuilder
6+
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.className
7+
import io.toolisticon.kotlin.generation._test.MutableSpiRegistry
8+
import io.toolisticon.kotlin.generation._test.TestContext
9+
import io.toolisticon.kotlin.generation.builder.KotlinFileSpecBuilder
10+
import org.assertj.core.api.Assertions.assertThat
11+
import org.junit.jupiter.api.Test
12+
13+
@OptIn(ExperimentalKotlinPoetApi::class)
14+
internal class KotlinFileSpecEmptyInputProcessorTest {
15+
16+
@Test
17+
fun `add doc to file via processor`() {
18+
val file = fileBuilder("foo", "bar")
19+
20+
class AddDocProcessor : KotlinFileSpecEmptyInputProcessor<TestContext>(TestContext::class) {
21+
override fun invoke(context: TestContext, builder: KotlinFileSpecBuilder): KotlinFileSpecBuilder {
22+
return builder.addFileComment(KotlinCodeGeneration.format.FORMAT_STRING, "Hello World")
23+
}
24+
}
25+
26+
AddDocProcessor().execute(TestContext(className("foo", "bar"), MutableSpiRegistry()), file)
27+
28+
assertThat(file.spec().code).isEqualToIgnoringWhitespace("""
29+
// "Hello World"
30+
package foo
31+
""".trimIndent())
32+
}
33+
}

0 commit comments

Comments
 (0)