-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quine.kt
70 lines (66 loc) · 2.55 KB
/
Quine.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.nightlynexus.kotlinpoetquine
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.KModifier.CONST
import com.squareup.kotlinpoet.KModifier.PRIVATE
import com.squareup.kotlinpoet.MemberName
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.asClassName
import kotlin.String
private const val PACKAGE_NAME: String = "com.nightlynexus.kotlinpoetquine"
private const val FILE_NAME: String = "Quine"
fun main() {
val string = "%1S"
val body = """
|val string = %1S
|val body = %2S
|%3T.builder(PACKAGE_NAME, FILE_NAME)
| .addProperty(%4T.builder("PACKAGE_NAME", %5T::class, %6M, %7M)
| .initializer(string, PACKAGE_NAME).build())
| .addProperty(PropertySpec.builder("FILE_NAME", %5T::class, PRIVATE, CONST)
| .initializer(string, FILE_NAME).build())
| .addFunction(%8T.builder("main")
| .addCode(
| body,
| string,
| body,
| %3T::class,
| %4T::class,
| %5T::class,
| %10T(%11T::class.%9M(), "PRIVATE"),
| %10T(%11T::class.%9M(), "CONST"),
| %8T::class,
| %10T("com.squareup.kotlinpoet", "asClassName"),
| %10T::class,
| %11T::class,
| %12T::class
| )
| .build())
| .build().writeTo(System.out)
|""".trimMargin()
FileSpec.builder(PACKAGE_NAME, FILE_NAME)
.addProperty(PropertySpec.builder("PACKAGE_NAME", String::class, PRIVATE, CONST)
.initializer(string, PACKAGE_NAME).build())
.addProperty(PropertySpec.builder("FILE_NAME", String::class, PRIVATE, CONST)
.initializer(string, FILE_NAME).build())
.addFunction(FunSpec.builder("main")
.addCode(
body,
string,
body,
FileSpec::class,
PropertySpec::class,
String::class,
MemberName(KModifier::class.asClassName(), "PRIVATE"),
MemberName(KModifier::class.asClassName(), "CONST"),
FunSpec::class,
MemberName("com.squareup.kotlinpoet", "asClassName"),
MemberName::class,
KModifier::class,
ParameterizedTypeName.Companion::class
)
.build())
.build().writeTo(System.out)
}