Finalize merges base and reference type attributes and finalizes the Type attribute.
()
| 338 | // Finalize merges base and reference type attributes and finalizes the Type |
| 339 | // attribute. |
| 340 | func (a *AttributeExpr) Finalize() { |
| 341 | if a.finalized { |
| 342 | return // Avoid infinite recursion. |
| 343 | } |
| 344 | a.finalized = true |
| 345 | if ut, ok := a.Type.(UserType); ok { |
| 346 | ut.Finalize() |
| 347 | } |
| 348 | switch { |
| 349 | case IsObject(a.Type): |
| 350 | for _, ref := range a.References { |
| 351 | ru, ok := ref.(UserType) |
| 352 | if !ok { |
| 353 | continue |
| 354 | } |
| 355 | a.Inherit(ru.Attribute()) |
| 356 | } |
| 357 | for _, base := range a.Bases { |
| 358 | ru, ok := base.(UserType) |
| 359 | if !ok { |
| 360 | continue |
| 361 | } |
| 362 | a.Merge(ru.Attribute()) |
| 363 | } |
| 364 | |
| 365 | // Now that we've merged the bases, we can clear them. This |
| 366 | // avoids issues where the bases are dupped and modifications |
| 367 | // made to the originals are not reflected in the dups. |
| 368 | a.Bases = nil |
| 369 | |
| 370 | for _, nat := range *AsObject(a.Type) { |
| 371 | nat.Attribute.Finalize() |
| 372 | } |
| 373 | case IsUnion(a.Type): |
| 374 | for _, nat := range AsUnion(a.Type).Values { |
| 375 | nat.Attribute.Finalize() |
| 376 | } |
| 377 | case IsArray(a.Type): |
| 378 | AsArray(a.Type).ElemType.Finalize() |
| 379 | case IsMap(a.Type): |
| 380 | m := AsMap(a.Type) |
| 381 | m.ElemType.Finalize() |
| 382 | m.KeyType.Finalize() |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // Merge merges other's attributes into a overriding attributes of a with |
| 387 | // attributes of other with identical names. |
nothing calls this directly
no test coverage detected