genbindings: generate better automatic names for Q_PROPERTY setters

This commit is contained in:
mappu 2024-08-08 18:55:37 +12:00
parent 85dd87e6d0
commit dd004dd06b

View File

@ -149,7 +149,21 @@ nextMethod:
// Parameter variable // Parameter variable
parmName, _ := methodObj["name"].(string) // n.b. may be unnamed parmName, _ := methodObj["name"].(string) // n.b. may be unnamed
if parmName == "" { if parmName == "" {
parmName = fmt.Sprintf("param%d", paramCounter+1)
// Generate a default parameter name
// Super nice autogen names if this is a Q_PROPERTY setter:
if len(mm.Parameters) == 1 && strings.HasPrefix(mm.MethodName, "set") {
parmName = strings.ToLower(string(mm.MethodName[3])) + mm.MethodName[4:]
} else {
// Otherwise - default
parmName = fmt.Sprintf("param%d", paramCounter+1)
}
}
// Block reserved Go words, replace with generic parameters
if parmName == "default" || parmName == "const" || parmName == "func" {
parmName += "Val"
} }
// Update the name for the existing nth parameter // Update the name for the existing nth parameter