reserved words
parent
09a690998c
commit
a411090422
|
@ -9,8 +9,7 @@ module.exports = {
|
|||
model.package = `${namespace}.${suffix}`;
|
||||
model.dir = model.package.replace(/\./g, '/')
|
||||
model.fields = model.fields.map(field => {
|
||||
field.name = field.name
|
||||
field.nameSafe = utils.camelcase(field.name == 'default' ? 'defaultValue' : field.name)
|
||||
field.nameSafe = utils.camelcase(javaType.safeName(field.name))
|
||||
field.type = javaType.mapJavaType(field.type, namespace)
|
||||
field.default = javaType.mapDefaultValue(field.type, field.default)
|
||||
return field
|
||||
|
|
|
@ -3,6 +3,18 @@ const utils = require('./utils')
|
|||
const COLLECTION_REGEX = /\[?([^\[\]]+)\]?/
|
||||
const LAST_ELEMENT_REGEX = /(.*)\.([a-zA-Z_0-9]+$)/
|
||||
|
||||
const RESERVED_WORDS = [
|
||||
'abstract', 'assert' 'boolean', 'break' , 'byte', 'case',
|
||||
'catch', 'char', 'class', 'const', 'continue', 'default',
|
||||
'double', 'do', 'else', 'enum', 'extends', 'false',
|
||||
'final', 'finally', 'float', 'for','goto', 'if',
|
||||
'implements', 'import', 'instanceof', 'int', 'interface', 'long',
|
||||
'native', 'new', 'null', 'package', 'private', 'protected',
|
||||
'public', 'return', 'short', 'static', 'strictfp', 'super',
|
||||
'switch', 'synchronized', 'this', 'throw', 'throws', 'transient',
|
||||
'true', 'try', 'void', 'volatile', 'while'
|
||||
]
|
||||
|
||||
const SUPPORTED_TYPES = {
|
||||
boolean: {
|
||||
name: 'Boolean',
|
||||
|
@ -52,7 +64,6 @@ const SUPPORTED_TYPES = {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function getCustomType(type, namespace, suffix='') {
|
||||
|
||||
let match = LAST_ELEMENT_REGEX.exec(type)
|
||||
|
@ -117,5 +128,12 @@ module.exports = {
|
|||
return `${type.name}.${value.toUpperCase()}`
|
||||
}
|
||||
return value
|
||||
},
|
||||
|
||||
safeName(name) {
|
||||
if(RESERVED_WORDS.includes(name)) {
|
||||
return `${name}Value`;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue