func getMethodOverridesRec()

in packages/@jsii/go-runtime/jsii-runtime-go/runtime/runtime.go [400:444]


func getMethodOverridesRec(ptr interface{}, basePrefix string, cache map[string]bool) {
	ptrType := reflect.TypeOf(ptr)
	if ptrType.Kind() != reflect.Ptr {
		return
	}
	structType := ptrType.Elem()
	if structType.Kind() != reflect.Struct {
		return
	}
	if strings.HasPrefix(structType.Name(), basePrefix) {
		// Skip base class
		return
	}

	ptrVal := reflect.ValueOf(ptr)
	structVal := ptrVal.Elem()

	// Add embedded/super overrides first
	for i := 0; i < structType.NumField(); i++ {
		field := structType.Field(i)
		if !field.Anonymous {
			continue
		}
		if field.Type.Kind() == reflect.Ptr ||
			field.Type.Kind() == reflect.Interface {
			p := structVal.Field(i)
			if !p.IsNil() {
				getMethodOverridesRec(p.Interface(), basePrefix, cache)
			}
		}
	}
	// Add overrides in current struct
	// Current struct's value-type method-set
	valMethods := make(map[string]bool)
	for i := 0; i < structType.NumMethod(); i++ {
		valMethods[structType.Method(i).Name] = true
	}
	// Compare current struct's pointer-type method-set to its value-type method-set
	for i := 0; i < ptrType.NumMethod(); i++ {
		mn := ptrType.Method(i).Name
		if !valMethods[mn] {
			cache[mn] = true
		}
	}
}