Skip to content

Commit 35a8e41

Browse files
authored
Merge pull request #196 from wuseal/3.3.0
3.3.0 Released then merge it into master branch
2 parents d234392 + ad78b31 commit 35a8e41

File tree

69 files changed

+1112
-1108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1112
-1108
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,22 @@ Open the `build.gradle` in IntelliJ, open "Gradle" tool window, expand the proje
183183
* Share to others to help more people have a better develope expierience :heart:
184184

185185
### Authors
186-
* This project exists thanks to all the people who contribute.
186+
This project exists thanks to all the people who contribute.
187187

188188
<a href="https://github.com/wuseal/JsonToKotlinClass/graphs/contributors"><img src="https://opencollective.com/jsontokotlin/contributors.svg?width=890" /></a>
189189

190190
### Acknowledgement
191191

192-
* The development of this plugin is powerly driven by JetBrains.
192+
The development of this plugin is powerly driven by JetBrains.
193193

194194
### Join the Community
195195

196196
| QQ Group |
197197
| -------- |
198198
| ![QQ Group](qq_qrcode.png "Scan QR code with QQ/TIM to join the group chat")
199199

200+
### Note:
201+
We analytics anonymous user behavior for improving plugin production, If you don't want this behavior enable, please contact us, we will provide a switch case for that.
200202
### Stargazers over time
201203

