/
helpers.go
43 lines (36 loc) · 1022 Bytes
/
helpers.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
package coupling
import (
"github.com/go-architect/go-architect-lib/internal/utils/arrays"
packageUtils "github.com/go-architect/go-architect-lib/internal/utils/packages"
"github.com/go-architect/go-architect-lib/packages"
"go/ast"
"strings"
)
func retrievePrefix(dep string) string {
split := strings.Split(dep, "/")
return split[len(split)-1]
}
func containsDependency(file *ast.File, dep string) bool {
for _, is := range file.Imports {
if sameDependency(is.Path.Value, dep) {
return true
}
}
return false
}
func sameDependency(d1, d2 string) bool {
dx1 := strings.Replace(d1, "\"", "", 2)
dx2 := strings.Replace(d2, "\"", "", 2)
return dx1 == dx2
}
func resolveDependantPackages(pkgs []*packages.PackageInfo, dep string) []*packages.PackageInfo {
var dependants []*packages.PackageInfo
for _, p := range pkgs {
if p.PackageData != nil {
if arrays.Contains(packageUtils.GetImportedPackages(p.PackageData), dep) {
dependants = append(dependants, p)
}
}
}
return dependants
}