17
17
import java .util .Map ;
18
18
import java .util .Set ;
19
19
20
- public abstract class AbstractKotlinCodegen extends DefaultCodegenConfig {
20
+ public abstract class AbstractKotlinCodegen extends DefaultCodegenConfig {
21
21
22
22
private static Logger LOGGER = LoggerFactory .getLogger (AbstractKotlinCodegen .class );
23
23
24
24
private Set <String > instantiationLibraryFunction ;
25
25
26
-
27
-
28
26
protected String artifactId ;
29
27
protected String artifactVersion = "1.0.0" ;
30
28
protected String groupId = "io.swagger" ;
@@ -41,7 +39,7 @@ public AbstractKotlinCodegen() {
41
39
super ();
42
40
supportsInheritance = true ;
43
41
44
- languageSpecificPrimitives = new HashSet <String >(Arrays .asList (
42
+ languageSpecificPrimitives = new HashSet <>(Arrays .asList (
45
43
"kotlin.Any" ,
46
44
"kotlin.Byte" ,
47
45
"kotlin.Short" ,
@@ -60,8 +58,9 @@ public AbstractKotlinCodegen() {
60
58
61
59
// this includes hard reserved words defined by https://github.com/JetBrains/kotlin/blob/master/core/descriptors/src/org/jetbrains/kotlin/renderer/KeywordStringsGenerated.java
62
60
// as well as keywords from https://kotlinlang.org/docs/reference/keyword-reference.html
63
- reservedWords = new HashSet <String >(Arrays .asList (
61
+ reservedWords = new HashSet <>(Arrays .asList (
64
62
"abstract" ,
63
+ "actual" ,
65
64
"annotation" ,
66
65
"as" ,
67
66
"break" ,
@@ -78,6 +77,7 @@ public AbstractKotlinCodegen() {
78
77
"do" ,
79
78
"else" ,
80
79
"enum" ,
80
+ "expect" ,
81
81
"external" ,
82
82
"false" ,
83
83
"final" ,
@@ -126,7 +126,7 @@ public AbstractKotlinCodegen() {
126
126
"while"
127
127
));
128
128
129
- defaultIncludes = new HashSet <String >(Arrays .asList (
129
+ defaultIncludes = new HashSet <>(Arrays .asList (
130
130
"kotlin.Byte" ,
131
131
"kotlin.Short" ,
132
132
"kotlin.Int" ,
@@ -141,12 +141,12 @@ public AbstractKotlinCodegen() {
141
141
"kotlin.collections.Map"
142
142
));
143
143
144
- instantiationLibraryFunction = new HashSet <String >(Arrays .asList (
144
+ instantiationLibraryFunction = new HashSet <>(Arrays .asList (
145
145
"arrayOf" ,
146
146
"mapOf"
147
147
));
148
148
149
- typeMapping = new HashMap <String , String >();
149
+ typeMapping = new HashMap <>();
150
150
typeMapping .put ("string" , "kotlin.String" );
151
151
typeMapping .put ("boolean" , "kotlin.Boolean" );
152
152
typeMapping .put ("integer" , "kotlin.Int" );
@@ -169,7 +169,7 @@ public AbstractKotlinCodegen() {
169
169
instantiationTypes .put ("list" , "arrayOf" );
170
170
instantiationTypes .put ("map" , "mapOf" );
171
171
172
- importMapping = new HashMap <String , String >();
172
+ importMapping = new HashMap <>();
173
173
importMapping .put ("BigDecimal" , "java.math.BigDecimal" );
174
174
importMapping .put ("UUID" , "java.util.UUID" );
175
175
importMapping .put ("File" , "java.io.File" );
@@ -272,7 +272,7 @@ public void setEnumPropertyNaming(final String enumPropertyNamingType) {
272
272
public String getTypeDeclaration (Schema propertySchema ) {
273
273
if (propertySchema instanceof ArraySchema ) {
274
274
return getArrayTypeDeclaration ((ArraySchema ) propertySchema );
275
- } else if (propertySchema instanceof MapSchema && hasSchemaProperties (propertySchema )) {
275
+ } else if (propertySchema instanceof MapSchema && hasSchemaProperties (propertySchema )) {
276
276
Schema inner = (Schema ) propertySchema .getAdditionalProperties ();
277
277
if (inner == null ) {
278
278
LOGGER .warn (propertySchema .getName () + "(map property) does not have a proper inner type defined" );
@@ -444,7 +444,7 @@ public String toEnumVarName(String value, String datatype) {
444
444
break ;
445
445
}
446
446
447
- if (reservedWords . contains (modified )) {
447
+ if (isReservedWord (modified )) {
448
448
return escapeReservedWord (modified );
449
449
}
450
450
@@ -498,7 +498,7 @@ public String toModelName(final String name) {
498
498
String modifiedName = name .replaceAll ("\\ ." , "" );
499
499
modifiedName = sanitizeKotlinSpecificNames (modifiedName );
500
500
501
- if (reservedWords . contains (modifiedName )) {
501
+ if (isReservedWord (modifiedName )) {
502
502
modifiedName = escapeReservedWord (modifiedName );
503
503
}
504
504
@@ -578,11 +578,11 @@ protected boolean isReservedWord(String word) {
578
578
protected boolean needToImport (String type ) {
579
579
// provides extra protection against improperly trying to import language primitives and java types
580
580
boolean imports =
581
- !type .startsWith ("kotlin." ) &&
582
- !type .startsWith ("java." ) &&
583
- !defaultIncludes .contains (type ) &&
584
- !languageSpecificPrimitives .contains (type ) &&
585
- !instantiationLibraryFunction .contains (type );
581
+ !type .startsWith ("kotlin." ) &&
582
+ !type .startsWith ("java." ) &&
583
+ !defaultIncludes .contains (type ) &&
584
+ !languageSpecificPrimitives .contains (type ) &&
585
+ !instantiationLibraryFunction .contains (type );
586
586
587
587
return imports ;
588
588
}
0 commit comments