MCPcopy
hub / github.com/tinylib/msgp / getTypeSpecs

Method getTypeSpecs

parse/getast.go:449–489  ·  view source on GitHub ↗

getTypeSpecs extracts all of the *ast.TypeSpecs in the file into fs.Identities, but does not set the actual element

(f *ast.File)

Source from the content-addressed store, hash-verified

447// getTypeSpecs extracts all of the *ast.TypeSpecs in the file
448// into fs.Identities, but does not set the actual element
449func (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
491func fieldName(f *ast.Field) string {
492 switch len(f.Names) {

Callers 1

FileFunction · 0.95

Calls 1

stringifyFunction · 0.85

Tested by

no test coverage detected