1
+
1
2
package love.forte.plugin.suspendtrans.gradle
2
3
3
4
import love.forte.plugin.suspendtrans.configuration.*
@@ -6,7 +7,6 @@ import love.forte.plugin.suspendtrans.configuration.SuspendTransformConfiguratio
6
7
import love.forte.plugin.suspendtrans.configuration.SuspendTransformConfigurations.jvmBlockingTransformer
7
8
import org.gradle.api.Action
8
9
import org.gradle.api.DomainObjectSet
9
- import org.gradle.api.Named
10
10
import org.gradle.api.model.ObjectFactory
11
11
import org.gradle.api.provider.ListProperty
12
12
import org.gradle.api.provider.Property
@@ -26,51 +26,43 @@ annotation class SuspendTransformPluginExtensionSpecDslMarker
26
26
@SuspendTransformPluginExtensionSpecDslMarker
27
27
interface SuspendTransformPluginExtensionSpec
28
28
29
- interface NamedTransformerSpecListContainer : Named {
30
- val platform: Provider <TargetPlatform >
31
- val transformers: ListProperty <TransformerSpec >
29
+ @SuspendTransformPluginExtensionSpecDslMarker
30
+ interface SuspendTransformPluginExtensionClassInfoSpec : SuspendTransformPluginExtensionSpec {
31
+ fun classInfo (action : Action <in ClassInfoSpec >)
32
+ fun classInfo (action : ClassInfoSpec .() -> Unit )
32
33
}
33
34
34
- internal interface NamedTransformerSpecListContainerInternal : NamedTransformerSpecListContainer {
35
- override val platform: Property <TargetPlatform >
36
- }
35
+ // TODO
36
+ // interface SuspendTransformPluginExtensionSpecFactory {
37
+ // fun createClassInfo(): ClassInfoSpec
38
+ // fun createMarkAnnotation(): MarkAnnotationSpec
39
+ // fun createFunctionInfo(): FunctionInfoSpec
40
+ // fun createIncludeAnnotation(): IncludeAnnotationSpec
41
+ // fun createCopyAnnotationExclude(): CopyAnnotationExcludeSpec
42
+ // fun createRuntimeDependency(): RuntimeDependencySpec
43
+ // fun createAnnotationDependency(): AnnotationDependencySpec
44
+ // fun createTransformFunctionInfo(): TransformFunctionInfoSpec
45
+ // fun createTransformReturnType(): TransformReturnTypeSpec
46
+ // fun createTransformer(): TransformerSpec
47
+ // }
48
+ //
49
+ // interface SuspendTransformPluginExtensionSpecFactoryAware {
50
+ // val factory: SuspendTransformPluginExtensionSpecFactory
51
+ // }
37
52
38
53
/* *
39
54
* @since 0.12.0
40
55
*/
56
+ @Suppress(" unused" )
41
57
abstract class TransformersContainer
42
58
@Inject constructor (
43
59
private val objects: ObjectFactory
44
60
) : SuspendTransformPluginExtensionSpec {
45
- internal val _containers : MutableMap <TargetPlatform , ListProperty <TransformerSpec >> =
61
+ internal val containers : MutableMap <TargetPlatform , ListProperty <TransformerSpec >> =
46
62
mutableMapOf ()
47
63
48
- // private val _containers: NamedDomainObjectContainer<NamedTransformerSpecListContainerInternal> =
49
- // objects.domainObjectContainer(NamedTransformerSpecListContainerInternal::class.java) { name ->
50
- // val targetPlatform = try {
51
- // TargetPlatform.valueOf(name)
52
- // } catch (e: IllegalArgumentException) {
53
- // throw IllegalArgumentException(
54
- // "The name '$name' is not a valid TargetPlatform name. " +
55
- // "Valid names: ${TargetPlatform.entries.joinToString { it.name }}",
56
- // e
57
- // )
58
- // }
59
- //
60
- // objects.newInstance(
61
- // NamedTransformerSpecListContainerInternal::class.java,
62
- // name
63
- // ).apply {
64
- // platform.set(targetPlatform)
65
- // }
66
- // }
67
-
68
- // @ExperimentalTransformersContainerApi
69
- // val containers: NamedDomainObjectContainer<out NamedTransformerSpecListContainer>
70
- // get() = _containers
71
-
72
64
private fun getTransformersInternal (platform : TargetPlatform ): ListProperty <TransformerSpec > {
73
- return _containers .computeIfAbsent(platform) { objects.listProperty(TransformerSpec ::class .java) }
65
+ return containers .computeIfAbsent(platform) { objects.listProperty(TransformerSpec ::class .java) }
74
66
}
75
67
76
68
/* *
@@ -217,6 +209,7 @@ abstract class TransformersContainer
217
209
/* *
218
210
* @since 0.12.0
219
211
*/
212
+ @Suppress(" unused" )
220
213
abstract class SuspendTransformPluginExtension
221
214
@Inject constructor (objects: ObjectFactory ) : SuspendTransformPluginExtensionSpec {
222
215
/* *
@@ -279,25 +272,6 @@ abstract class SuspendTransformPluginExtension
279
272
}
280
273
}
281
274
282
- @OptIn(InternalSuspendTransformConfigurationApi ::class )
283
- internal fun SuspendTransformPluginExtension.toConfiguration (): SuspendTransformConfiguration {
284
- return SuspendTransformConfiguration (
285
- // 此处 Map 可能为 空,但是 List 不会有空的。
286
- // 后续在使用的时候只需要判断一下 transformers 本身是不是空即可。
287
- transformers = buildMap {
288
- transformers._containers .forEach { targetPlatform, transformerListProperty ->
289
- val list = transformerListProperty
290
- .map { valueList -> valueList.map { it.toTransformer() } }
291
- .getOrElse(emptyList())
292
-
293
- if (list.isNotEmpty()) {
294
- put(targetPlatform, list)
295
- }
296
- }
297
- },
298
- )
299
- }
300
-
301
275
internal data class TransformerEntry (
302
276
val targetPlatform : TargetPlatform ,
303
277
val transformers : List <Transformer >
@@ -306,7 +280,7 @@ internal data class TransformerEntry(
306
280
@OptIn(InternalSuspendTransformConfigurationApi ::class )
307
281
internal fun SuspendTransformPluginExtension.toConfigurationProvider (objects : ObjectFactory ): Provider <SuspendTransformConfiguration > {
308
282
val combines = objects.listProperty(TransformerEntry ::class .java)
309
- for ((targetPlatform, transformerListProperty) in transformers._containers ) {
283
+ for ((targetPlatform, transformerListProperty) in transformers.containers ) {
310
284
combines.addAll(
311
285
transformerListProperty.map { list ->
312
286
if (list.isEmpty()) {
@@ -399,6 +373,7 @@ internal fun SuspendTransformPluginExtension.defaults(
399
373
/* *
400
374
* @since 0.12.0
401
375
*/
376
+ @Suppress(" unused" )
402
377
abstract class TransformerSpec
403
378
@Inject constructor (private val objects: ObjectFactory ) : SuspendTransformPluginExtensionSpec {
404
379
/* *
@@ -438,6 +413,7 @@ abstract class TransformerSpec
438
413
* @Api4J fun fooXxx(): CompletableFuture<Foo> = transform(block = { foo() }, scope = this)
439
414
* }
440
415
*/
416
+ @Suppress(" KDocUnresolvedReference" )
441
417
abstract val transformFunctionInfo: Property <FunctionInfoSpec >
442
418
443
419
fun transformFunctionInfo (action : Action <in FunctionInfoSpec >) {
@@ -634,18 +610,21 @@ abstract class TransformerSpec
634
610
/* *
635
611
* @since 0.12.0
636
612
*/
613
+ @Suppress(" unused" )
637
614
abstract class MarkAnnotationSpec
638
- @Inject constructor (private val objects: ObjectFactory ) : SuspendTransformPluginExtensionSpec {
615
+ @Inject constructor (private val objects: ObjectFactory ) :
616
+ SuspendTransformPluginExtensionSpec ,
617
+ SuspendTransformPluginExtensionClassInfoSpec {
639
618
/* *
640
619
* The mark annotation's class info.
641
620
*/
642
621
abstract val classInfo: Property <ClassInfoSpec >
643
622
644
- fun classInfo (action : Action <in ClassInfoSpec >) {
623
+ override fun classInfo (action : Action <in ClassInfoSpec >) {
645
624
classInfo.set(classInfo.getOrElse(objects.newInstance<ClassInfoSpec >()).also (action::execute))
646
625
}
647
626
648
- fun classInfo (action : ClassInfoSpec .() -> Unit ) {
627
+ override fun classInfo (action : ClassInfoSpec .() -> Unit ) {
649
628
classInfo.set(classInfo.getOrElse(objects.newInstance<ClassInfoSpec >()).also (action))
650
629
}
651
630
@@ -743,15 +722,18 @@ interface FunctionInfoSpec : SuspendTransformPluginExtensionSpec {
743
722
/* *
744
723
* @since 0.12.0
745
724
*/
725
+ @Suppress(" unused" )
746
726
abstract class IncludeAnnotationSpec
747
- @Inject constructor (private val objects: ObjectFactory ) : SuspendTransformPluginExtensionSpec {
727
+ @Inject constructor (private val objects: ObjectFactory ) :
728
+ SuspendTransformPluginExtensionSpec ,
729
+ SuspendTransformPluginExtensionClassInfoSpec {
748
730
abstract val classInfo: Property <ClassInfoSpec >
749
731
750
- fun classInfo (action : Action <in ClassInfoSpec >) {
732
+ override fun classInfo (action : Action <in ClassInfoSpec >) {
751
733
classInfo.set(classInfo.getOrElse(objects.newInstance<ClassInfoSpec >()).also (action::execute))
752
734
}
753
735
754
- fun classInfo (action : ClassInfoSpec .() -> Unit ) {
736
+ override fun classInfo (action : ClassInfoSpec .() -> Unit ) {
755
737
classInfo.set(classInfo.getOrElse(objects.newInstance<ClassInfoSpec >()).also (action))
756
738
}
757
739
0 commit comments