202204
[![Stargazers over time](https://starcharts.herokuapp.com/wuseal/JsonToKotlinClass.svg)](https://starcharts.herokuapp.com/wuseal/JsonToKotlinClass)

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ apply plugin: 'kotlin'
2020
apply plugin: 'org.jetbrains.intellij'
2121

2222
group 'wu.seal'
23-
version '3.2.0'
23+
version '3.3.0'
2424

2525
intellij {
2626
version '2017.1'
@@ -43,7 +43,9 @@ repositories {
4343
}
4444

4545
dependencies {
46-
compile 'com.squareup:kotlinpoet:1.1.0'
46+
compile ('com.squareup:kotlinpoet:1.1.0'){
47+
exclude group: "org.jetbrains.kotlin"
48+
}
4749

4850
testImplementation('com.winterbe:expekt:0.5.0') {
4951
exclude group: "org.jetbrains.kotlin"

src/main/kotlin/extensions/Extension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ abstract class Extension : IImportClassDeclarationInterceptor, IKotlinDataClassI
5656
}
5757

5858
fun getConfig(key: String): String {
59-
return getConfig(key)
59+
return extension.getConfig(key)
6060
}
6161
}
6262
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package extensions
22

3+
import extensions.chen.biao.KeepAnnotationSupport
4+
import extensions.ted.zeng.PropertyAnnotationLineSupport
5+
import extensions.wu.seal.ClassNameSuffixSupport
36
import extensions.wu.seal.PropertyPrefixSupport
47
import extensions.wu.seal.PropertySuffixSupport
5-
import extensions.chen.biao.KeepAnnotationSupport
8+
69
/**
710
* extension collect, all extensions will be hold by this class's extensions property
811
*/
@@ -11,8 +14,10 @@ object ExtensionsCollector {
1114
* all extensions
1215
*/
1316
val extensions = listOf(
14-
PropertyPrefixSupport,
15-
PropertySuffixSupport,
16-
KeepAnnotationSupport
17+
PropertyPrefixSupport,
18+
PropertySuffixSupport,
19+
KeepAnnotationSupport,
20+
PropertyAnnotationLineSupport,
21+
ClassNameSuffixSupport
1722
)
1823
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package extensions.ted.zeng
2+
3+
import com.intellij.ui.layout.verticalPanel
4+
import extensions.Extension
5+
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
6+
import wu.seal.jsontokotlin.classscodestruct.Property
7+
import javax.swing.JCheckBox
8+
import javax.swing.JPanel
9+
10+
/**
11+
* Created by ted on 2019-06-13 18:10.
12+
*/
13+
object PropertyAnnotationLineSupport : Extension() {
14+
15+
private const val enable = "ted.zeng.property_annotation_in_same_line_enable"
16+
17+
override fun createUI(): JPanel {
18+
val checkBox = JCheckBox("Keep Annotation And Property In Same Line").apply {
19+
isSelected = getConfig(enable).toBoolean()
20+
addActionListener {
21+
setConfig(enable, isSelected.toString())
22+
}
23+
}
24+
return verticalPanel {
25+
checkBox()
26+
}
27+
}
28+
29+
override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass {
30+
if (getConfig(enable).toBoolean()) {
31+
kotlinDataClass.properties.forEach(Property::letLastAnnotationStayInSameLine)
32+
}
33+
return kotlinDataClass
34+
}
35+
36+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package extensions.wu.seal
2+
3+
import com.intellij.ui.layout.panel
4+
import com.intellij.util.ui.JBDimension
5+
import com.intellij.util.ui.JBEmptyBorder
6+
import extensions.Extension
7+
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
8+
import wu.seal.jsontokotlin.utils.getChildType
9+
import wu.seal.jsontokotlin.utils.getRawType
10+
import java.awt.event.FocusEvent
11+
import java.awt.event.FocusListener
12+
import javax.swing.JCheckBox
13+
import javax.swing.JPanel
14+
import javax.swing.JTextField
15+
16+
object ClassNameSuffixSupport : Extension() {
17+
18+
private const val suffixKeyEnable = "wu.seal.class_name_suffix_enable"
19+
private const val suffixKey = "wu.seal.class_name_suffix"
20+
21+
override fun createUI(): JPanel {
22+
val prefixJField = JTextField().apply {
23+
text = getConfig(suffixKey)
24+
25+
addFocusListener(object : FocusListener {
26+
override fun focusGained(e: FocusEvent?) {
27+
}
28+
29+
override fun focusLost(e: FocusEvent?) {
30+
if (getConfig(suffixKeyEnable).toBoolean()) {
31+
setConfig(suffixKey, text)
32+
}
33+
}
34+
})
35+
36+
minimumSize = JBDimension(150, 25)
37+
38+
isEnabled = getConfig(suffixKeyEnable).toBoolean()
39+
40+
}
41+
42+
val checkBox = JCheckBox("Suffix append after every class name: ").apply {
43+
isSelected = getConfig(suffixKeyEnable).toBoolean()
44+
addActionListener {
45+
setConfig(suffixKeyEnable, isSelected.toString())
46+
prefixJField.isEnabled = isSelected
47+
}
48+
}
49+
50+
return panel {
51+
row {
52+
checkBox()
53+
prefixJField()
54+
}
55+
}.apply {
56+
border = JBEmptyBorder(6, 0, 0, 0)
57+
}
58+
}
59+
60+
61+
override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass {
62+
63+
val suffix = getConfig(suffixKey)
64+
65+
return if (getConfig(suffixKeyEnable).toBoolean() && suffix.isNotEmpty()) {
66+
val standTypes = listOf("Int", "Double", "Long", "String", "Boolean")
67+
val originName = kotlinDataClass.name
68+
val newPropertyTypes =
69+
kotlinDataClass.properties.map {
70+
val rawSubType = getChildType(getRawType(it.type))
71+
when {
72+
it.type.isMapType() -> {
73+
it.type//currently don't support map type
74+
}
75+
standTypes.contains(rawSubType) -> it.type
76+
else -> it.type.replace(rawSubType, rawSubType + suffix)
77+
}
78+
}
79+
80+
val newPropertyDefaultValues = kotlinDataClass.properties.map {
81+
val rawSubType = getChildType(getRawType(it.type))
82+
when {
83+
it.value.isEmpty()-> it.value
84+
it.type.isMapType() -> {
85+
it.value//currently don't support map type
86+
}
87+
standTypes.contains(rawSubType) -> it.value
88+
else -> it.value.replace(rawSubType, rawSubType + suffix)
89+
}
90+
}
91+
92+
val newProperties = kotlinDataClass.properties.mapIndexed { index, property ->
93+
94+
val newType = newPropertyTypes[index]
95+
96+
val newValue = newPropertyDefaultValues[index]
97+
98+
property.copy(type = newType,value = newValue)
99+
}
100+
101+
102+
kotlinDataClass.copy(name = originName + suffix, properties = newProperties)
103+
104+
} else {
105+
kotlinDataClass
106+
}
107+
108+
}
109+
110+
private fun String.isMapType(): Boolean {
111+
112+
return matches(Regex("Map<.+,.+>"))
113+
}
114+
115+
116+
}
117+

src/main/kotlin/wu/seal/jsontokotlin/ConfigManager.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ object ConfigManager : IConfigManager {
3535
TestConfig.enableMapType = value
3636
} else PropertiesComponent.getInstance().setValue(ENABLE_MAP_TYP_KEY, value, false)
3737

38-
var enableAutoReformat: Boolean
39-
get() = (TestConfig.isTestModel && TestConfig.enableAutoReformat)
40-
|| PropertiesComponent.getInstance().getBoolean(ENABLE_AUTO_REFORMAT, true)
41-
set(value) = if (TestConfig.isTestModel) {
42-
TestConfig.enableAutoReformat = value
43-
} else PropertiesComponent.getInstance().setValue(ENABLE_AUTO_REFORMAT, value, true)
44-
4538
var enableMinimalAnnotation: Boolean
4639
get() = if (TestConfig.isTestModel) {
4740
TestConfig.enableMinimalAnnotation
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package wu.seal.jsontokotlin
2+
3+
enum class DefaultValueStrategy {
4+
AvoidNull, AllowNull, None
5+
}

src/main/kotlin/wu/seal/jsontokotlin/GenerateKotlinFileAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import wu.seal.jsontokotlin.utils.KotlinDataClassFileGenerator
2121
/**
2222
* Created by Seal.Wu on 2018/4/18.
2323
*/
24-
class GenerateKotlinFileAction : AnAction("GenerateKotlinClassFile") {
24+
class GenerateKotlinFileAction : AnAction("Kotlin data class File from JSON") {
2525

2626
override fun actionPerformed(event: AnActionEvent) {
2727
var jsonString = ""

0 commit comments

Comments
 (0)