1
+ package extensions.wu.seal
2
+
3
+ import com.google.gson.annotations.Expose
4
+ import extensions.Extension
5
+ import wu.seal.jsontokotlin.model.classscodestruct.Annotation
6
+ import wu.seal.jsontokotlin.model.classscodestruct.DataClass
7
+ import wu.seal.jsontokotlin.model.classscodestruct.KotlinClass
8
+ import wu.seal.jsontokotlin.ui.addSelectListener
9
+ import wu.seal.jsontokotlin.ui.jCheckBox
10
+ import wu.seal.jsontokotlin.ui.jHorizontalLinearLayout
11
+ import javax.swing.JPanel
12
+
13
+ object AddGsonExposeAnnotation : Extension() {
14
+
15
+ @Expose
16
+ val config_key = " wu.seal.add_gson_expose_annotation"
17
+
18
+ override fun createUI (): JPanel {
19
+ return jHorizontalLinearLayout {
20
+ jCheckBox(" Add Gson Expose Annotation" , config_key.booleanConfigValue) {
21
+ addSelectListener { setConfig(config_key, it.toString()) }
22
+ }
23
+ fillSpace()
24
+ }
25
+ }
26
+
27
+ override fun intercept (kotlinClass : KotlinClass ): KotlinClass {
28
+ return if (config_key.booleanConfigValue) {
29
+ if (kotlinClass is DataClass ) {
30
+ val newProperties = kotlinClass.properties.map {
31
+ val newAnnotations = it.annotations + Annotation .fromAnnotationString(" @Expose" )
32
+ it.copy(annotations = newAnnotations)
33
+ }
34
+ kotlinClass.copy(properties = newProperties)
35
+ } else kotlinClass
36
+ } else kotlinClass
37
+ }
38
+
39
+ override fun intercept (originClassImportDeclaration : String ): String {
40
+ return if (config_key.booleanConfigValue) {
41
+ originClassImportDeclaration.append(" import com.google.gson.annotations.Expose" )
42
+ } else originClassImportDeclaration
43
+ }
44
+ }
0 commit comments