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 #212 from wuseal/3.4.0
3.4.0
- Loading branch information
Showing
23 changed files
with
464 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon May 14 11:49:38 CST 2018 | ||
#Sun Jul 21 15:52:28 CST 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip |
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 @@ | ||
#### Use Annotation | ||
|
||
##### 1.add in gradle file | ||
|
||
``` | ||
android { | ||
... | ||
//Using Kotlin experimental characteristics | ||
//You only need this for Kotlin < 1.3.40 | ||
androidExtensions { | ||
experimental = true | ||
} | ||
} | ||
``` | ||
|
||
##### 2. Marking Data Classes with Annotations and Implementing Parcelable Interface | ||
|
||
``` | ||
@SuppressLint("ParcelCreator") | ||
@Parcelize | ||
data class User(val name: String, val age: Int) : Parcelable | ||
``` |
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
67 changes: 67 additions & 0 deletions
67
src/main/kotlin/extensions/jose/han/ParcelableAnnotationSupport.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,67 @@ | ||
package extensions.jose.han; | ||
|
||
import com.intellij.ide.BrowserUtil | ||
import com.intellij.ui.layout.panel | ||
import extensions.Extension | ||
import wu.seal.jsontokotlin.classscodestruct.Annotation | ||
import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass | ||
import javax.swing.JCheckBox | ||
import javax.swing.JPanel | ||
|
||
/** | ||
* @author jose.han | ||
* @Date 2019/7/27脴 | ||
*/ | ||
object ParcelableAnnotationSupport : Extension() { | ||
|
||
val configKey = "jose.han.add_parcelable_annotatioin_enable" | ||
|
||
override fun createUI(): JPanel { | ||
|
||
|
||
val checkBox = JCheckBox("Enable Parcelable Support ").apply { | ||
isSelected = ParcelableAnnotationSupport.getConfig(ParcelableAnnotationSupport.configKey).toBoolean() | ||
addActionListener { | ||
ParcelableAnnotationSupport.setConfig(ParcelableAnnotationSupport.configKey, isSelected.toString()) | ||
} | ||
} | ||
|
||
return panel { | ||
row { | ||
|
||
checkBox() | ||
right { | ||
link("Need Some Config") { | ||
BrowserUtil.browse("https://github.com/wuseal/JsonToKotlinClass/blob/master/parceable_support_tip.md.md") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass { | ||
return if (ParcelableAnnotationSupport.getConfig(ParcelableAnnotationSupport.configKey).toBoolean()) { | ||
|
||
val classAnnotationString1 = "@SuppressLint(\"ParcelCreator\")" | ||
val classAnnotationString2 = "@Parcelize" | ||
|
||
val classAnnotation1 = Annotation.fromAnnotationString(classAnnotationString1) | ||
val classAnnotation2 = Annotation.fromAnnotationString(classAnnotationString2) | ||
|
||
return kotlinDataClass.copy(annotations = listOf(classAnnotation1,classAnnotation2),parentClassTemplate = "Parcelable") | ||
} else { | ||
kotlinDataClass | ||
} | ||
} | ||
|
||
override fun intercept(originClassImportDeclaration: String): String { | ||
|
||
val classAnnotationImportClassString = "import kotlinx.android.parcel.Parcelize".append("import android.os.Parcelable") | ||
|
||
return if (ParcelableAnnotationSupport.getConfig(ParcelableAnnotationSupport.configKey).toBoolean()) { | ||
originClassImportDeclaration.append(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
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
Oops, something went wrong.