|
1 | 1 | package love.forte.plugin.suspendtrans
|
2 | 2 |
|
| 3 | +import kotlinx.serialization.json.Json |
3 | 4 | import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
|
4 | 5 | import kotlin.reflect.KMutableProperty
|
5 | 6 |
|
6 |
| -private typealias ExcludeAnnotation = SuspendTransformConfiguration.ExcludeAnnotation |
7 |
| - |
8 |
| -private const val REPEAT_MARK = "\$&+" |
9 |
| - |
10 |
| -private fun includeAnnotationEncode(value: List<SuspendTransformConfiguration.IncludeAnnotation>): String { |
11 |
| - return value.joinToString(",") { if (it.repeatable) "${it.name}$REPEAT_MARK" else it.name } |
12 |
| -} |
13 |
| - |
14 |
| -private fun includeAnnotationDecode(value: String): List<SuspendTransformConfiguration.IncludeAnnotation> { |
15 |
| - return value.split(",").map { |
16 |
| - val annotationName = it.substringBeforeLast(REPEAT_MARK) |
17 |
| - val repeat = annotationName != it |
18 |
| - SuspendTransformConfiguration.IncludeAnnotation(annotationName, repeat) |
19 |
| - } |
| 7 | +private val defaultJson = Json { |
| 8 | + isLenient = true |
| 9 | + ignoreUnknownKeys = true |
| 10 | + encodeDefaults = true |
20 | 11 | }
|
21 | 12 |
|
22 | 13 | object CliOptions {
|
23 | 14 |
|
24 | 15 | const val CONFIGURATION = "configuration"
|
25 |
| - val ENABLED = option("enabled") { |
26 |
| - inc { enabled = it.toBoolean() } |
27 |
| - out { enabled.toString() } |
28 |
| - } |
29 |
| - |
30 |
| - object Jvm { |
31 |
| - |
32 |
| - val ORIGIN_FUNCTION_INCLUDE_ANNOTATIONS = option("jvm.originFunctionIncludeAnnotations") { |
33 |
| - inc { jvm.originFunctionIncludeAnnotations = includeAnnotationDecode(it) } |
34 |
| - // TODO |
35 |
| - out { includeAnnotationEncode(jvm.originFunctionIncludeAnnotations ?: emptyList()) } |
36 |
| - } |
37 |
| - |
38 |
| - |
39 |
| - //region blocking |
40 |
| - val JVM_BLOCKING_FUNCTION_NAME = option("jvm.jvmBlockingFunctionName") { |
41 |
| - // TODO |
42 |
| - withNullableProp { jvm::jvmBlockingFunctionName } |
43 |
| - } |
44 |
| - |
45 |
| - //region blocking mark |
46 |
| - const val JVM_BLOCKING_MARK_ANNOTATION = "jvm.jvmBlockingMarkAnnotation" |
47 |
| - |
48 |
| - val JVM_BLOCKING_MARK_ANNOTATION_ANNOTATION_NAME = |
49 |
| - JVM_BLOCKING_MARK_ANNOTATION.option("annotationName") { |
50 |
| - withProp { jvm.jvmBlockingMarkAnnotation::annotationName } |
51 |
| - } |
52 |
| - val JVM_BLOCKING_MARK_ANNOTATION_BASE_NAME_PROPERTY = |
53 |
| - JVM_BLOCKING_MARK_ANNOTATION.option("baseNameProperty") { |
54 |
| - withProp { jvm.jvmBlockingMarkAnnotation::baseNameProperty } |
55 |
| - } |
56 |
| - val JVM_BLOCKING_MARK_ANNOTATION_SUFFIX_PROPERTY = |
57 |
| - JVM_BLOCKING_MARK_ANNOTATION.option("suffixProperty") { |
58 |
| - withProp { jvm.jvmBlockingMarkAnnotation::suffixProperty } |
59 |
| - } |
60 |
| - val JVM_BLOCKING_MARK_ANNOTATION_AS_PROPERTY_PROPERTY = |
61 |
| - JVM_BLOCKING_MARK_ANNOTATION.option("asPropertyProperty") { |
62 |
| - withProp { jvm.jvmBlockingMarkAnnotation::asPropertyProperty } |
63 |
| - } |
64 |
| - //endregion |
65 |
| - |
66 |
| - val COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION = |
67 |
| - option("jvm.copyAnnotationsToSyntheticBlockingFunction") { |
68 |
| - inc { jvm.copyAnnotationsToSyntheticBlockingFunction = it.toBoolean() } |
69 |
| - out { jvm.copyAnnotationsToSyntheticBlockingFunction.toString() } |
70 |
| - } |
71 |
| - const val COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION_EXCLUDES = |
72 |
| - "jvm.copyAnnotationsToSyntheticBlockingFunctionExcludes" |
73 |
| - |
74 |
| - val COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION_EXCLUDES_NAME = |
75 |
| - COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION_EXCLUDES.option("name") { |
76 |
| - inc { jvm.copyAnnotationsToSyntheticBlockingFunctionExcludes = it.split(",").map(::ExcludeAnnotation) } |
77 |
| - out { jvm.copyAnnotationsToSyntheticBlockingFunctionExcludes.joinToString(",") { it.name } } |
78 |
| - |
79 |
| - } |
80 |
| - |
81 |
| - val SYNTHETIC_BLOCKING_FUNCTION_INCLUDE_ANNOTATIONS = |
82 |
| - option("jvm.syntheticBlockingFunctionIncludeAnnotations") { |
83 |
| - inc { jvm.syntheticBlockingFunctionIncludeAnnotations = includeAnnotationDecode(it) } |
84 |
| - // TODO |
85 |
| - out { includeAnnotationEncode(jvm.syntheticBlockingFunctionIncludeAnnotations ?: emptyList()) } |
86 |
| - } |
87 |
| - |
88 |
| - //endregion |
89 |
| - |
90 |
| - |
91 |
| - //region async |
92 |
| - val JVM_ASYNC_FUNCTION_NAME = option("jvm.jvmAsyncFunctionName") { |
93 |
| - // TODO |
94 |
| - withNullableProp { jvm::jvmAsyncFunctionName } |
95 |
| - } |
96 |
| - |
97 |
| - //region async mark |
98 |
| - const val JVM_ASYNC_MARK_ANNOTATION = "jvm.jvmAsyncMarkAnnotation" |
99 |
| - |
100 |
| - val JVM_ASYNC_MARK_ANNOTATION_ANNOTATION_NAME = |
101 |
| - JVM_ASYNC_MARK_ANNOTATION.option("annotationName") { |
102 |
| - withProp { jvm.jvmAsyncMarkAnnotation::annotationName } |
103 |
| - } |
104 |
| - val JVM_ASYNC_MARK_ANNOTATION_BASE_NAME_PROPERTY = |
105 |
| - JVM_ASYNC_MARK_ANNOTATION.option("baseNameProperty") { |
106 |
| - withProp { jvm.jvmAsyncMarkAnnotation::baseNameProperty } |
107 |
| - } |
108 |
| - val JVM_ASYNC_MARK_ANNOTATION_SUFFIX_PROPERTY = |
109 |
| - JVM_ASYNC_MARK_ANNOTATION.option("suffixProperty") { |
110 |
| - withProp { jvm.jvmAsyncMarkAnnotation::suffixProperty } |
111 |
| - } |
112 |
| - val JVM_ASYNC_MARK_ANNOTATION_AS_PROPERTY_PROPERTY = |
113 |
| - JVM_ASYNC_MARK_ANNOTATION.option("asPropertyProperty") { |
114 |
| - withProp { jvm.jvmAsyncMarkAnnotation::asPropertyProperty } |
115 |
| - } |
116 |
| - //endregion |
117 |
| - |
118 |
| - |
119 |
| - val SYNTHETIC_ASYNC_FUNCTION_INCLUDE_ANNOTATIONS = option("jvm.syntheticAsyncFunctionIncludeAnnotations") { |
120 |
| - inc { jvm.syntheticAsyncFunctionIncludeAnnotations = includeAnnotationDecode(it) } |
121 |
| - // TODO |
122 |
| - out { includeAnnotationEncode(jvm.syntheticAsyncFunctionIncludeAnnotations ?: emptyList()) } |
123 |
| - } |
124 |
| - |
125 |
| - val COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION = |
126 |
| - option("jvm.copyAnnotationsToSyntheticAsyncFunction") { |
127 |
| - inc { jvm.copyAnnotationsToSyntheticAsyncFunction = it.toBoolean() } |
128 |
| - out { jvm.copyAnnotationsToSyntheticAsyncFunction.toString() } |
129 |
| - } |
130 |
| - const val COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION_EXCLUDES = |
131 |
| - "jvm.copyAnnotationsToSyntheticAsyncFunctionExcludes" |
132 |
| - |
133 |
| - val COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION_EXCLUDES_NAME = |
134 |
| - COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION_EXCLUDES.option("name") { |
135 |
| - inc { jvm.copyAnnotationsToSyntheticAsyncFunctionExcludes = it.split(",").map(::ExcludeAnnotation) } |
136 |
| - out { jvm.copyAnnotationsToSyntheticAsyncFunctionExcludes.joinToString(",") { it.name } } |
137 |
| - } |
138 |
| - |
139 |
| - //endregion |
140 |
| - |
141 | 16 |
|
| 17 | + private val RAW_CONFIGURATION = option( |
| 18 | + name = "raw_configuration", |
| 19 | + valueDescription = "Serialize the results in JSON format for configuration information", |
| 20 | + description = "Serialize the results in JSON format for configuration information", |
| 21 | + ) { |
| 22 | + inc { defaultJson.decodeFromString(SuspendTransformConfiguration.serializer(), it) } |
| 23 | + out { defaultJson.encodeToString(SuspendTransformConfiguration.serializer(), this) } |
142 | 24 | }
|
143 | 25 |
|
144 |
| - object Js |
| 26 | + private val ENABLED = option("enabled") { |
| 27 | + inc { enabled = it.toBoolean() } |
| 28 | + out { enabled.toString() } |
| 29 | + } |
145 | 30 |
|
146 | 31 |
|
147 | 32 | val allOptions: List<ICliOption> = listOf(
|
148 | 33 | ENABLED,
|
149 |
| - Jvm.ORIGIN_FUNCTION_INCLUDE_ANNOTATIONS, |
150 |
| - Jvm.JVM_BLOCKING_FUNCTION_NAME, |
151 |
| - Jvm.JVM_BLOCKING_MARK_ANNOTATION_ANNOTATION_NAME, |
152 |
| - Jvm.JVM_BLOCKING_MARK_ANNOTATION_BASE_NAME_PROPERTY, |
153 |
| - Jvm.JVM_BLOCKING_MARK_ANNOTATION_SUFFIX_PROPERTY, |
154 |
| - Jvm.JVM_BLOCKING_MARK_ANNOTATION_AS_PROPERTY_PROPERTY, |
155 |
| - Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION, |
156 |
| - Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION_EXCLUDES_NAME, |
157 |
| - Jvm.SYNTHETIC_BLOCKING_FUNCTION_INCLUDE_ANNOTATIONS, |
158 |
| - Jvm.JVM_ASYNC_FUNCTION_NAME, |
159 |
| - Jvm.JVM_ASYNC_MARK_ANNOTATION_ANNOTATION_NAME, |
160 |
| - Jvm.JVM_ASYNC_MARK_ANNOTATION_BASE_NAME_PROPERTY, |
161 |
| - Jvm.JVM_ASYNC_MARK_ANNOTATION_SUFFIX_PROPERTY, |
162 |
| - Jvm.JVM_ASYNC_MARK_ANNOTATION_AS_PROPERTY_PROPERTY, |
163 |
| - Jvm.SYNTHETIC_ASYNC_FUNCTION_INCLUDE_ANNOTATIONS, |
164 |
| - Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION, |
165 |
| - Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION_EXCLUDES_NAME, |
| 34 | + RAW_CONFIGURATION |
166 | 35 | )
|
167 | 36 | val allOptionsMap = allOptions.associateBy { it.oName }
|
168 | 37 |
|
|
0 commit comments