Hallucinate more fixes

This commit is contained in:
2025-07-20 17:29:37 +02:00
parent 42de0ddbb2
commit 766a5a9cfe
2 changed files with 26 additions and 4 deletions

View File

@@ -221,7 +221,7 @@ func ParseClass(file string) (*Class, error) {
log.Debug("Found %d fields", len(res.Fields))
log.Debug("Parsing methods")
res.Methods, err = getMethods(doc, log)
res.Methods, err = getMethods(doc, log, res.ClassName)
if err != nil {
log.Error("Error getting methods: %v", err)
return nil, fmt.Errorf("error getting methods: %w", err)
@@ -332,7 +332,7 @@ func getFields(doc *goquery.Document, log *logger.Logger) ([]Field, error) {
return res, nil
}
func getMethods(doc *goquery.Document, log *logger.Logger) ([]Method, error) {
func getMethods(doc *goquery.Document, log *logger.Logger, className string) ([]Method, error) {
log.Debug("Starting method parsing")
res := []Method{}
@@ -495,6 +495,24 @@ func getMethods(doc *goquery.Document, log *logger.Logger) ([]Method, error) {
}
}
// If this is a constructor (method name matches class name or is contained in the original class name), ensure it returns the correct type
// Handle cases where method name is "Alliance" but class name is "Alliance_Client"
originalClassName := strings.TrimSpace(doc.Find("div.floatright > h1").Text())
if method.Name == className || method.Name == originalClassName || strings.Contains(originalClassName, method.Name) {
// Override the return type to be the cleaned class name
if len(method.Returns) > 0 {
method.Returns[0].Type = className
method.Returns[0].Comment = "A new instance of " + className
} else {
method.Returns = []Return{
{
Type: className,
Comment: "A new instance of " + className,
},
}
}
}
log.Trace("Method %s has %d parameters and %d return values", method.Name, len(method.Params), len(method.Returns))
res = append(res, method)
})