-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser.go
More file actions
31 lines (28 loc) · 805 Bytes
/
Copy pathparser.go
File metadata and controls
31 lines (28 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package fake
import (
"go/parser"
"github.com/rs/zerolog/log"
"github.com/sonalys/fake/internal/files"
)
func (g *Generator) ParseFile(input string) (*ParsedFile, error) {
file, err := parser.ParseFile(g.FileSet, input, nil, parser.SkipObjectResolution)
if err != nil {
return nil, err
}
packagePath, err := files.GetPackagePath(g.goModFilename, g.goMod, input)
if err != nil {
log.Error().Err(err).Msg("failed to get package info")
return nil, err
}
imports, importsPathMap := g.cachedPackageInfo(file)
return &ParsedFile{
Generator: g,
Ref: file,
Size: int(file.End()),
PkgPath: packagePath,
PkgName: file.Name.Name,
Imports: imports,
ImportsPathMap: importsPathMap,
UsedImports: make(map[string]struct{}),
}, nil
}