commonType finds the most specific type common to t1 and t2. If t1 and t2 are both Java classes, the most specific ancestor class is returned. Else if the types are equal, their type is returned. Finally, nil is returned, indicating no common type.
(clsMap map[string]*Class, t1, t2 *Type)
| 329 | // Else if the types are equal, their type is returned. |
| 330 | // Finally, nil is returned, indicating no common type. |
| 331 | func commonType(clsMap map[string]*Class, t1, t2 *Type) *Type { |
| 332 | if t1 == nil || t2 == nil { |
| 333 | return nil |
| 334 | } |
| 335 | if reflect.DeepEqual(t1, t2) { |
| 336 | return t1 |
| 337 | } |
| 338 | if t1.Kind != Object || t2.Kind != Object { |
| 339 | // The types are fundamentally incompatible |
| 340 | return nil |
| 341 | } |
| 342 | superSet := make(map[string]struct{}) |
| 343 | supers := []string{t1.Class} |
| 344 | for len(supers) > 0 { |
| 345 | var newSupers []string |
| 346 | for _, s := range supers { |
| 347 | cls := clsMap[s] |
| 348 | superSet[s] = struct{}{} |
| 349 | newSupers = append(newSupers, cls.Supers...) |
| 350 | } |
| 351 | supers = newSupers |
| 352 | } |
| 353 | supers = []string{t2.Class} |
| 354 | for len(supers) > 0 { |
| 355 | var newSupers []string |
| 356 | for _, s := range supers { |
| 357 | if _, exists := superSet[s]; exists { |
| 358 | return &Type{Kind: Object, Class: s} |
| 359 | } |
| 360 | cls := clsMap[s] |
| 361 | newSupers = append(newSupers, cls.Supers...) |
| 362 | } |
| 363 | supers = newSupers |
| 364 | } |
| 365 | return &Type{Kind: Object, Class: "java.lang.Object"} |
| 366 | } |
| 367 | |
| 368 | // combineSigs finds the most specific function signature |
| 369 | // that covers all its overload variants. |
no outgoing calls