getTypeSpecs extracts all of the *ast.TypeSpecs in the file into fs.Identities, but does not set the actual element
(f *ast.File)
| 447 | // getTypeSpecs extracts all of the *ast.TypeSpecs in the file |
| 448 | // into fs.Identities, but does not set the actual element |
| 449 | func (fs *FileSet) getTypeSpecs(f *ast.File) { |
| 450 | // collect all imports... |
| 451 | fs.Imports = append(fs.Imports, f.Imports...) |
| 452 | |
| 453 | // check all declarations... |
| 454 | for i := range f.Decls { |
| 455 | // for GenDecls... |
| 456 | if g, ok := f.Decls[i].(*ast.GenDecl); ok { |
| 457 | // and check the specs... |
| 458 | for _, s := range g.Specs { |
| 459 | // for ast.TypeSpecs.... |
| 460 | if ts, ok := s.(*ast.TypeSpec); ok { |
| 461 | // Handle type aliases, by adding a "replace" directive. |
| 462 | if ts.Assign != 0 { |
| 463 | if fs.Aliased == nil { |
| 464 | fs.Aliased = make(map[string]string) |
| 465 | } |
| 466 | fs.Aliased[ts.Name.Name] = fmt.Sprintf("replace %s with:%s", ts.Name.Name, stringify(ts.Type)) |
| 467 | continue |
| 468 | } |
| 469 | |
| 470 | switch ts.Type.(type) { |
| 471 | // this is the list of parse-able |
| 472 | // type specs |
| 473 | case *ast.ArrayType, |
| 474 | *ast.StarExpr, |
| 475 | *ast.Ident, |
| 476 | *ast.StructType, |
| 477 | *ast.MapType: |
| 478 | fs.Specs[ts.Name.Name] = ts.Type |
| 479 | // Store type info (no type params for non-struct types yet) |
| 480 | fs.TypeInfos[ts.Name.Name] = &TypeInfo{ |
| 481 | Type: ts.Type, |
| 482 | TypeParams: ts.TypeParams, |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | func fieldName(f *ast.Field) string { |
| 492 | switch len(f.Names) { |