-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from AZKZero/master
- Loading branch information
Showing
9 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package extensions.wu.seal | ||
|
||
import extensions.Extension | ||
import wu.seal.jsontokotlin.model.classscodestruct.DataClass | ||
import wu.seal.jsontokotlin.model.classscodestruct.KotlinClass | ||
import wu.seal.jsontokotlin.ui.* | ||
import javax.swing.JPanel | ||
|
||
object BaseClassSupport : Extension() { | ||
/** | ||
* Config key can't be private, as it will be accessed from `library` module | ||
*/ | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
val baseClassSupportEnabledKey = "azk.zero.baseclass_enabled" | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
const val baseClassImportKey = "azk.zero.baseclass_import" | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
const val baseClassNameKey = "azk.zero.baseclass_name" | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
const val baseClassPropertiesKey = "azk.zero.baseclass_properties" | ||
|
||
override fun createUI(): JPanel { | ||
val classImportField = jTextInput(getConfig(baseClassImportKey), getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
addFocusLostListener { | ||
if (getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
setConfig(baseClassImportKey, text) | ||
} | ||
} | ||
document = ImportConventionDocument() | ||
} | ||
|
||
val classNameField = jTextInput(getConfig(baseClassNameKey), getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
addFocusLostListener { | ||
if (getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
setConfig(baseClassNameKey, text) | ||
} | ||
} | ||
document = SuperClassConventionDocument(100) | ||
} | ||
|
||
val classPropertiesField = jTextInput(getConfig(baseClassPropertiesKey), getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
addFocusLostListener { | ||
if (getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
setConfig(baseClassPropertiesKey, text) | ||
} | ||
} | ||
document = PropertyConventionDocument() | ||
} | ||
|
||
return jVerticalLinearLayout { | ||
jHorizontalLinearLayout{ | ||
jCheckBox("Base Class Support?", getConfig(baseClassSupportEnabledKey).toBoolean(), { isSelected -> | ||
setConfig(baseClassSupportEnabledKey, isSelected.toString()) | ||
classImportField.isEnabled = isSelected | ||
classNameField.isEnabled = isSelected | ||
classPropertiesField.isEnabled = isSelected | ||
}) | ||
} | ||
jHorizontalLinearLayout { | ||
jLabel("Base Class Import line") | ||
add(classImportField) | ||
} | ||
jHorizontalLinearLayout { | ||
jLabel("Base Class Name, used as-is") | ||
add(classNameField) | ||
} | ||
jHorizontalLinearLayout { | ||
jLabel("Excluded Properties list, comma-separated") | ||
add(classPropertiesField) | ||
} | ||
} | ||
} | ||
; | ||
override fun intercept(kotlinClass: KotlinClass): KotlinClass { | ||
// val exclusion = listOf("error", "message", "status_code", "status", "statusCode") | ||
return if (getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
val exclusionNames = getConfig(baseClassPropertiesKey).split(",").map { it.trim() } | ||
val baseClassName = getConfig(baseClassNameKey) | ||
if (kotlinClass is DataClass) { | ||
if (kotlinClass.isTop.not()) return kotlinClass | ||
val newProperties = kotlinClass.properties.mapNotNull { it.takeIf { it.originName !in exclusionNames } } | ||
kotlinClass.copy(properties = newProperties, parentClassTemplate = baseClassName) | ||
} else kotlinClass | ||
} else { | ||
kotlinClass | ||
} | ||
} | ||
|
||
override fun intercept(originClassImportDeclaration: String): String { | ||
|
||
// val classAnnotationImportClassString = "import com.arena.banglalinkmela.app.data.model.response.base.BaseResponse" | ||
val classAnnotationImportClassString = getConfig(baseClassImportKey) | ||
|
||
return if (getConfig(baseClassSupportEnabledKey).toBoolean()) { | ||
originClassImportDeclaration.append("import $classAnnotationImportClassString") | ||
} else { | ||
originClassImportDeclaration | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/wu/seal/jsontokotlin/ui/ImportConventionDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package wu.seal.jsontokotlin.ui | ||
|
||
import javax.swing.text.AttributeSet | ||
import javax.swing.text.PlainDocument | ||
|
||
/** | ||
* Created by ted on 2019/8/21 11:08. | ||
*/ | ||
class ImportConventionDocument(maxLength: Int) : PlainDocument() { | ||
constructor() : this(252) | ||
|
||
private val maxLength: Int = if (maxLength > 252 || maxLength <= 0) 252 else maxLength | ||
override fun insertString(offs: Int, str: String?, a: AttributeSet?) { | ||
str ?: return | ||
val take = maxLength - length | ||
if (take <= 0) return | ||
super.insertString( | ||
offs, | ||
str.filter { it.isLetterOrDigit() || it in listOf('_', '.') }.take(take), | ||
a | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/wu/seal/jsontokotlin/ui/PropertyConventionDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package wu.seal.jsontokotlin.ui | ||
|
||
import javax.swing.text.AttributeSet | ||
import javax.swing.text.PlainDocument | ||
|
||
/** | ||
* Created by ted on 2019/8/21 11:08. | ||
*/ | ||
class PropertyConventionDocument(maxLength: Int) : PlainDocument() { | ||
constructor() : this(252) | ||
|
||
private val maxLength: Int = if (maxLength > 252 || maxLength <= 0) 252 else maxLength | ||
override fun insertString(offs: Int, str: String?, a: AttributeSet?) { | ||
str ?: return | ||
val take = maxLength - length | ||
if (take <= 0) return | ||
super.insertString( | ||
offs, | ||
str.filter { it.isLetterOrDigit() || it in listOf('_', ',') }.take(take), | ||
a | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/wu/seal/jsontokotlin/ui/SuperClassConventionDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package wu.seal.jsontokotlin.ui | ||
|
||
import javax.swing.text.AttributeSet | ||
import javax.swing.text.PlainDocument | ||
|
||
/** | ||
* Created by ted on 2019/8/21 11:08. | ||
*/ | ||
class SuperClassConventionDocument(maxLength: Int) : PlainDocument() { | ||
constructor() : this(252) | ||
|
||
private val maxLength: Int = if (maxLength > 252 || maxLength <= 0) 252 else maxLength | ||
override fun insertString(offs: Int, str: String?, a: AttributeSet?) { | ||
str ?: return | ||
val take = maxLength - length | ||
if (take <= 0) return | ||
super.insertString( | ||
offs, | ||
str.filter { it.isLetterOrDigit() || it in listOf('_', '(', ')', '.') }.take(take), | ||
a | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters