buildClassFromReflection creates a ClassBuilder from reflection analysis MODIFIED FOR SCHEME C: Constructor signature changed to receive instance and return Go object
(ctx *Context, className string, typ reflect.Type, opts *ReflectOptions)
| 143 | // buildClassFromReflection creates a ClassBuilder from reflection analysis |
| 144 | // MODIFIED FOR SCHEME C: Constructor signature changed to receive instance and return Go object |
| 145 | func buildClassFromReflection(ctx *Context, className string, typ reflect.Type, opts *ReflectOptions) (*ClassBuilder, error) { |
| 146 | builder := NewClassBuilder(className) |
| 147 | |
| 148 | // SCHEME C: Modified constructor with new signature |
| 149 | // Constructor now receives pre-created instance and returns Go object to associate |
| 150 | builder.Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) { |
| 151 | // Create new Go object instance |
| 152 | goObject := reflect.New(typ).Interface() |
| 153 | |
| 154 | // Initialize from constructor arguments using mixed parameter strategy |
| 155 | if len(args) > 0 { |
| 156 | if err := initializeFromArgs(goObject, args, typ, ctx); err != nil { |
| 157 | return nil, fmt.Errorf("constructor initialization failed: %w", err) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // SCHEME C: Return Go object for automatic association with instance |
| 162 | // The framework handles accessor-based synchronization automatically |
| 163 | return goObject, nil |
| 164 | }) |
| 165 | |
| 166 | // Add accessors (only exported fields) - unchanged |
| 167 | addReflectionAccessors(builder, typ, opts) |
| 168 | |
| 169 | // Add methods (only exported methods) - unchanged |
| 170 | addReflectionMethods(builder, typ, opts) |
| 171 | |
| 172 | return builder, nil |
| 173 | } |
| 174 | |
| 175 | // initializeFromArgs implements mixed parameter constructor strategy |
| 176 | func initializeFromArgs(instance interface{}, args []*Value, typ reflect.Type, ctx *Context) error { |
no test coverage detected