Skip to content

Commit fdee57a

Browse files
author
seal
committed
Fix special notate can't to be repalce bug(as '-' can't remove)
Add ClassName Class to transtform class name strong to be legal
1 parent d4b458c commit fdee57a

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>wu.seal.tool.jsontokotlin</id>
33
<name>JsonToKotlinClass</name>
4-
<version>1.1</version>
4+
<version>1.1.1</version>
55
<vendor email="[email protected]" url="https://www.github.com/wuseal">Seal</vendor>
66

77
<description><![CDATA[
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package wu.seal.jsontokotlin
2+
3+
/**
4+
* Transform to legal Class name
5+
* Created by Seal on 2017/9/18.
6+
*/
7+
8+
interface IKClassName {
9+
fun getLegalClassName(rawClassName: String): String
10+
11+
}
12+
13+
object KClassName : IKClassName {
14+
15+
private val ilegalClassNameList = listOf<String>(
16+
"as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in", "interface", "is", "null"
17+
, "object", "package", "return", "super", "this", "throw", "true", "try", "typealias", "val", "var", "when", "while"
18+
)
19+
20+
21+
private val ilegalCharactor = listOf<String>(
22+
"\\+", "\\-", "\\*", "/", "%", "=", "&", "|", "!", "\\[", "\\]", "\\{", "\\}", "\\(", "\\)"
23+
, ",", ".", ":", "\\?", "\\>", "\\<", "@", ";","'", "\\`","\\~" ,"\\$", "^", "#", "\\", "/", " "
24+
)
25+
26+
private val suffix = "X"
27+
28+
29+
override fun getLegalClassName(rawClassName: String): String {
30+
31+
val pattern = "${ilegalCharactor}"
32+
33+
val temp = rawClassName.replace(Regex(pattern), "")
34+
35+
return if (temp in ilegalClassNameList) {
36+
return temp + suffix
37+
} else {
38+
temp
39+
}
40+
}
41+
}

src/wu/seal/jsontokotlin/KotlinMaker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private void appendJsonObject(StringBuilder stringBuilder, JsonObject jsonObject
8282
private String getJsonObjectType(String property, JsonObject jsonElementValue) {
8383
String type;
8484
type = property.subSequence(0, 1).toString().toUpperCase() + property.subSequence(1, property.length());
85+
type = KClassName.INSTANCE.getLegalClassName(type);
8586
toBeAppend.add(new KotlinMaker(type, jsonElementValue).makeKotlinData());
8687
return type;
8788
}

src/wu/seal/jsontokotlin/PropertyName.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ object PropertyNameMaker : IPropertyNameMaker {
3131

3232

3333
private val ilegalCharactor = listOf<String>(
34-
"+", "-", "*", "/", "%", "=", "&", "|", "!", "[", "]", "{", "}", "(", ")"
35-
, ",", ".", ":", "?", ">", "<", "@", ";", "`", "$", "^", "#", "\\", "/", " "
34+
"\\+", "\\-", "\\*", "/", "%", "=", "&", "|", "!", "\\[", "\\]", "\\{", "\\}", "\\(", "\\)"
35+
, ",", ".", ":", "\\?", "\\>", "\\<", "@", ";","'", "\\`","\\~" ,"\\$", "^", "#", "\\", "/", " "
3636
)
3737

3838
private val suffix = "X"

0 commit comments

Comments
 (0)