All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.regnosys.rosetta.generator.python.object.PythonModelObjectBoilerPlate.xtend Maven / Gradle / Ivy

There is a newer version: 11.31.0
Show newest version
package com.regnosys.rosetta.generator.python.object

import com.regnosys.rosetta.generator.object.ExpandedAttribute

import static extension com.regnosys.rosetta.generator.python.util.PythonTranslator.toPythonType
import com.regnosys.rosetta.generator.object.ExpandedType

class PythonModelObjectBoilerPlate {

    def toAttributeName(ExpandedAttribute attribute) {
        if (attribute.name == "val")
        '''`val`'''
        else
        attribute.name.toFirstLower
    }

    def replaceTabsWithSpaces(CharSequence code) {
        code.toString.replace('\t', '  ')
    }

    def toEnumAnnotationType(ExpandedType type) {
        '''«type.name»'''
    }

    def toType(ExpandedAttribute attribute) {
        if (attribute.multiple)
            '''MutableList<«attribute.toRawType»>'''
        else if (attribute.singleOptional)
            '''«attribute.toRawType»'''
        else
        '''«attribute.toRawType»'''
    }

    def toRawType(ExpandedAttribute attribute) {
        attribute.type.toPythonType
    }

    def toReferenceWithMetaTypeName(ExpandedType type) {
        '''ReferenceWithMeta«type.toMetaTypeName»'''
    }

    def toBasicReferenceWithMetaTypeName(ExpandedType type) {
        '''BasicReferenceWithMeta«type.toMetaTypeName»'''
    }

    def toFieldWithMetaTypeName(ExpandedType type) {
        '''FieldWithMeta«type.toMetaTypeName»'''
    }

    static def toMetaTypeName(ExpandedType type) {
        val name = type.toPythonType
        if (name === null) {
            return "null-name"
        }

        if (type.enumeration) {
            return name
        } else if (name.contains(".")) {
            return name.substring(name.lastIndexOf(".") + 1).toFirstUpper
        }

        return name.toFirstUpper
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy