-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3235a87
commit cd16032
Showing
36 changed files
with
241 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
object KotlinCodeGenerationITest { | ||
// empty | ||
const val ROOT_PACKAGE = "io.toolisticon.kotlin.generation.itest.created" | ||
} |
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 io.toolisticon.kotlin.generation.itest | ||
|
||
import com.squareup.kotlinpoet.ClassName | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildAnnotationClass | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFile | ||
import io.toolisticon.kotlin.generation.itest.KotlinCodeGenerationITest.ROOT_PACKAGE | ||
|
||
object MyCustomAnnotationSpec { | ||
val name = ClassName(ROOT_PACKAGE, "MyCustomAnnotation") | ||
|
||
val spec = buildAnnotationClass(name) { | ||
mustBeDocumented() | ||
retention(AnnotationRetention.RUNTIME) | ||
target(AnnotationTarget.CLASS) | ||
addConstructorProperty("value", String::class) | ||
} | ||
|
||
val file = buildFile(name) { | ||
addType(spec) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
import com.squareup.kotlinpoet.ClassName | ||
import com.tschuchort.compiletesting.KotlinCompilation | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildAnnotation | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFile | ||
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest | ||
import io.toolisticon.kotlin.generation.test.model.KotlinCompilationCommand | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import kotlin.reflect.KClass | ||
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.assertThat as assertThatCompilation | ||
|
||
|
||
internal class MyCustomAnnotationSpecTest { | ||
|
||
@Test | ||
fun `generate class with custom annotation`() { | ||
val name = ClassName(KotlinCodeGenerationITest.ROOT_PACKAGE, "MyClass") | ||
|
||
val customAnnotation = buildAnnotation(MyCustomAnnotationSpec.name) { | ||
addStringMember("value", "hello") | ||
} | ||
|
||
val myClass = KotlinCodeGeneration.buildClass(name) { | ||
addAnnotation(customAnnotation) | ||
} | ||
|
||
val file = buildFile(name) { | ||
addType(myClass) | ||
} | ||
|
||
println(myClass.code) | ||
|
||
val result = KotlinCodeGenerationTest.compile(KotlinCompilationCommand(MyCustomAnnotationSpec.file).plus(file)) | ||
|
||
assertThatCompilation(result).hasExitCode(KotlinCompilation.ExitCode.OK); | ||
|
||
val klass: KClass<out Any> = result.loadClass(name) | ||
assertThat(klass.annotations).hasSize(1) | ||
val annotation: Annotation = klass.annotations[0] | ||
|
||
//assertThat(annotation::class.) | ||
} | ||
} |
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
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
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
12 changes: 9 additions & 3 deletions
12
kotlin-code-generation-test/src/main/kotlin/model/KotlinCompilationCommand.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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
package io.toolisticon.kotlin.generation.test.model | ||
|
||
import com.tschuchort.compiletesting.SourceFile | ||
import io.toolisticon.kotlin.generation._BAK.KotlinFileSpec | ||
import io.toolisticon.kotlin.generation.spec.KotlinFileSpec | ||
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.sourceFile | ||
|
||
data class KotlinCompilationCommand( | ||
val fileSpec: KotlinFileSpec | ||
val fileSpecs: List<KotlinFileSpec> | ||
) { | ||
|
||
val sourceFile = SourceFile.kotlin(name = fileSpec.fileName, contents = fileSpec.code) | ||
constructor(fileSpec: KotlinFileSpec) : this(listOf(fileSpec)) | ||
|
||
operator fun plus(fileSpec: KotlinFileSpec) = copy(fileSpecs = fileSpecs + fileSpec) | ||
|
||
|
||
val sourceFiles: List<SourceFile> by lazy { fileSpecs.map { it.sourceFile() } } | ||
} |
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
Oops, something went wrong.