Skip to content

Commit 1353454

Browse files
committed
Fix bug,support custom super interface name. update to 1.3
1 parent 2818ae4 commit 1353454

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22

33

4+
## [v1.3](https://plugins.jetbrains.com/plugin/10907-mvpautocodeplus)(2018-11-27)
5+
- Fix bug.
6+
- Support custom super interface name..
7+
48
## [v1.2](https://plugins.jetbrains.com/plugin/10907-mvpautocodeplus)(2018-11-27)
59

610
- Add generate model checkbox state save.

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
id 'org.jetbrains.intellij' version '0.3.4'
1515
}
1616

17-
version '1.2'
17+
version '1.3'
1818
group 'com.longforus'
1919

2020

@@ -52,6 +52,7 @@ if (!hasProperty('StudioCompilePath')) {
5252
intellij {
5353
// version '2018.3'
5454
plugins 'org.jetbrains.kotlin:1.3.10-release-IJ2018.3-1' //here
55+
// plugins 'org.jetbrains.kotlin:1.3.21-release-IJ2018.2-1' //here
5556
// version '2018.2'
5657
// plugins 'org.jetbrains.kotlin:1.2.61-release-IJ2018.2-1' //here
5758
// version '2018.1'
@@ -74,7 +75,7 @@ dependencies {
7475
}
7576

7677
patchPluginXml {
77-
changeNotes """<h3>Add generate model checkbox state save,change file template format,fix bug</h3>
78+
changeNotes """<h3>Fix bug,support custom super interface name. Thank you klxy1990 for your feedback.</h3>
7879
<br/>
7980
<a href="https://github.com/longforus/MvpAutoCodePlus/blob/master/CHANGELOG.md"><b>Full Changelog History</b></a>"""
8081
}

src/main/kotlin/com/longforus/mvpautocodeplus/MainAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class MainAction : AnAction("main", "auto make mvp code", PlatformIcons.CLASS_IC
7777
runWriteAction {
7878
if (it.isJava) {
7979
val contractJ = createFile(it.name, if (it.generateModel) CONTRACT_TP_NAME_JAVA else CONTRACT_TP_NO_MODEL_NAME_JAVA, getSubDir(dir, CONTRACT),
80-
"") as PsiJavaFile
80+
"")
8181
if (!it.vImpl.isEmpty() && !it.vImpl.startsWith(IS_NOT_SET)) {
8282
val sdV = getSubDir(dir, VIEW)
8383
if (it.isActivity) {

src/main/kotlin/com/longforus/mvpautocodeplus/TemplateCons.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ public interface TemplateCons {
1010
String CONTRACT_TP_CONTENT_JAVA =
1111
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME};#end\n" + "\n" + "import ${V};\n" + "import ${P};\n" + "import ${M};\n" + "/**\n" + " * @describe \n" +
1212
" * @author ${USER}\n" + " * @date ${DATE} ${TIME}\n" + " * \t\t\t\t\t\t\t\t - generate by MvpAutoCodePlus plugin.\n" + " */\n" + "\n" +
13-
"public interface I${NAME}Contract {\n" + " interface View extends IView${VG}{}\n" + " interface Presenter extends IPresenter${PG}{}\n" +
14-
" interface Model extends IModel${MG}{}\n" + "}\n";
13+
"public interface I${NAME}Contract {\n" + " interface View extends ${VN}${VG}{}\n" + " interface Presenter extends ${PN}${PG}{}\n" +
14+
" interface Model extends ${MN}${MG}{}\n" + "}\n";
1515
String CONTRACT_TP_CONTENT_NO_MODEL_JAVA =
1616
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME};#end\n" + "\n" + "import ${V};\n" + "import ${P};\n" + "/**\n" + " * @describe \n" + " * @author ${USER}\n" +
1717
" * @date ${DATE} ${TIME}\n" + " * \t\t\t\t\t\t\t\t - generate by MvpAutoCodePlus plugin.\n" + " */\n" + "\n" + "public interface I${NAME}Contract {\n" +
18-
" interface View extends IView${VG}{}\n" + " interface Presenter extends IPresenter${PG}{}\n" + "}\n";
18+
" interface View extends ${VN}${VG}{}\n" + " interface Presenter extends ${PN}${PG}{}\n" + "}\n";
1919

2020
String CONTRACT_TP_CONTENT_KOTLIN =
2121
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME}#end\n" + "\n" + "import ${V}\n" + "import ${P}\n" + "import ${M}\n" + "/**\n" + " * @describe \n" +
2222
" * @author ${USER}\n" + " * @date ${DATE} ${TIME}\n" + " * \t\t\t\t\t\t\t\t - generate by MvpAutoCodePlus plugin.\n" + " */\n" + "\n" + "interface ${NAME} {\n" +
23-
" interface View : IView${VG}{}\n" + " interface Presenter : IPresenter${PG}{}\n" + " interface Model : IModel${MG}{}\n" + "}\n";
23+
" interface View : ${VN}${VG}{}\n" + " interface Presenter : ${PN}${PG}{}\n" + " interface Model : ${MN}${MG}{}\n" + "}\n";
2424
String CONTRACT_TP_CONTENT_NO_MODEL_KOTLIN =
2525
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME}#end\n" + "\n" + "import ${V}\n" + "import ${P}\n" + "/**\n" + " * @describe \n" + " * @author ${USER}\n" +
2626
" * @date ${DATE} ${TIME}\n" + " * \t\t\t\t\t\t\t\t - generate by MvpAutoCodePlus plugin.\n" + " */\n" + "\n" + "interface ${NAME} {\n" +
27-
" interface View : IView${VG}{}\n" + " interface Presenter : IPresenter${PG}{}\n" + "}\n";
27+
" interface View : ${VN}${VG}{}\n" + " interface Presenter : ${PN}${PG}{}\n" + "}\n";
2828

2929
String COMMON_IMPL_TP_CONTENT_JAVA =
3030
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME};#end\n" + "\n" + "import ${CONTRACT};\n" + "#if (${IMPL} != \"\")import ${IMPL};#end\n" + "\n" + "\n" + "/**\n" +

src/main/kotlin/com/longforus/mvpautocodeplus/maker/TemplateParamFactory.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ object TemplateParamFactory {
2828
liveTemplateParam["V"] = superVNameNoGeneric
2929
liveTemplateParam["M"] = superMNameNoGeneric
3030
liveTemplateParam["P"] = superPNameNoGeneric
31+
liveTemplateParam["VN"] = superVNameNoGeneric?.substring(superVNameNoGeneric.lastIndexOf('.')+1..(superVNameNoGeneric.length-1))?: "IView"
32+
liveTemplateParam["MN"] = superMNameNoGeneric?.substring(superMNameNoGeneric.lastIndexOf('.')+1..(superMNameNoGeneric.length-1))?: "IModel"
33+
liveTemplateParam["PN"] = superPNameNoGeneric?.substring(superPNameNoGeneric.lastIndexOf('.')+1..(superPNameNoGeneric.length-1))?: "IPresenter"
34+
3135
liveTemplateParam["VG"] = superVGenericValue
3236
liveTemplateParam["PG"] = superPGenericValue
3337
liveTemplateParam["MG"] = superMGenericValue
@@ -102,14 +106,14 @@ object TemplateParamFactory {
102106
Messages.showErrorDialog("Super Interface name is null !", "Error")
103107
throw IllegalArgumentException("Super Interface name is null !")
104108
}
105-
val indexOf = setValue?.indexOf("<") ?: -1
109+
val indexOf = setValue.indexOf("<")
106110
var generic = ""
107111
var resultName = setValue
108112
if (indexOf > -1) {
109-
resultName = setValue?.substring(0, indexOf)
110-
val g = setValue?.substring(indexOf, setValue.length)
113+
resultName = setValue.substring(0, indexOf)
114+
val g = setValue.substring(indexOf, setValue.length)
111115
val sb = StringBuilder()
112-
g?.forEach {
116+
g.forEach {
113117
when (it) {
114118
"V"[0] -> sb.append(if (isContract) "View" else "${getContractName(enterName)}.View")
115119
"P"[0] -> sb.append(if (isContract) "Presenter" else "${getContractName(enterName)}.Presenter")

0 commit comments

Comments
 (0)