Skip to content

Commit

Permalink
Types/Accessorts: native ganeration - prefixing logic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed May 25, 2023
1 parent e768454 commit 72a6e81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions languages/c/Types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref
}
else if (json.type === 'string' && json.enum) {
//Enum
structure.name = capitalize(name || json.title)
structure.name = name || json.title
let typeName = getTypeName(getModuleName(module), name || json.title, prefix, false, false)
let res = description(capitalize(name || json.title), json.description) + '\n' + generateEnum(json, typeName)
structure.json = json
Expand Down Expand Up @@ -280,7 +280,7 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref
}
else if (json.anyOf) {
let mergedSchema = getMergedSchema(module, json, name, schemas)
let prefixName = ((prefix.length > 0) && (name != prefix)) ? prefix : capitalize(name)
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
return getSchemaTypeInfo(module, mergedSchema, '', schemas, prefixName, options)
}
else if (json.type === 'object') {
Expand Down Expand Up @@ -360,7 +360,7 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
let tName = getTypeName(getModuleName(module), name, prefix)
c_shape += '\n' + (isHeader ? getObjectHandleManagement(tName) : getObjectHandleManagementImpl(tName, getJsonType(json, module, { name })))
let props = []
let containerName = ((prefix.length > 0) && (name != prefix)) ? (prefix + capitalize(name)) : capitalize(name)
let containerName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? (prefix + '_' + capitalize(name)) : capitalize(name)
Object.entries(json.properties).forEach(([pname, prop]) => {
let items
var desc = '\n' + description(capitalize(pname), prop.description)
Expand Down Expand Up @@ -454,7 +454,7 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
else if (json.anyOf) {
if (level > 0) {
let mergedSchema = getMergedSchema(module, json, name, schemas)
let prefixName = ((prefix.length > 0) && (name != prefix)) ? prefix : capitalize(name)
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
shape += getSchemaShapeInfo(mergedSchema, module, schemas, { name, prefix: prefixName, merged, level, title, summary, descriptions, destination, section, enums })
}
}
Expand Down Expand Up @@ -612,7 +612,6 @@ function getJsonTypeInfo(module = {}, json = {}, name = '', schemas, prefix = ''
}
res = getJsonTypeInfo(module, items, items.name || name, schemas, prefix)
structure.deps = res.deps
let n = capitalize(name || json.title)
structure.type.push(`WPEFramework::Core::JSON::ArrayType<${res.type}>`)

return structure
Expand All @@ -635,7 +634,7 @@ function getJsonTypeInfo(module = {}, json = {}, name = '', schemas, prefix = ''
}
else if (json.anyOf) {
let mergedSchema = getMergedSchema(module, json, name, schemas)
let prefixName = ((prefix.length > 0) && (name != prefix)) ? prefix : capitalize(name)
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
structure = getJsonTypeInfo(module, mergedSchema, name, schemas, prefixName, {descriptions, level})
}
else if (json.type === 'object') {
Expand Down
4 changes: 2 additions & 2 deletions languages/c/src/types/JSONHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const getSdkNameSpace = () => 'FireboltSDK'
const getJsonDataPrefix = () => 'JsonData_'
const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON'

const getJsonDataStructName = (modName, name, prefixName = '') => {
let result =((prefixName.length > 0) && (capitalize(prefixName) != capitalize(name))) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefixName)}${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}`
const getJsonDataStructName = (modName, name, prefix = '') => {
let result =((prefix.length > 0) && (!name.startsWith(prefix))) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefix)}_${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}`

return ((result.includes(wpeJsonNameSpace()) === true) ? result : `${getSdkNameSpace()}::${result}`)
}
Expand Down
10 changes: 5 additions & 5 deletions languages/c/src/types/NativeHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ const getMapAccessors = (typeName, accessorPropertyType, level = 0) => {
return res
}

const getTypeName = (moduleName, varName, prefixName = '', upperCase = false, capitalCase = true) => {
const getTypeName = (moduleName, varName, prefix = '', upperCase = false, capitalCase = true) => {

let mName = upperCase ? moduleName.toUpperCase() : capitalize(moduleName)
let vName = upperCase ? varName.toUpperCase() : capitalCase ? capitalize(varName) : varName
if (prefixName.length > 0) {
prefixName = (prefixName !== varName) ? (upperCase ? prefixName.toUpperCase() : capitalize(prefixName)) : ''
if (prefix.length > 0) {
prefix = (!varName.startsWith(prefix)) ? (upperCase ? prefix.toUpperCase() : capitalize(prefix)) : ''
}
prefixName = (prefixName.length > 0) ?(upperCase ? prefixName.toUpperCase() : capitalize(prefixName)) : prefixName
let name = (prefixName.length > 0) ? `${mName}_${prefixName}_${vName}` : `${mName}_${vName}`
prefix = (prefix.length > 0) ?(upperCase ? prefix.toUpperCase() : capitalize(prefix)) : prefix
let name = (prefix.length > 0) ? `${mName}_${prefix}_${vName}` : `${mName}_${vName}`
return name
}

Expand Down

0 comments on commit 72a6e81

Please sign in to comment.