Skip to content

Commit ed32667

Browse files
authored
Merge pull request #240 from wuseal/3.5.0
3.5.0-EAP
2 parents c9f709c + e6a959b commit ed32667

File tree

91 files changed

+2380
-3659
lines changed

Some content is hidden

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

91 files changed

+2380
-3659
lines changed

build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.2.51'
2+
ext.kotlin_version = '1.3.41'
33

44
repositories {
55
mavenLocal()
@@ -20,7 +20,7 @@ apply plugin: 'kotlin'
2020
apply plugin: 'org.jetbrains.intellij'
2121

2222
group 'wu.seal'
23-
version '3.4.1'
23+
version '3.5.0-EAP'
2424

2525
intellij {
2626
version '2017.1'
@@ -42,9 +42,8 @@ repositories {
4242
}
4343

4444
dependencies {
45-
compile ('com.squareup:kotlinpoet:1.1.0'){
46-
exclude group: "org.jetbrains.kotlin"
47-
}
45+
46+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4847

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

src/main/kotlin/extensions/Extension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class Extension : IImportClassDeclarationInterceptor, IKotlinDataClassI
2626
* to keep the key primary, we could define it like : wu.seal.xxx using domain before the real config
2727
*/
2828
protected fun setConfig(key: String, value: String) {
29-
val configs = gson.fromJson<JsonObject>(ConfigManager.extensionsConfig, JsonObject::class.java) ?: JsonObject()
29+
val configs = gson.fromJson(ConfigManager.extensionsConfig, JsonObject::class.java) ?: JsonObject()
3030
configs.addProperty(key, value)
3131
ConfigManager.extensionsConfig = gson.toJson(configs)
3232
}
@@ -36,7 +36,7 @@ abstract class Extension : IImportClassDeclarationInterceptor, IKotlinDataClassI
3636
* to keep the key primary, we could define it like : wu.seal.xxx using domain before the real config
3737
*/
3838
protected fun getConfig(key: String): String {
39-
val configs = gson.fromJson<JsonObject>(ConfigManager.extensionsConfig, JsonObject::class.java) ?: JsonObject()
39+
val configs = gson.fromJson(ConfigManager.extensionsConfig, JsonObject::class.java) ?: JsonObject()
4040
return configs[key]?.asString ?: ""
4141
}
4242

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package extensions
22

33
import extensions.chen.biao.KeepAnnotationSupport
4+
import extensions.jose.han.ParcelableAnnotationSupport
45
import extensions.ted.zeng.PropertyAnnotationLineSupport
56
import extensions.wu.seal.ClassNameSuffixSupport
67
import extensions.wu.seal.PropertyPrefixSupport
78
import extensions.wu.seal.PropertySuffixSupport
8-
import extensions.jose.han.ParcelableAnnotationSupport
9+
import extensions.xu.rui.PrimitiveTypeNonNullableSupport
910

1011
/**
1112
* extension collect, all extensions will be hold by this class's extensions property
@@ -15,11 +16,12 @@ object ExtensionsCollector {
1516
* all extensions
1617
*/
1718
val extensions = listOf(
18-
PropertyPrefixSupport,
19-
PropertySuffixSupport,
20-
KeepAnnotationSupport,
21-
PropertyAnnotationLineSupport,
22-
ClassNameSuffixSupport,
23-
ParcelableAnnotationSupport
19+
KeepAnnotationSupport,
20+
PropertyAnnotationLineSupport,
21+
ParcelableAnnotationSupport,
22+
PropertyPrefixSupport,
23+
PropertySuffixSupport,
24+
ClassNameSuffixSupport,
25+
PrimitiveTypeNonNullableSupport
2426
)
2527
}

src/main/kotlin/extensions/chen/biao/KeepAnnotationSupport.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package extensions.chen.biao
33
import extensions.Extension
44
import wu.seal.jsontokotlin.classscodestruct.Annotation
55
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
6+
import wu.seal.jsontokotlin.ui.checkBox
67
import wu.seal.jsontokotlin.ui.horizontalLinearLayout
7-
import javax.swing.JCheckBox
88
import javax.swing.JPanel
99

1010
/**
@@ -15,19 +15,14 @@ import javax.swing.JPanel
1515
object KeepAnnotationSupport : Extension() {
1616

1717

18-
val configKey = "chen.biao.add_keep_annotation_enable"
18+
private const val configKey = "chen.biao.add_keep_annotation_enable"
1919

2020
override fun createUI(): JPanel {
21-
22-
val checkBox = JCheckBox("Add @Keep Annotation On Class ").apply {
23-
isSelected = getConfig(configKey).toBoolean()
24-
addActionListener {
25-
setConfig(configKey, isSelected.toString())
26-
}
27-
}
28-
2921
return horizontalLinearLayout {
30-
checkBox()
22+
checkBox("Add @Keep Annotation On Class ", getConfig(configKey).toBoolean()) { isSelectedAfterClick ->
23+
setConfig(configKey, isSelectedAfterClick.toString())
24+
}()
25+
fillSpace()
3126
}
3227
}
3328

src/main/kotlin/extensions/jose/han/ParcelableAnnotationSupport.kt

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
package extensions.jose.han;
1+
package extensions.jose.han
22

33
import extensions.Extension
44
import wu.seal.jsontokotlin.classscodestruct.Annotation
55
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
6+
import wu.seal.jsontokotlin.ui.checkBox
67
import wu.seal.jsontokotlin.ui.horizontalLinearLayout
7-
import java.awt.Cursor
8-
import java.awt.Desktop
9-
import java.awt.event.MouseAdapter
10-
import java.awt.event.MouseEvent
11-
import java.net.URI
12-
import javax.swing.JCheckBox
13-
import javax.swing.JLabel
8+
import wu.seal.jsontokotlin.ui.link
149
import javax.swing.JPanel
1510

1611
/**
@@ -19,36 +14,15 @@ import javax.swing.JPanel
1914
*/
2015
object ParcelableAnnotationSupport : Extension() {
2116

22-
val configKey = "jose.han.add_parcelable_annotatioin_enable"
17+
const val configKey = "jose.han.add_parcelable_annotatioin_enable"
2318

2419
override fun createUI(): JPanel {
25-
26-
27-
val checkBox = JCheckBox("Enable Parcelable Support ").apply {
28-
isSelected = getConfig(configKey).toBoolean()
29-
addActionListener {
30-
setConfig(configKey, isSelected.toString())
31-
}
32-
}
33-
34-
val linkLabel = JLabel("<html><a href='https://github.com/wuseal/JsonToKotlinClass/blob/master/parceable_support_tip.md'>Need Some Config</a></html>")
35-
linkLabel.addMouseListener(object : MouseAdapter() {
36-
override fun mouseClicked(e: MouseEvent?) {
37-
Desktop.getDesktop().browse(URI("https://github.com/wuseal/JsonToKotlinClass/blob/master/parceable_support_tip.md"))
38-
}
39-
40-
override fun mouseEntered(e: MouseEvent?) {
41-
linkLabel.cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
42-
}
43-
44-
override fun mouseExited(e: MouseEvent?) {
45-
linkLabel.cursor = Cursor.getDefaultCursor()
46-
}
47-
})
48-
4920
return horizontalLinearLayout {
50-
checkBox()
51-
linkLabel()
21+
checkBox("Enable Parcelable Support ", getConfig(configKey).toBoolean()) { isSelectedAfterClick ->
22+
setConfig(configKey, isSelectedAfterClick.toString())
23+
}()
24+
link("May Need Some Config", "https://github.com/wuseal/JsonToKotlinClass/blob/master/parceable_support_tip.md")()
25+
fillSpace()
5226
}
5327
}
5428

src/main/kotlin/extensions/ted/zeng/PropertyAnnotationLineSupport.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package extensions.ted.zeng
33
import extensions.Extension
44
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
55
import wu.seal.jsontokotlin.classscodestruct.Property
6+
import wu.seal.jsontokotlin.ui.checkBox
67
import wu.seal.jsontokotlin.ui.horizontalLinearLayout
7-
import javax.swing.JCheckBox
88
import javax.swing.JPanel
99

1010
/**
@@ -15,14 +15,12 @@ object PropertyAnnotationLineSupport : Extension() {
1515
private const val enable = "ted.zeng.property_annotation_in_same_line_enable"
1616

1717
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-
}
2418
return horizontalLinearLayout {
25-
checkBox()
19+
checkBox("Keep Annotation And Property In Same Line",getConfig(enable).toBoolean()){
20+
isSelectedAfterClick ->
21+
setConfig(enable, isSelectedAfterClick.toString())
22+
}()
23+
fillSpace()
2624
}
2725
}
2826

src/main/kotlin/extensions/wu/seal/ClassNameSuffixSupport.kt

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,35 @@
11
package extensions.wu.seal
22

3-
import com.intellij.util.ui.JBDimension
43
import extensions.Extension
54
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
5+
import wu.seal.jsontokotlin.ui.NamingConventionDocument
6+
import wu.seal.jsontokotlin.ui.checkBox
67
import wu.seal.jsontokotlin.ui.horizontalLinearLayout
8+
import wu.seal.jsontokotlin.ui.textInput
79
import wu.seal.jsontokotlin.utils.getChildType
810
import wu.seal.jsontokotlin.utils.getRawType
9-
import java.awt.event.FocusEvent
10-
import java.awt.event.FocusListener
11-
import javax.swing.JCheckBox
1211
import javax.swing.JPanel
13-
import javax.swing.JTextField
1412

1513
object ClassNameSuffixSupport : Extension() {
1614

1715
private const val suffixKeyEnable = "wu.seal.class_name_suffix_enable"
1816
private const val suffixKey = "wu.seal.class_name_suffix"
1917

2018
override fun createUI(): JPanel {
21-
val prefixJField = JTextField().apply {
22-
text = getConfig(suffixKey)
2319

24-
addFocusListener(object : FocusListener {
25-
override fun focusGained(e: FocusEvent?) {
26-
}
27-
28-
override fun focusLost(e: FocusEvent?) {
29-
if (getConfig(suffixKeyEnable).toBoolean()) {
30-
setConfig(suffixKey, text)
31-
}
20+
return horizontalLinearLayout {
21+
val prefixJField = textInput(getConfig(suffixKey), getConfig(suffixKeyEnable).toBoolean()) {
22+
if (getConfig(suffixKeyEnable).toBoolean()) {
23+
setConfig(suffixKey, it.text)
3224
}
33-
})
34-
35-
minimumSize = JBDimension(150, 25)
36-
37-
isEnabled = getConfig(suffixKeyEnable).toBoolean()
38-
39-
}
40-
41-
val checkBox = JCheckBox("Suffix append after every class name: ").apply {
42-
isSelected = getConfig(suffixKeyEnable).toBoolean()
43-
addActionListener {
44-
setConfig(suffixKeyEnable, isSelected.toString())
45-
prefixJField.isEnabled = isSelected
25+
}.also{
26+
it.document = NamingConventionDocument(80)
4627
}
47-
}
48-
49-
return horizontalLinearLayout {
50-
checkBox()
28+
checkBox("Suffix append after every class name: ", getConfig(suffixKeyEnable).toBoolean()) { isSelectedAfterClick ->
29+
setConfig(suffixKeyEnable, isSelectedAfterClick.toString())
30+
prefixJField.isEnabled = isSelectedAfterClick
31+
}()
5132
prefixJField()
52-
}.apply {
53-
maximumSize = JBDimension(600,40)
5433
}
5534
}
5635

src/main/kotlin/extensions/wu/seal/PropertyPrefixSupport.kt

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
package extensions.wu.seal
22

3-
import com.intellij.util.ui.JBDimension
43
import extensions.Extension
54
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
5+
import wu.seal.jsontokotlin.ui.NamingConventionDocument
6+
import wu.seal.jsontokotlin.ui.checkBox
67
import wu.seal.jsontokotlin.ui.horizontalLinearLayout
7-
import java.awt.event.FocusEvent
8-
import java.awt.event.FocusListener
9-
import javax.swing.JCheckBox
8+
import wu.seal.jsontokotlin.ui.textInput
109
import javax.swing.JPanel
11-
import javax.swing.JTextField
1210

1311
object PropertyPrefixSupport : Extension() {
1412

1513
private const val prefixKeyEnable = "wu.seal.property_prefix_enable"
1614
private const val prefixKey = "wu.seal.property_prefix"
1715

1816
override fun createUI(): JPanel {
19-
val prefixJField = JTextField().apply {
20-
text = getConfig(prefixKey)
21-
22-
addFocusListener(object : FocusListener {
23-
override fun focusGained(e: FocusEvent?) {
24-
}
25-
26-
override fun focusLost(e: FocusEvent?) {
27-
if (getConfig(prefixKeyEnable).toBoolean()) {
28-
setConfig(prefixKey, text)
29-
}
17+
return horizontalLinearLayout {
18+
val prefixJField = textInput(getConfig(prefixKey), getConfig(prefixKeyEnable).toBoolean()) {
19+
if (getConfig(prefixKeyEnable).toBoolean()) {
20+
setConfig(prefixKey, it.text)
3021
}
31-
})
32-
33-
isEnabled = getConfig(prefixKeyEnable).toBoolean()
34-
}
35-
36-
val checkBox = JCheckBox("Prefix append before every property: ").apply {
37-
isSelected = getConfig(prefixKeyEnable).toBoolean()
38-
addActionListener {
39-
setConfig(prefixKeyEnable, isSelected.toString())
40-
prefixJField.isEnabled = isSelected
22+
}.also{
23+
it.document = NamingConventionDocument(80)
4124
}
42-
}
43-
44-
return horizontalLinearLayout {
45-
checkBox()
25+
checkBox("Prefix append before every property: ", getConfig(prefixKeyEnable).toBoolean()) { isSelectedAfterClick ->
26+
setConfig(prefixKeyEnable, isSelectedAfterClick.toString())
27+
prefixJField.isEnabled = isSelectedAfterClick
28+
}()
4629
prefixJField()
47-
}.apply {
48-
maximumSize = JBDimension(600,40)
4930
}
50-
5131
}
5232

5333

@@ -56,8 +36,10 @@ object PropertyPrefixSupport : Extension() {
5636
val originProperties = kotlinDataClass.properties
5737
val newProperties = originProperties.map {
5838
val prefix = getConfig(prefixKey)
59-
val newName = prefix + it.name.first().toUpperCase() + it.name.substring(1)
60-
it.copy(name = newName)
39+
if (it.name.isNotEmpty()) {
40+
val newName = prefix + it.name.first().toUpperCase() + it.name.substring(1)
41+
it.copy(name = newName)
42+
} else it
6143
}
6244
kotlinDataClass.copy(properties = newProperties)
6345
} else {

0 commit comments

Comments
 (0)