Skip to content

Commit

Permalink
add: 识别到不明确的import, 最后一个目录和package名称不一致时,需要手动
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-home committed Jun 1, 2023
1 parent ddee966 commit ae88475
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 9 additions & 4 deletions console/commands/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (BeanCommand) Execute(input command.Input) {
for _, goType := range fileParser.Types {
for _, attr := range goType.Attrs {
if attr.HasTag("inject") {
for _, impStr := range fileParser.Imports {
bc.imports[impStr] = impStr
for alias, impStr := range fileParser.Imports {
bc.imports[impStr] = alias
}

break
Expand All @@ -105,7 +105,8 @@ func (BeanCommand) Execute(input command.Input) {
}

type beanCache struct {
name string
name string
// path => alias
imports map[string]string
structList []parser.GoType
}
Expand Down Expand Up @@ -210,7 +211,11 @@ func getInitializeNewFunName(k parser.GoTypeAttr, m map[string]string) string {

if !k.InPackage {
a := m[k.TypeImport]
alias = a + "."
if a == "" {
panic("识别到不明确的import, 最后一个目录和package名称不一致时,需要手动, 例如\nredis \"github.com/go-redis/redis/v8\"")
} else {
alias = a + "."
}
arr := strings.Split(k.TypeName, ".")
name = arr[len(arr)-1]
} else if name[0:1] == "*" {
Expand Down
11 changes: 7 additions & 4 deletions parser/help_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,13 @@ func GenImportAlias(path, packageName string, m map[string]string) map[string]st
keys = append(keys, s)
}
sort.Strings(keys)
for _, k := range keys {
imp := m[k]
temp := strings.Split(imp, "/")
key := temp[len(temp)-1]
for _, imp := range keys {
key := m[imp]

temp := strings.Split(key, "/")
if len(temp) != 1 {
key = temp[len(temp)-1]
}

if _, ok := aliasMapImport[key]; ok {
for i := 1; i < 1000; i++ {
Expand Down

0 comments on commit ae88475

Please sign in to comment.