/
resp.go
69 lines (64 loc) · 2.03 KB
/
resp.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package udwGoImport
import (
"github.com/tachyon-protocol/udw/udwMap"
"sort"
)
type MustMulitGetPackageImportResponse struct {
absImportPathMapMap map[string]map[string]struct{}
absImportPathToDirMap map[string]string
}
func (resp MustMulitGetPackageImportResponse) GetAllLevelImportPathList(absImportPath string) (output []string) {
m := resp.absImportPathMapMap[absImportPath]
if len(m) == 0 {
return nil
}
var visitor func(absImportPath string)
seenImportPathSet := map[string]struct{}{}
visitor = func(absImportPath string) {
_, ok := seenImportPathSet[absImportPath]
if ok {
return
}
seenImportPathSet[absImportPath] = struct{}{}
m := resp.absImportPathMapMap[absImportPath]
for pkg := range m {
visitor(pkg)
}
}
visitor(absImportPath)
return udwMap.SetStringToStringListAes(seenImportPathSet)
}
func (resp MustMulitGetPackageImportResponse) GetAllIncludeImportPathList() (output []string) {
seenImportPathSet := map[string]struct{}{}
for p1, m1 := range resp.absImportPathMapMap {
seenImportPathSet[p1] = struct{}{}
for p2 := range m1 {
seenImportPathSet[p2] = struct{}{}
}
}
return udwMap.SetStringToStringListAes(seenImportPathSet)
}
func (resp MustMulitGetPackageImportResponse) GetAllIncludeDirList() (output []string) {
dirImportPathSet := map[string]struct{}{}
for p1, m1 := range resp.absImportPathMapMap {
dirImportPathSet[resp.absImportPathToDirMap[p1]] = struct{}{}
for p2 := range m1 {
dirImportPathSet[resp.absImportPathToDirMap[p2]] = struct{}{}
}
}
return udwMap.SetStringToStringListAes(dirImportPathSet)
}
func (resp MustMulitGetPackageImportResponse) GetImportPathTreeMapSet() map[string]map[string]struct{} {
return resp.absImportPathMapMap
}
func (resp MustMulitGetPackageImportResponse) GetDirectReferToPkgList(pkg string) []string {
level1ReferPkgList := []string{}
for referPkg, m1 := range resp.absImportPathMapMap {
_, ok := m1[pkg]
if ok {
level1ReferPkgList = append(level1ReferPkgList, referPkg)
}
}
sort.Strings(level1ReferPkgList)
return level1ReferPkgList
}