MCPcopy Create free account
hub / github.com/Autodesk/AutomaticComponentToolkit / writeGoMethod

Function writeGoMethod

Source/buildbindinggo.go:688–1140  ·  view source on GitHub ↗
(method ComponentDefinitionMethod, w LanguageWriter, implw LanguageWriter, NameSpace string, ClassName string, isGlobal bool, classdefinitions* []string)

Source from the content-addressed store, hash-verified

686}
687
688func writeGoMethod(method ComponentDefinitionMethod, w LanguageWriter, implw LanguageWriter, NameSpace string, ClassName string, isGlobal bool, classdefinitions* []string) error {
689
690 parameters := ""
691 callparameters := ""
692 returnvalues := ""
693
694 var comments []string
695
696 var implDeclarations []string
697 implDeclarations = append(implDeclarations, fmt.Sprintf("var err error = nil"))
698 var implCasts []string
699
700 implReturnValues := ""
701
702 errorReturn := ""
703 for k := 0; k < len(method.Params); k++ {
704 param := method.Params[k]
705
706 if (param.ParamPass == "out") || (param.ParamPass == "return") {
707 switch param.ParamType {
708 case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double":
709 errorReturn = errorReturn + fmt.Sprintf("0, ")
710 case "pointer":
711 errorReturn = errorReturn + fmt.Sprintf("0, ")
712 case "enum":
713 errorReturn = errorReturn + fmt.Sprintf("0, ")
714 case "bool":
715 errorReturn = errorReturn + fmt.Sprintf("false, ")
716 case "string":
717 errorReturn = errorReturn + fmt.Sprintf("\"\", ")
718 case "struct":
719 errorReturn = errorReturn + fmt.Sprintf("s%s, ", param.ParamName)
720 case "class", "optionalclass":
721 errorReturn = errorReturn + fmt.Sprintf("h%s, ", param.ParamName)
722 case "functiontype":
723 errorReturn = errorReturn + fmt.Sprintf("0, ")
724 case "basicarray":
725 basicType, err := getGoBasicType(param.ParamClass)
726 if err != nil {
727 return err
728 }
729 errorReturn = errorReturn + fmt.Sprintf("make([]%s, 0), ", basicType)
730 case "structarray":
731 errorReturn = errorReturn + fmt.Sprintf("make([]s%s%s, 0), ", NameSpace, param.ParamClass)
732 default:
733 return fmt.Errorf("invalid method parameter type \"%s\" for %s.%s(%s)", param.ParamType, ClassName, method.MethodName, param.ParamName)
734 }
735 }
736 }
737 errorReturn = errorReturn + "err"
738
739 if !isGlobal {
740 implCasts = append(implCasts, fmt.Sprintf(""))
741 implCasts = append(implCasts, fmt.Sprintf("implementation_%s, err := implementation.GetWrapperHandle(%s)", strings.ToLower(ClassName), ClassName))
742 implCasts = append(implCasts, fmt.Sprintf("if (err != nil) {"))
743 implCasts = append(implCasts, fmt.Sprintf(" return %s", errorReturn))
744 implCasts = append(implCasts, fmt.Sprintf("}"))
745 }

Callers 2

buildGoClassFunction · 0.85
buildGoWrapperFunction · 0.85

Calls 4

getGoBasicTypeFunction · 0.85
paramFunctionFunction · 0.85
WritelnMethod · 0.80
WritelnsMethod · 0.80

Tested by

no test coverage detected