Skip to content

Commit b5ee76d

Browse files
committed
Kotlin added
1 parent 2ce7d82 commit b5ee76d

File tree

3 files changed

+115
-7
lines changed

3 files changed

+115
-7
lines changed

languages/KotlinGson.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"modelStart": "",
3+
"reservedKeywords": [
4+
"abstract",
5+
"continue",
6+
"for",
7+
"new",
8+
"null",
9+
"switch",
10+
"assert",
11+
"default",
12+
"if",
13+
"package",
14+
"synchronized",
15+
"boolean",
16+
"do",
17+
"goto",
18+
"private",
19+
"this",
20+
"break",
21+
"double",
22+
"implements",
23+
"protected",
24+
"throw",
25+
"byte",
26+
"else",
27+
"import",
28+
"public",
29+
"throws",
30+
"case",
31+
"enum",
32+
"instanceof",
33+
"return",
34+
"transient",
35+
"catch",
36+
"extends",
37+
"int",
38+
"short",
39+
"try",
40+
"char",
41+
"final",
42+
"interface",
43+
"static",
44+
"void",
45+
"class",
46+
"finally",
47+
"long",
48+
"strictfp",
49+
"volatile",
50+
"const",
51+
"float",
52+
"native",
53+
"super",
54+
"while"
55+
],
56+
57+
"dataTypes": {
58+
"arrayType": "List<<!ElementType!>>",
59+
"generic": "Any",
60+
"string": "String",
61+
"boolean": "Boolean",
62+
"float": "Double",
63+
"doubleType": "Double",
64+
"characterType": "Int",
65+
"longType": "Long",
66+
"int": "Int"
67+
},
68+
69+
"modelDefinition": "\ndata class <!ModelName!> (<!ModelDefinitionProperty!>\n) ",
70+
"fileExtension": "kt",
71+
"codeForEachProperty": "\n\t\t@SerializedName(\"<!JsonKeyName!>\") val <!VarName!>: <!VarType!>",
72+
"modelEnd": "",
73+
"staticImports": "\nimport com.google.gson.annotations.SerializedName",
74+
"supportsCamelcasing": true,
75+
"methods": {
76+
}
77+
}

script/parser.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let jsonKeyName = "<!JsonKeyName!>"
1212
let constKeyName = "<!ConstKeyName!>"
1313
let additionalCustomTypeProperty = "<!AdditionalForCustomTypeProperty!>"
1414
let modelIdentifier = "<!ModelIdentifier!>"
15+
let modelDefinitionProperties = "<!ModelDefinitionProperty!>"
1516

1617

1718
// FileBuilder
@@ -255,13 +256,17 @@ FileRepresenter.prototype = {
255256
},
256257

257258
addProperties: function() {
258-
var propertyString = "\n";
259259

260-
this.properties.forEach(function(property) {
261-
propertyString += property.toString();
262-
});
260+
if (this.language.instanceVarDefinition) {
261+
var propertyString = "\n";
262+
263+
this.properties.forEach(function(property) {
264+
propertyString += property.toString();
265+
});
263266

264-
return propertyString;
267+
return propertyString;
268+
}
269+
return "";
265270
},
266271

267272
addSetterGetter: function() {
@@ -375,15 +380,31 @@ FileRepresenter.prototype = {
375380
return content;
376381
},
377382

383+
addModelDefinition: function() {
384+
385+
var modelDefinition = this.language.modelDefinition.replaceAll(modelName, this.className).replaceAll(modelIdentifier, this.modelIdentifier);
386+
387+
388+
if (this.language.codeForEachProperty) {
389+
var _language = this.language;
390+
let propertyList = this.properties.map(function (property) {
391+
return _language.codeForEachProperty.replaceAll(varName, property.propertyName).replaceAll(jsonKeyName, property.jsonKeyName).replaceAll(varType, property.propertyType);
392+
}).join(",");
393+
394+
modelDefinition = modelDefinition.replaceAll(modelDefinitionProperties, propertyList);
395+
}
396+
397+
return modelDefinition;
398+
},
399+
378400
toString: function() {
379401
var content = "";
380402

381403
content = content + this.addFirstLine();
382404
content = content + this.addCopyright();
383405
content = content + this.addImports();
384406

385-
let modelDefinition = this.language.modelDefinition.replaceAll(modelName, this.className).replaceAll(modelIdentifier, this.modelIdentifier);
386-
content = content + modelDefinition;
407+
content = content + this.addModelDefinition();
387408
content = content + this.language.modelStart;
388409

389410
content = content + this.addProperties();

script/script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ let languages = {
6161
}
6262
}
6363
},
64+
kotlin: {
65+
name: "Kotlin",
66+
frameworks: {
67+
gson: {
68+
mode: "text/x-java",
69+
name: "Gson",
70+
file: "KotlinGson.json"
71+
}
72+
}
73+
},
6474
csharo: {
6575
name: "C#",
6676
frameworks: {

0 commit comments

Comments
 (0)